summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-16 15:32:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-16 15:32:36 +0800
commite5bcfb04cd32045aaea778752350ea6ed0725953 (patch)
tree2366317b25433110819c8a63a72f7f1ee5228e53
parenteb57da9aa226890bf40d6187811227f5150fb1b1 (diff)
downloadlua-language-server-e5bcfb04cd32045aaea778752350ea6ed0725953.zip
自动完成也能使用所有符号
-rw-r--r--server/src/core/completion.lua14
-rw-r--r--server/test/completion/init.lua26
2 files changed, 37 insertions, 3 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 9e7b72ab..5bf55053 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -461,6 +461,19 @@ local function searchInResult(result, source, vm, pos, callback)
end
end
+local function searchAllWords(result, vm, callback)
+ if result.key == '' then
+ return
+ end
+ for source in pairs(vm.results.sources) do
+ if source.type == 'name' then
+ if result.key ~= source[1] and matchKey(result.key, source[1]) then
+ callback(source[1], CompletionItemKind.Text)
+ end
+ end
+ end
+end
+
local function searchSpecial(vm, pos, callback)
-- 尝试 #
local result, source = findResult(vm, pos, 2)
@@ -532,6 +545,7 @@ return function (vm, pos)
if result then
callback = makeList(list, source)
searchInResult(result, source, vm, pos, callback)
+ searchAllWords(result, vm, callback)
clearList(list, source)
end
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index f4b459a0..65fd17e5 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -112,7 +112,11 @@ local zabcde
{
label = 'zabcdefg',
kind = CompletionItemKind.Variable,
- }
+ },
+ {
+ label = 'zabcde',
+ kind = CompletionItemKind.Text,
+ },
}
TEST [[
@@ -315,7 +319,11 @@ print(fff)
{
label = 'function',
kind = CompletionItemKind.Keyword,
- }
+ },
+ {
+ label = 'faa',
+ kind = CompletionItemKind.Text,
+ },
}
TEST [[
@@ -494,7 +502,6 @@ local xxxx
local XXXX
xxxx@
]]
-
{
{
label = 'xxxx',
@@ -505,3 +512,16 @@ xxxx@
kind = CompletionItemKind.Variable,
}
}
+
+TEST [[
+local t = {
+ xxxxx = 1,
+}
+xx@
+]]
+{
+ {
+ label = 'xxxxx',
+ kind = CompletionItemKind.Text,
+ },
+}