summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/completion.lua13
-rw-r--r--test-beta/completion/init.lua26
2 files changed, 37 insertions, 2 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index c5cb2e1b..0dd0f3d1 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -406,7 +406,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul
}
end
-local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results)
+local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals)
local fields = {}
for _, src in ipairs(refs) do
if src.type == 'library' then
@@ -422,6 +422,9 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res
goto CONTINUE
end
local name = key:sub(3)
+ if locals and locals[name] then
+ goto CONTINUE
+ end
if not matchKey(word, name) then
goto CONTINUE
end
@@ -450,6 +453,12 @@ local function checkField(ast, word, start, offset, parent, oop, results)
checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results)
end
+local function checkGlobal(ast, word, start, offset, parent, oop, results)
+ local locals = guide.getVisibleLocals(ast.ast, offset)
+ local refs = vm.getFields(parent, 'deep')
+ checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals)
+end
+
local function checkTableField(ast, word, start, results)
local source = guide.eachSourceContain(ast.ast, start, function (source)
if source.start == start
@@ -840,7 +849,7 @@ local function tryWord(ast, text, offset, results)
checkLocal(ast, word, start, results)
checkTableField(ast, word, start, results)
local env = guide.getENV(ast.ast, start)
- checkField(ast, word, start, offset, env, false, results)
+ checkGlobal(ast, word, start, offset, env, false, results)
end
end
end
diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua
index de22e3f4..c69e69fe 100644
--- a/test-beta/completion/init.lua
+++ b/test-beta/completion/init.lua
@@ -158,6 +158,32 @@ ass$
}
TEST [[
+local assert = 1
+ass$
+]]
+{
+ {
+ label = 'assert',
+ kind = define.CompletionItemKind.Variable,
+ },
+}
+
+TEST [[
+local assert = 1
+_G.ass$
+]]
+{
+ {
+ label = 'assert',
+ kind = define.CompletionItemKind.Function,
+ },
+ {
+ label = 'assert()',
+ kind = define.CompletionItemKind.Snippet,
+ },
+}
+
+TEST [[
local function ffff(a, b)
end
ff$