summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-17 13:40:14 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-17 13:40:14 +0800
commit110b227257ce5d7f4af0bd19e78f2187e276ee95 (patch)
tree45dc51fbfd3c5680ae7019454523b96558d00f47
parentf112239ae5aca2cdf67114243156747eb1d729a8 (diff)
downloadlua-language-server-110b227257ce5d7f4af0bd19e78f2187e276ee95.zip
自动完成过滤自己
-rw-r--r--server/src/core/completion.lua15
-rw-r--r--server/test/completion/init.lua11
2 files changed, 20 insertions, 6 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index e5769f20..28a1f354 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -114,7 +114,7 @@ local function searchLocals(vm, pos, name, callback)
end
end
-local function searchFields(name, parent, object, callback)
+local function searchFields(name, source, parent, object, callback)
if not parent or not parent.value or not parent.value.child then
return
end
@@ -127,6 +127,9 @@ local function searchFields(name, parent, object, callback)
goto CONTINUE
end
end
+ if field.source == source then
+ goto CONTINUE
+ end
if type(name) == 'string' and matchKey(name, key) then
callback(field)
end
@@ -203,7 +206,7 @@ local function getDocument(var, source)
end
local function searchAsLocal(vm, pos, result, callback)
- searchFields(result.key, vm.results.locals[1], nil, function (var)
+ searchFields(result.key, result.source, vm.results.locals[1], nil, function (var)
callback(var, CompletionItemKind.Variable)
end)
@@ -214,7 +217,7 @@ local function searchAsLocal(vm, pos, result, callback)
end
local function searchAsArg(vm, pos, result, callback)
- searchFields(result.key, vm.results.locals[1], nil, function (var)
+ searchFields(result.key, result.source, vm.results.locals[1], nil, function (var)
if var.value.lib then
return
end
@@ -229,7 +232,7 @@ local function searchAsGlobal(vm, pos, result, callback)
searchLocals(vm, pos, result.key, function (var)
callback(var, CompletionItemKind.Variable)
end)
- searchFields(result.key, vm.results.locals[1], nil, function (var)
+ searchFields(result.key, result.source, vm.results.locals[1], nil, function (var)
callback(var, CompletionItemKind.Field)
end)
searchKeyWords(result.key, function (name)
@@ -238,7 +241,7 @@ local function searchAsGlobal(vm, pos, result, callback)
end
local function searchAsSuffix(result, callback)
- searchFields(result.key, result.parent, result.source.object, function (var)
+ searchFields(result.key, result.source, result.parent, result.source.object, function (var)
callback(var, CompletionItemKind.Field)
end)
end
@@ -300,7 +303,7 @@ local function searchAsIndex(vm, pos, result, callback)
callback(index.key, CompletionItemKind.Property)
end
end
- searchFields(result.key, vm.results.locals[1], nil, function (var)
+ searchFields(result.key, result.source, vm.results.locals[1], nil, function (var)
callback(var, CompletionItemKind.Field)
end)
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 65fd17e5..e34789bd 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -525,3 +525,14 @@ xx@
kind = CompletionItemKind.Text,
},
}
+
+TEST [[
+local index
+tbl[ind@]
+]]
+{
+ {
+ label = 'index',
+ kind = CompletionItemKind.Variable,
+ },
+}