From bb45b7ba340fc9bc1e1571587ddfdff5afa087fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 3 Nov 2020 16:38:23 +0800 Subject: =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=8F=82=E6=95=B0=E5=8F=82=E8=80=83?= =?UTF-8?q?=20doc.param?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/core/completion.lua | 51 ++++++++++++++++++++++++++++++++++++++++- test-beta/completion/init.lua | 1 - 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 42f56e06..8612bd62 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -87,7 +87,8 @@ local function findSymbol(text, offset) goto CONTINUE end if char == '.' - or char == ':' then + or char == ':' + or char == '(' then return char, i else return nil @@ -588,6 +589,50 @@ local function checkProvideLocal(ast, word, start, results) end) end +local function checkFunctionArgByDocParam(ast, word, start, results) + local func = guide.eachSourceContain(ast.ast, start, function (source) + if source.type == 'function' then + return source + end + end) + if not func then + return + end + local docs = func.bindDocs + if not docs then + return + end + local params = {} + for _, doc in ipairs(docs) do + if doc.type == 'doc.param' then + params[#params+1] = doc + end + end + local firstArg = func.args and func.args[1] + if not firstArg + or firstArg.start <= start and firstArg.finish >= start then + local firstParam = params[1] + if firstParam and matchKey(word, firstParam.param[1]) then + local label = {} + for _, param in ipairs(params) do + label[#label+1] = param.param[1] + end + results[#results+1] = { + label = table.concat(label, ', '), + kind = define.CompletionItemKind.Snippet, + } + end + end + for _, doc in ipairs(params) do + if matchKey(word, doc.param[1]) then + results[#results+1] = { + label = doc.param[1], + kind = define.CompletionItemKind.Interface, + } + end + end +end + local function isAfterLocal(text, start) local pos = skipSpace(text, start-1) local word = findWord(text, pos) @@ -776,6 +821,7 @@ local function tryWord(ast, text, offset, results) end elseif isFuncArg(ast, offset) then checkProvideLocal(ast, word, start, results) + checkFunctionArgByDocParam(ast, word, start, results) else local afterLocal = isAfterLocal(text, start) local stop = checkKeyWord(ast, text, start, word, hasSpace, afterLocal, results) @@ -814,6 +860,9 @@ local function trySymbol(ast, text, offset, results) checkField(ast, '', start, offset, parent, oop, results) end end + if symbol == '(' then + checkFunctionArgByDocParam(ast, '', start, results) + end end local function getCallEnums(source, index) diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index 630c9b47..f6ddf501 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -1365,7 +1365,6 @@ end ]] (EXISTS) -do return end TEST [[ ---@param xyz Class ---@param xxx Class -- cgit v1.2.3