From a8c95b64d7e8a8481cbe961b8b872ef0710d618f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 16:37:29 +0800 Subject: fix call snip --- script/core/completion.lua | 20 ++++++-------------- test/completion/init.lua | 5 +++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/script/core/completion.lua b/script/core/completion.lua index 60c3e16d..ee61029d 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -121,17 +121,9 @@ local function findParentInStringIndex(ast, text, offset) return parent.node, false end -local function buildFunctionSnip(source, oop) +local function buildFunctionSnip(source, value, oop) local name = getName(source):gsub('^.+[$.:]', '') - local defs = vm.getDefs(source, 0) - local args = '' - for _, def in ipairs(defs) do - local defArgs = getArg(def, oop) - if defArgs ~= '' then - args = defArgs - break - end - end + local args = getArg(value, oop) local id = 0 args = args:gsub('[^,]+', function (arg) id = id + 1 @@ -191,7 +183,7 @@ local function buildDesc(source) return md:string() end -local function buildFunction(results, source, oop, data) +local function buildFunction(results, source, value, oop, data) local snipType = config.config.completion.callSnippet if snipType == 'Disable' or snipType == 'Both' then results[#results+1] = data @@ -199,7 +191,7 @@ local function buildFunction(results, source, oop, data) if snipType == 'Both' or snipType == 'Replace' then local snipData = util.deepCopy(data) snipData.kind = define.CompletionItemKind.Snippet - snipData.insertText = buildFunctionSnip(source, oop) + snipData.insertText = buildFunctionSnip(source, value, oop) snipData.insertTextFormat = 2 snipData.id = stack(function () return { @@ -286,7 +278,7 @@ local function checkLocal(ast, word, offset, results) if def.type == 'function' or def.type == 'doc.type.function' then local funcLabel = name .. getParams(def, false) - buildFunction(results, source, false, { + buildFunction(results, source, def, false, { label = funcLabel, insertText = name, kind = define.CompletionItemKind.Function, @@ -434,7 +426,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul else kind = define.CompletionItemKind.Function end - buildFunction(results, src, oop, { + buildFunction(results, src, value, oop, { label = name, kind = kind, insertText = name:match '^[^(]+', diff --git a/test/completion/init.lua b/test/completion/init.lua index b2cac99d..89772853 100644 --- a/test/completion/init.lua +++ b/test/completion/init.lua @@ -2479,6 +2479,7 @@ TEST [[ } } +Cared['insertText'] = true TEST [[ ---@overload fun(a: any, b: any) local function zzzz(a) end @@ -2488,17 +2489,21 @@ zzzz$ { label = 'zzzz(a)', kind = define.CompletionItemKind.Function, + insertText = 'zzzz', }, { label = 'zzzz(a)', kind = define.CompletionItemKind.Snippet, + insertText = 'zzzz(${1:a: any})', }, { label = 'zzzz(a, b)', kind = define.CompletionItemKind.Function, + insertText = 'zzzz', }, { label = 'zzzz(a, b)', kind = define.CompletionItemKind.Snippet, + insertText = 'zzzz(${1:a: any}, ${2:b: any})', }, } -- cgit v1.2.3