diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-14 21:03:47 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-14 21:03:47 +0800 |
commit | 28961050d5c5994f2cd65ebcc67a9d66318c1052 (patch) | |
tree | 6b736632f19497ab566e7eef8b7d71b7f948be1b /script/core | |
parent | 40f1c261e52898d3c9d187bde02033f6071a187d (diff) | |
download | lua-language-server-28961050d5c5994f2cd65ebcc67a9d66318c1052.zip |
resolve #1112
only show signatures matching the entered parameters
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/signature.lua | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/script/core/signature.lua b/script/core/signature.lua index 91b1156d..21e954bf 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -68,27 +68,30 @@ local function makeOneSignature(source, oop, index) } end -- 不定参数 - if index > i and i > 0 then + if index and index > i and i > 0 then local lastLabel = params[i].label local text = label:sub(lastLabel[1] + 1, lastLabel[2]) if text:sub(1, 3) == '...' then index = i end end + if #params < (index or 0) then + return nil + end return { label = label, params = params, - index = index, + index = index or 1, description = hoverDesc(source), } end ---@async local function makeSignatures(text, call, pos) - local node = call.node - local oop = node.type == 'method' - or node.type == 'getmethod' - or node.type == 'setmethod' + local func = call.node + local oop = func.type == 'method' + or func.type == 'getmethod' + or func.type == 'setmethod' local index if call.args then local args = {} @@ -124,13 +127,13 @@ local function makeSignatures(text, call, pos) index = #args end end - else - index = 1 end local signs = {} - local defs = vm.getDefs(node) + local node = vm.compileNode(func) + ---@type vm.node + node = node:getData 'originNode' or node local mark = {} - for _, src in ipairs(defs) do + for src in node:eachObject() do if src.type == 'function' or src.type == 'doc.type.function' then if not mark[src] then @@ -159,5 +162,8 @@ return function (uri, pos) if not signs or #signs == 0 then return nil end + table.sort(signs, function (a, b) + return #a.params < #b.params + end) return signs end |