summaryrefslogtreecommitdiff
path: root/server/src/matcher
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/matcher')
-rw-r--r--server/src/matcher/completion.lua31
-rw-r--r--server/src/matcher/vm.lua24
2 files changed, 44 insertions, 11 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index 16be7b4b..db34edfb 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -199,6 +199,23 @@ local function getDocument(var, source)
return nil
end
+local function searchAsLocal(vm, pos, result, callback)
+ searchFields(result.key, vm.results.locals[1], nil, function (var)
+ callback(var, CompletionItemKind.Variable)
+ end)
+
+ -- 支持 local function
+ if matchKey(result.key, 'function') then
+ callback('function', CompletionItemKind.Keyword)
+ end
+end
+
+local function searchAsArg(vm, pos, result, callback)
+ searchFields(result.key, vm.results.locals[1], nil, function (var)
+ callback(var, CompletionItemKind.Variable)
+ end)
+end
+
local function searchAsGlobal(vm, pos, result, callback)
searchLocals(vm, pos, result.key, function (var)
callback(var, CompletionItemKind.Variable)
@@ -217,7 +234,7 @@ local function searchAsSuffix(result, callback)
end)
end
-local function searchAsArg(vm, inCall, inString, callback)
+local function searchInArg(vm, inCall, inString, callback)
local special = inCall.func.lib and inCall.func.lib.special
if not special then
return
@@ -403,12 +420,18 @@ return function (vm, pos)
end
if inCall then
- searchAsArg(vm, inCall, inString, callback)
+ searchInArg(vm, inCall, inString, callback)
else
if result.type == 'local' then
- searchAsGlobal(vm, pos, result, callback)
+ if source.isArg then
+ searchAsArg(vm, pos, result, callback)
+ elseif source.isLocal then
+ searchAsLocal(vm, pos, result, callback)
+ else
+ searchAsGlobal(vm, pos, result, callback)
+ end
elseif result.type == 'field' then
- if result.isIndex then
+ if source.isIndex then
searchAsIndex(vm, pos, result, callback)
elseif result.parent and result.parent.value and result.parent.value.ENV == true then
searchAsGlobal(vm, pos, result, callback)
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 00e4d11f..f054f800 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -99,6 +99,10 @@ function mt:createLocal(key, source, value)
close = self.scope.block.finish,
}
+ if source then
+ source.isLocal = true
+ end
+
local shadow = self.scope.locals[key]
if shadow then
shadow.close = source and (source.start-1)
@@ -121,6 +125,14 @@ function mt:createLocal(key, source, value)
return loc
end
+function mt:createArg(key, source, value)
+ local loc = self:createLocal(key, source, value)
+ if source then
+ source.isArg = true
+ end
+ return loc
+end
+
function mt:scopePush(block)
if not block.start then
error('Scope push without start!')
@@ -200,7 +212,7 @@ function mt:buildTable(source)
local index = key[1]
insertOnce(self.results.indexs, index)
local field = self:createField(tbl, index, key)
- field.isIndex = true
+ key.isIndex = true
if value.type == 'list' then
self:setValue(field, value[1], key)
else
@@ -228,10 +240,7 @@ function mt:buildTable(source)
end
-- 处理写了一半的 key = value,把name类的数组元素视为哈希键
if obj.type == 'name' then
- local field = self.results.sources[obj]
- if field then
- field.isIndex = true
- end
+ obj.isIndex = true
end
end
end
@@ -393,7 +402,7 @@ function mt:buildFunction(exp, object)
self.chunk.func = func
if object then
- local var = self:createLocal('self', object.source, self:getValue(object))
+ local var = self:createArg('self', object.source, self:getValue(object))
var.disableRename = true
func.args[1] = var
end
@@ -404,7 +413,8 @@ function mt:buildFunction(exp, object)
return
end
if arg.type == 'name' then
- local var = self:createLocal(arg[1], arg)
+ local var = self:createArg(arg[1], arg)
+ arg.isArg = true
func.args[#func.args+1] = var
func.argValues[#func.args] = self:getValue(var)
elseif arg.type == '...' then