summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-19 15:40:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-19 15:40:27 +0800
commit510fa41e64286e32b921da66dbca0c4063c1eb4d (patch)
tree6a8d495dc7865ae497301366f7a84ca3d4e08774 /server
parent367bf0d2f9e172cb34bdba00eb42230c1508dfa5 (diff)
downloadlua-language-server-510fa41e64286e32b921da66dbca0c4063c1eb4d.zip
支持关键字
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/completion.lua41
-rw-r--r--server/test/completion/init.lua12
2 files changed, 44 insertions, 9 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index d4ee3e6e..aae94efd 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -126,6 +126,15 @@ local function searchFields(name, parent, callback)
end
end
+local KEYS = {'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while', 'toclose'}
+local function searchKeyWords(name, callback)
+ for _, key in ipairs(KEYS) do
+ if matchKey(name, key) then
+ callback(key)
+ end
+ end
+end
+
local function getKind(var, default)
local value = var.value
if default == CompletionItemKind.Variable then
@@ -174,6 +183,9 @@ local function searchAsGlobal(vm, pos, result, callback)
searchFields(result.key, vm.results.locals[1], function (var)
callback(var, CompletionItemKind.Field)
end)
+ searchKeyWords(result.key, function (name)
+ callback(name, CompletionItemKind.Keyword)
+ end)
end
local function searchAsSuffix(result, callback)
@@ -191,16 +203,29 @@ return function (vm, pos)
local list = {}
local mark = {}
local function callback(var, defualt)
- if mark[var.key] then
+ local key
+ if type(var) == 'string' then
+ key = var
+ else
+ key = var.key
+ end
+ if mark[key] then
return
end
- mark[var.key] = true
- list[#list+1] = {
- label = var.key,
- kind = getKind(var, defualt),
- detail = getDetail(var),
- documentation = getDocument(var, source),
- }
+ mark[key] = true
+ if var == key then
+ list[#list+1] = {
+ label = key,
+ kind = defualt,
+ }
+ else
+ list[#list+1] = {
+ label = var.key,
+ kind = getKind(var, defualt),
+ detail = getDetail(var),
+ documentation = getDocument(var, source),
+ }
+ end
end
if result.type == 'local' then
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index c0ce7076..1524badf 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -135,7 +135,7 @@ zac@
}
TEST [[
-a@
+as@
]]
{
{
@@ -185,3 +185,13 @@ mt:g@
documentation = EXISTS,
}
}
+
+TEST [[
+loc@
+]]
+{
+ {
+ label = 'local',
+ kind = CompletionItemKind.Keyword,
+ }
+}