diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-26 18:09:04 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-26 18:09:04 +0800 |
commit | 0e425123aaf2fe14b0031988277326831a10764a (patch) | |
tree | d60e4656b84a7b42e42f7d93ca446b7786ae7c7e /server/src | |
parent | 71122e07d25c8f97219ef91226eb94de65a19825 (diff) | |
download | lua-language-server-0e425123aaf2fe14b0031988277326831a10764a.zip |
支持不在字符串内部
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/matcher/completion.lua | 22 | ||||
-rw-r--r-- | server/src/method/initialize.lua | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index 29a86d10..9e9d7919 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -217,6 +217,9 @@ local function searchAsArg(vm, pos, result, callback) end local function searchAsGlobal(vm, pos, result, callback) + if result.key == '' then + return + end searchLocals(vm, pos, result.key, function (var) callback(var, CompletionItemKind.Variable) end) @@ -258,10 +261,15 @@ local function searchInArg(vm, inCall, inString, callback) -- 其他库函数,根据参数位置找枚举值 if lib.args and lib.enums then - local name = lib.args[inCall.select].name + local arg = lib.args[inCall.select] + local name = arg and arg.name for _, enum in ipairs(lib.enums) do if enum.name == name and enum.enum then - callback(enum.enum, CompletionItemKind.EnumMember, nil, enum.description) + if inString then + callback(enum.enum, CompletionItemKind.EnumMember, nil, enum.description) + else + callback(('%q'):format(enum.enum), CompletionItemKind.EnumMember, nil, enum.description) + end end end end @@ -347,10 +355,10 @@ end local function findArgCount(args, pos) for i, arg in ipairs(args) do if isContainPos(arg, pos) then - return i, arg + return i end end - return #args + 1, nil + return #args + 1 end -- 找出范围包含pos的call @@ -358,10 +366,7 @@ local function findCall(vm, pos) local results = {} for _, call in ipairs(vm.results.calls) do if isContainPos(call.args, pos) then - local n, arg = findArgCount(call.args, pos) - if arg and arg.type ~= 'string' then - return nil - end + local n = findArgCount(call.args, pos) local var = vm.results.sources[call.lastObj] if var then results[#results+1] = { @@ -387,7 +392,6 @@ end return function (vm, pos) local result, source = findResult(vm, pos) if not result then - isClose = true result, source = findClosePos(vm, pos) if not result then return nil diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 0f5b840a..9ba890bc 100644 --- a/server/src/method/initialize.lua +++ b/server/src/method/initialize.lua @@ -1,5 +1,5 @@ local function allWords() - local str = [[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:('"[]] + local str = [[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:('"[, ]] local list = {} for c in str:gmatch '.' do list[#list+1] = c |