summaryrefslogtreecommitdiff
path: root/script/files.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-28 17:23:14 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-28 17:23:14 +0800
commite1cdcbe08aecb3a9c70cc0ce9c9bdd4a59dada0c (patch)
tree80b2a20400eae23922520fc8d03d1836b7e02153 /script/files.lua
parent9c6b9bda1a797213aa896eb705b16a232c71fee9 (diff)
downloadlua-language-server-e1cdcbe08aecb3a9c70cc0ce9c9bdd4a59dada0c.zip
cleanup
Diffstat (limited to 'script/files.lua')
-rw-r--r--script/files.lua40
1 files changed, 34 insertions, 6 deletions
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)