summaryrefslogtreecommitdiff
path: root/server/src/matcher/completion.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/matcher/completion.lua')
-rw-r--r--server/src/matcher/completion.lua48
1 files changed, 41 insertions, 7 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index 910173f0..a5bc6eb5 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -84,13 +84,13 @@ local function matchKey(me, other)
end
return false
end
- -- 5. 找到下一个可用的字,如果超出长度则失败
+ -- 5. 找到下一个可用的字,如果超出长度就算成功
::NEXT::
repeat
cur = cur + 1
until not used[cur]
if cur > #lOther then
- return false
+ break
end
end
return true
@@ -103,27 +103,61 @@ local function searchLocals(vm, pos, name, callback)
end
if loc.source.start <= pos and loc.close >= pos then
if matchKey(name, loc.key) then
- callback(loc.key)
+ callback(loc)
end
end
::CONTINUE::
end
end
+local function searchFields(name, parent, callback)
+ for key, field in pairs(parent.value.child) do
+ if type(key) ~= 'string' then
+ goto CONTINUE
+ end
+ if matchKey(name, key ) then
+ callback(field)
+ end
+ ::CONTINUE::
+ end
+end
+
return function (vm, pos)
local result = findResult(vm, pos)
if not result then
return nil
end
local list = {}
- local source = result.source
- if source.type == 'name' then
- searchLocals(vm, pos, result.key, function (label)
+ if result.type == 'local' then
+ searchLocals(vm, pos, result.key, function (loc)
list[#list+1] = {
- label = label,
+ label = loc.key,
kind = CompletionItemKind.Variable,
}
end)
+ -- 也尝试搜索全局变量
+ searchFields(result.key, vm.results.locals[1], function (field)
+ list[#list+1] = {
+ label = field.key,
+ kind = CompletionItemKind.Field,
+ }
+ end)
+ elseif result.type == 'field' then
+ if result.parent.value.ENV == true then
+ -- 全局变量也搜索是不是local
+ searchLocals(vm, pos, result.key, function (loc)
+ list[#list+1] = {
+ label = loc.key,
+ kind = CompletionItemKind.Variable,
+ }
+ end)
+ end
+ searchFields(result.key, result.parent, function (field)
+ list[#list+1] = {
+ label = field.key,
+ kind = CompletionItemKind.Field,
+ }
+ end)
end
return list
end