diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-06 19:43:43 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-06 19:43:43 +0800 |
commit | ce0e466279ccd237ec8b3df5e7ed9275b166e1c7 (patch) | |
tree | 765108bf350103345f4538b73e237bf016fce660 /server/src/core | |
parent | df62d7a467cc2ffa1d4945c4912a4568baf75847 (diff) | |
download | lua-language-server-ce0e466279ccd237ec8b3df5e7ed9275b166e1c7.zip |
param支持字面量
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/completion.lua | 99 |
1 files changed, 66 insertions, 33 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 59a3cb3f..83d740a3 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -509,39 +509,7 @@ local function searchInRequire(vm, select, source, callback) end end -local function searchCallArg(vm, source, word, callback, pos) - local results = {} - vm:eachSource(function (src) - if src.type == 'call' - and src.start <= pos - and src.finish >= pos - then - results[#results+1] = src - end - end) - if #results == 0 then - return nil - end - -- 可能处于 'func1(func2(' 的嵌套中,将最近的call放到最前面 - table.sort(results, function (a, b) - return a.start > b.start - end) - local call = results[1] - local args = call:bindCall() - if not args then - return - end - - local value = call:findCallFunction() - if not value then - return - end - - local lib = value:getLib() - if not lib then - return - end - +local function searchEnumAsLib(vm, source, word, callback, pos, args, lib) local select = #args + 1 for i, arg in ipairs(args) do if arg.start <= pos and arg.finish >= pos - 1 then @@ -584,6 +552,71 @@ local function searchCallArg(vm, source, word, callback, pos) end end +local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func) + local select = #args + 1 + for i, arg in ipairs(args) do + if arg.start <= pos and arg.finish >= pos - 1 then + select = i + break + end + end + + local param = func:findEmmyParamByIndex(select) + if not param then + return + end + + param:eachEnum(function (enum) + if matchKey(word, enum) then + callback(enum, nil, CompletionItemKind.EnumMember, { + label = enum, + }) + end + end) +end + +local function searchCallArg(vm, source, word, callback, pos) + local results = {} + vm:eachSource(function (src) + if src.type == 'call' + and src.start <= pos + and src.finish >= pos + then + results[#results+1] = src + end + end) + if #results == 0 then + return nil + end + -- 可能处于 'func1(func2(' 的嵌套中,将最近的call放到最前面 + table.sort(results, function (a, b) + return a.start > b.start + end) + local call = results[1] + local args = call:bindCall() + if not args then + return + end + + local value = call:findCallFunction() + if not value then + return + end + + local lib = value:getLib() + if lib then + searchEnumAsLib(vm, source, word, callback, pos, args, lib) + return + end + + ---@type function + local func = value:getFunction() + if func then + searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func) + return + end +end + local function searchAllWords(vm, source, word, callback, pos) if word == '' then return |