diff options
-rw-r--r-- | script/core/completion.lua | 24 | ||||
-rw-r--r-- | test/completion/continue.lua | 14 |
2 files changed, 32 insertions, 6 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua index a2eaca4e..fb7b2eb4 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -1933,6 +1933,23 @@ local function makeCache(uri, offset, results) cache.length = #word end +local function isValidCache(word, result) + if result.kind == define.CompletionItemKind.Text then + return false + end + local match = result.match or result.label + if matchKey(word, match) then + return true + end + if result.textEdit then + match = result.textEdit.newText:match '[%w_]+' + if match and matchKey(word, match) then + return true + end + end + return false +end + local function getCache(uri, offset) local cache = workspace.getCache 'completion' if not cache.results then @@ -1952,12 +1969,7 @@ local function getCache(uri, offset) 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) - or (result.textEdit and matchKey(word, result.textEdit.newText:match '[%w_]*')) then + if isValidCache(word, result) then if result.textEdit then result.textEdit.finish = result.textEdit.finish + ext end diff --git a/test/completion/continue.lua b/test/completion/continue.lua index a548859a..4159ea7a 100644 --- a/test/completion/continue.lua +++ b/test/completion/continue.lua @@ -55,4 +55,18 @@ f 'abc$' } } +TEST [[ +---@type '"abcdefg"' +local t + +if t == 'abc$' +]] +{ + { + label = "'abcdefg'", + kind = define.CompletionItemKind.EnumMember, + textEdit = EXISTS, + } +} + ContinueTyping = false |