From 061c9b03686c7ae8b3dc70d491ff003258b13bf6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= <sumneko@hotmail.com>
Date: Tue, 24 Aug 2021 20:19:15 +0800
Subject: [PATCH] fix

---
 script/core/completion.lua   | 24 ++++++++++++++++++------
 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 a2eaca4ea..fb7b2eb4d 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 a548859a7..4159ea7ac 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
-- 
GitLab