diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-08-23 20:50:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-08-23 20:50:15 +0800 |
commit | fd13e793d1229a7290a998c6705ad224ffc1f1a9 (patch) | |
tree | 6817d948c73506d3ab7b9489408d13109505b228 | |
parent | d84b3137321e6d61e165b8450236c879aee6360f (diff) | |
download | lua-language-server-fd13e793d1229a7290a998c6705ad224ffc1f1a9.zip |
fix
-rw-r--r-- | script/core/completion.lua | 33 | ||||
-rw-r--r-- | test/completion/continue.lua | 12 |
2 files changed, 32 insertions, 13 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua index 98e388c3..843a8317 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -302,6 +302,7 @@ local function checkLocal(ast, word, offset, results) local funcLabel = name .. getParams(def, false) buildFunction(results, source, def, false, { label = funcLabel, + match = name, insertText = name, kind = define.CompletionItemKind.Function, id = stack(function () @@ -469,6 +470,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul buildFunction(results, src, value, oop, { label = name, kind = kind, + match = name:match '^[^(]+', insertText = name:match '^[^(]+', deprecated = vm.isDeprecated(src) or nil, id = stack(function () @@ -853,6 +855,7 @@ local function checkFunctionArgByDocParam(ast, word, start, results) end results[#results+1] = { label = table.concat(label, ', '), + match = firstParam.param[1], kind = define.CompletionItemKind.Snippet, } end @@ -1016,6 +1019,7 @@ local function checkLenPlusOne(ast, text, offset, results) end results[#results+1] = { label = label, + match = nodeText, kind = define.CompletionItemKind.Snippet, textEdit = { start = pos, @@ -1945,22 +1949,25 @@ local function getCache(uri, offset) local ext = #word - cache.length cache.length = #word - for _, result in ipairs(cache.results) do - if result.textEdit then - result.textEdit.finish = result.textEdit.finish + ext + local results = cache.results + for i = #results, 1, -1 do + local result = results[i] + local match = result.match or result.label + if results.enableCommon and result.kind == define.CompletionItemKind.Text then + results[i] = results[#results] + results[#results] = nil + elseif matchKey(word, match) then + if result.textEdit then + result.textEdit.finish = result.textEdit.finish + ext + end + else + results[i] = results[#results] + results[#results] = nil end end - if cache.results.enableCommon then - local results = cache.results - for i = #results, 1, -1 do - local res = results[i] - if res.kind == define.CompletionItemKind.Text then - results[i] = results[#results] - results[#results] = nil - end - end - checkCommon(nil, word, text, offset, results) + if results.enableCommon then + checkCommon(uri, word, text, offset, results) end return cache.results diff --git a/test/completion/continue.lua b/test/completion/continue.lua index 4644c745..96ec4964 100644 --- a/test/completion/continue.lua +++ b/test/completion/continue.lua @@ -29,4 +29,16 @@ io.z$ } } + +TEST [[ +-- provider +pro$ +]] +{ + { + label = 'provider', + kind = define.CompletionItemKind.Text, + } +} + ContinueTyping = false |