diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-27 15:47:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-27 15:47:13 +0800 |
commit | 5a1a7eba965aa447d32f2c3be054bcbbdca0388b (patch) | |
tree | 41dec8f8853c0dfce28588a59c7b31062f80ac53 /server/src/matcher | |
parent | 1aa280d29710b08d9ae60597769165b4f55db527 (diff) | |
download | lua-language-server-5a1a7eba965aa447d32f2c3be054bcbbdca0388b.zip |
函数参数自动完成时过滤lib
Diffstat (limited to 'server/src/matcher')
-rw-r--r-- | server/src/matcher/completion.lua | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index 4b12c789..d0480cc4 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -212,6 +212,9 @@ end local function searchAsArg(vm, pos, result, callback) searchFields(result.key, vm.results.locals[1], nil, function (var) + if var.value.lib then + return + end callback(var, CompletionItemKind.Variable) end) end @@ -292,26 +295,22 @@ end local function findClosePos(vm, pos) local curDis = math.maxinteger local parent = nil + local function found(object, source) + local dis = pos - source.finish + if dis > 1 and dis < curDis then + curDis = dis + parent = object + end + end for sources, object in pairs(vm.results.sources) do if sources.type == 'multi-source' then for _, source in ipairs(sources) do if source.type ~= 'simple' then - local dis = pos - source.finish - if dis > 0 and dis < curDis then - curDis = dis - parent = object - end + found(object, source) end end else - local source = sources - if source.type ~= 'simple' then - local dis = pos - source.finish - if dis > 0 and dis < curDis then - curDis = dis - parent = object - end - end + found(object, sources) end end if parent and parent.type ~= 'local' and parent.type ~= 'field' then @@ -343,7 +342,7 @@ local function isContainPos(obj, pos) return false end -local function getString(vm, pos) +local function findString(vm, pos) for _, source in ipairs(vm.results.strings) do if isContainPos(source, pos) then return source @@ -386,7 +385,7 @@ local function findCall(vm, pos) table.sort(results, function (a, b) return a.args.start < b.args.start end) - return results + return results[#results] end local function makeList(source) @@ -422,6 +421,26 @@ local function makeList(source) return list, callback end +local function searchInResult(result, source, vm, pos, callback) + if result.type == 'local' then + 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 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) + else + searchAsSuffix(result, callback) + end + end +end + return function (vm, pos) local result, source = findResult(vm, pos) local closeResult, closeSource = findClosePos(vm, pos) @@ -430,41 +449,14 @@ return function (vm, pos) return nil end - local inCall - local calls = findCall(vm, pos) - if calls then - inCall = calls[#calls] - end - local inString = getString(vm, pos) - local list, callback = makeList(source or closeSource) - + local inCall = findCall(vm, pos) + local inString = findString(vm, pos) if inCall then searchInArg(vm, inCall, inString, callback) end - if not inString then - if not result then - result = closeResult - source = closeSource - end - if result.type == 'local' then - 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 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) - else - searchAsSuffix(result, callback) - end - end + searchInResult(result or closeResult, source or closeSource, vm, pos, callback) end if #list == 0 then return nil |