summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-19 15:29:24 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-19 15:29:24 +0800
commit367bf0d2f9e172cb34bdba00eb42230c1508dfa5 (patch)
treeca5f3cd0b1aa2d059630c56d38745d64f7bb3588
parent58a8a075c9a83d5356ef49c6bd6122d7387b92ae (diff)
downloadlua-language-server-367bf0d2f9e172cb34bdba00eb42230c1508dfa5.zip
整理代码
-rw-r--r--server/src/matcher/completion.lua83
1 files changed, 33 insertions, 50 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index 0718b5fb..d4ee3e6e 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -167,67 +167,50 @@ local function getDocument(var, source)
return nil
end
+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], function (var)
+ callback(var, CompletionItemKind.Field)
+ end)
+end
+
+local function searchAsSuffix(result, callback)
+ searchFields(result.key, result.parent, function (var)
+ callback(var, CompletionItemKind.Field)
+ end)
+end
+
return function (vm, pos)
local result, source = findResult(vm, pos)
if not result then
return nil
end
+
local list = {}
local mark = {}
+ local function callback(var, defualt)
+ if mark[var.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),
+ }
+ end
+
if result.type == 'local' then
- searchLocals(vm, pos, result.key, function (var)
- if mark[var.key] then
- return
- end
- mark[var.key] = true
- list[#list+1] = {
- label = var.key,
- kind = getKind(var, CompletionItemKind.Variable),
- detail = getDetail(var),
- documentation = getDocument(var, source),
- }
- end)
- -- 也尝试搜索全局变量
- searchFields(result.key, vm.results.locals[1], function (var)
- if mark[var.key] then
- return
- end
- mark[var.key] = true
- list[#list+1] = {
- label = var.key,
- kind = getKind(var, CompletionItemKind.Field),
- detail = getDetail(var),
- documentation = getDocument(var, source),
- }
- end)
+ searchAsGlobal(vm, pos, result, callback)
elseif result.type == 'field' then
if result.parent and result.parent.value and result.parent.value.ENV == true then
- -- 全局变量也搜索是不是local
- searchLocals(vm, pos, result.key, function (var)
- if mark[var.key] then
- return
- end
- mark[var.key] = true
- list[#list+1] = {
- label = var.key,
- kind = getKind(var, CompletionItemKind.Variable),
- detail = getDetail(var),
- documentation = getDocument(var, source),
- }
- end)
+ searchAsGlobal(vm, pos, result, callback)
+ else
+ searchAsSuffix(result, callback)
end
- searchFields(result.key, result.parent, function (var)
- if mark[var.key] then
- return
- end
- mark[var.key] = true
- list[#list+1] = {
- label = var.key,
- kind = getKind(var, CompletionItemKind.Field),
- detail = getDetail(var),
- documentation = getDocument(var, source),
- }
- end)
end
return list
end