summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/completion.lua2
-rw-r--r--script/files.lua40
2 files changed, 35 insertions, 7 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 26776634..653daff9 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -640,7 +640,7 @@ local function checkCommon(myUri, word, text, offset, results)
if not words then
goto CONTINUE
end
- for _, str in ipairs(words) do
+ for str in pairs(words) do
if #results >= 100 then
break
end
diff --git a/script/files.lua b/script/files.lua
index b84295bf..df49b183 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -278,13 +278,17 @@ function m.getWords(uri)
end
local mark = {}
for word in text:gmatch '([%a_][%w_]+)' do
- if #word >= 3 and not mark[word] then
- mark[word] = true
- local head = word:sub(1, 2)
- if not words[head] then
- words[head] = {}
+ if #word >= 3 then
+ if not mark[word] then
+ mark[word] = true
+ local head = word:sub(1, 2)
+ if not words[head] then
+ words[head] = {}
+ end
+ words[head][word] = true
end
- words[head][#words[head]+1] = word
+ else
+ words[word] = true
end
end
return words
@@ -303,6 +307,30 @@ function m.getWordsOfHead(uri, head)
return words[head]
end
+---@param uri uri
+---@param word string
+---@return boolean
+function m.hasWord(uri, word)
+ uri = getUriKey(uri)
+ local file = m.fileMap[uri]
+ if not file then
+ return false
+ end
+ local words = m.getWords(uri)
+ if not words then
+ return false
+ end
+ if #word <= 2 then
+ return words[word] == true
+ end
+ local head = word:sub(1, 2)
+ local headWords = words[head]
+ if not headWords then
+ return false
+ end
+ return headWords[word] == true
+end
+
--- 获取文件版本
function m.getVersion(uri)
uri = getUriKey(uri)