summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/completion.lua11
-rw-r--r--script-beta/core/diagnostics/redundant-parameter.lua5
-rw-r--r--script-beta/vm/eachDef.lua14
-rw-r--r--test-beta/completion/init.lua30
4 files changed, 39 insertions, 21 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index f5ba1563..13b5998e 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -259,6 +259,7 @@ local keyWordMap = {
{'and'},
{'break'},
{'do', function (ast, text, start, results)
+ --local stop = guide.eachSourceContain()
if config.config.completion.keywordSnippet then
guide.eachSourceContain()
results[#results+1] = {
@@ -342,7 +343,10 @@ local function checkKeyWord(ast, text, start, word, results)
}
local func = data[2]
if func then
- func(ast, text, start, results)
+ local stop = func(ast, text, start, results)
+ if stop then
+ return true
+ end
end
end
end
@@ -359,10 +363,13 @@ local function tryWord(ast, text, offset, results)
if parent then
checkField(word, start, parent, oop, results)
else
+ local stop = checkKeyWord(ast, text, start, word, results)
+ if stop then
+ return
+ end
checkLocal(ast, word, start, results)
local env = guide.getLocal(ast.ast, '_ENV', start)
checkField(word, start, env, false, results)
- checkKeyWord(ast, text, start, word, results)
end
end
checkCommon(word, text, results)
diff --git a/script-beta/core/diagnostics/redundant-parameter.lua b/script-beta/core/diagnostics/redundant-parameter.lua
index b9b994b8..8d486aea 100644
--- a/script-beta/core/diagnostics/redundant-parameter.lua
+++ b/script-beta/core/diagnostics/redundant-parameter.lua
@@ -64,9 +64,8 @@ return function (uri, callback)
local funcArgs
vm.eachDef(func, function (info)
local src = info.source
- local f = src.value
- if f and f.type == 'function' then
- local args = countFuncArgs(f)
+ if src.type == 'function' then
+ local args = countFuncArgs(src)
if not funcArgs or args > funcArgs then
funcArgs = args
end
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 54460942..d1cba2ae 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -20,6 +20,7 @@ end
function vm.eachDef(source, callback)
local results = {}
local valueUris = {}
+ local valueInfos = {}
local sourceUri = guide.getRoot(source).uri
vm.eachRef(source, function (info)
if info.mode == 'declare'
@@ -28,6 +29,7 @@ function vm.eachDef(source, callback)
or info.mode == 'value'
or info.mode == 'library' then
results[#results+1] = info
+ valueInfos[info.source] = info
local src = info.source
if info.mode == 'return' then
local uri = guide.getRoot(src).uri
@@ -37,9 +39,15 @@ function vm.eachDef(source, callback)
end)
local res
+ local used = {}
for _, info in ipairs(results) do
local src = info.source
- local destUri = guide.getRoot(src).uri
+ local destUri
+ if used[src] then
+ goto CONTINUE
+ end
+ used[src] = true
+ destUri = guide.getRoot(src).uri
-- 如果是library,则直接放行
if src.library then
res = callback(info)
@@ -53,6 +61,10 @@ function vm.eachDef(source, callback)
or src.type == 'tableindex'
or src.type == 'setglobal' then
res = callback(info)
+ if src.value and valueInfos[src.value] then
+ used[src.value] = true
+ res = callback(valueInfos[src.value])
+ end
goto CONTINUE
end
-- 如果是同一个文件,则检查位置关系后放行
diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua
index 5736d9b0..228c4e78 100644
--- a/test-beta/completion/init.lua
+++ b/test-beta/completion/init.lua
@@ -219,21 +219,21 @@ loc$
]]
{
{
- label = 'collectgarbage',
- kind = CompletionItemKind.Function,
+ label = 'local',
+ kind = CompletionItemKind.Keyword,
},
{
- label = 'collectgarbage()',
+ label = 'local function',
kind = CompletionItemKind.Snippet,
},
{
- label = 'local',
- kind = CompletionItemKind.Keyword,
+ label = 'collectgarbage',
+ kind = CompletionItemKind.Function,
},
{
- label = 'local function',
+ label = 'collectgarbage()',
kind = CompletionItemKind.Snippet,
- }
+ },
}
TEST [[
@@ -241,6 +241,14 @@ do$
]]
{
{
+ label = 'do',
+ kind = CompletionItemKind.Keyword,
+ },
+ {
+ label = 'do .. end',
+ kind = CompletionItemKind.Snippet,
+ },
+ {
label = 'dofile',
kind = CompletionItemKind.Function,
},
@@ -264,14 +272,6 @@ do$
label = 'loadfile()',
kind = CompletionItemKind.Snippet,
},
- {
- label = 'do',
- kind = CompletionItemKind.Keyword,
- },
- {
- label = 'do .. end',
- kind = CompletionItemKind.Snippet,
- }
}
TEST [[