diff options
Diffstat (limited to 'script/core/signature.lua')
-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 |