diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-13 20:25:59 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-13 20:25:59 +0800 |
commit | 2f8a2d9cdc4ea0b9f7de870113a400ddb0fa7c66 (patch) | |
tree | f01f1d693665fb277114c87e1d669da0fc89944c /server | |
parent | 6cfd613662f54fead966e4aa3c1d1aa4616c8eb5 (diff) | |
download | lua-language-server-2f8a2d9cdc4ea0b9f7de870113a400ddb0fa7c66.zip |
自动完成参数检查是否在函数或表内
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 32 | ||||
-rw-r--r-- | server/test/completion/init.lua | 11 |
2 files changed, 43 insertions, 0 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 22ee8167..e3606ef5 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -575,6 +575,34 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun end) end +local function getSelect(args, pos) + if not args then + return 1 + end + for i, arg in ipairs(args) do + if arg.start <= pos and arg.finish >= pos - 1 then + return i + end + end + return #args + 1 +end + +local function isInFunctionOrTable(call, pos) + local args = call:bindCall() + if not args then + return false + end + local select = getSelect(args, pos) + local arg = args[select] + if not arg then + return false + end + if arg.type == 'function' or arg.type == 'table' then + return true + end + return false +end + local function searchCallArg(vm, source, word, callback, pos) local results = {} vm:eachSource(function (src) @@ -593,6 +621,10 @@ local function searchCallArg(vm, source, word, callback, pos) return a.start > b.start end) local call = results[1] + if isInFunctionOrTable(call, pos) then + return + end + local args = call:bindCall() if not args then return diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index f288af2a..5e9b303e 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -1173,3 +1173,14 @@ f($) kind = CompletionItemKind.EnumMember, } } + +TEST [[ +---@param x function | 'function () end' +function f(x) +end + +f(function () + $ +end) +]] +(nil) |