summaryrefslogtreecommitdiff
path: root/server/src/matcher/completion.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-19 14:06:06 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-19 14:06:06 +0800
commit2aca34e65556b3428f4596906dfa6aa7a639c7b5 (patch)
treeba54ad6818c60c4f6f56dc25beba52b563888c57 /server/src/matcher/completion.lua
parent316fac0c3c4981444db27b18c2caaef29c32418e (diff)
downloadlua-language-server-2aca34e65556b3428f4596906dfa6aa7a639c7b5.zip
enum
Diffstat (limited to 'server/src/matcher/completion.lua')
-rw-r--r--server/src/matcher/completion.lua33
1 files changed, 29 insertions, 4 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index a5bc6eb5..d21afebf 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -122,6 +122,27 @@ local function searchFields(name, parent, callback)
end
end
+local function getValueKind(value, default)
+ if value.type == 'function' then
+ return CompletionItemKind.Function
+ end
+ if default == CompletionItemKind.Field then
+ local tp = type(value.value)
+ if tp == 'number' or tp == 'integer' or tp == 'string' then
+ return CompletionItemKind.Enum
+ end
+ end
+ return default
+end
+
+local function getDetail(var)
+ local tp = type(var.value.value)
+ if tp == 'boolean' or tp == 'number' or tp == 'integer' or tp == 'string' then
+ return ('%s = %q'):format(var.key, var.value.value)
+ end
+ return nil
+end
+
return function (vm, pos)
local result = findResult(vm, pos)
if not result then
@@ -132,14 +153,16 @@ return function (vm, pos)
searchLocals(vm, pos, result.key, function (loc)
list[#list+1] = {
label = loc.key,
- kind = CompletionItemKind.Variable,
+ kind = getValueKind(loc.value, CompletionItemKind.Variable),
+ detail = getDetail(loc),
}
end)
-- 也尝试搜索全局变量
searchFields(result.key, vm.results.locals[1], function (field)
list[#list+1] = {
label = field.key,
- kind = CompletionItemKind.Field,
+ kind = getValueKind(field.value, CompletionItemKind.Field),
+ detail = getDetail(field),
}
end)
elseif result.type == 'field' then
@@ -148,14 +171,16 @@ return function (vm, pos)
searchLocals(vm, pos, result.key, function (loc)
list[#list+1] = {
label = loc.key,
- kind = CompletionItemKind.Variable,
+ kind = getValueKind(loc.value, CompletionItemKind.Variable),
+ detail = getDetail(loc),
}
end)
end
searchFields(result.key, result.parent, function (field)
list[#list+1] = {
label = field.key,
- kind = CompletionItemKind.Field,
+ kind = getValueKind(field.value, CompletionItemKind.Field),
+ detail = getDetail(field),
}
end)
end