diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/completion.lua | 19 | ||||
-rw-r--r-- | script/files.lua | 43 |
2 files changed, 47 insertions, 15 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua index d5cca4e0..26776634 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -636,22 +636,11 @@ local function checkCommon(myUri, word, text, offset, results) if myUri and files.eq(myUri, uri) then goto CONTINUE end - local cache = files.getCache(uri) - if not cache.commonWords then - cache.commonWords = {} - local mark = {} - for str in files.getText(uri):gmatch '([%a_][%w_]+)' do - if #str >= 3 and not mark[str] then - mark[str] = true - local head = str:sub(1, 2) - if not cache.commonWords[head] then - cache.commonWords[head] = {} - end - cache.commonWords[head][#cache.commonWords[head]+1] = str - end - end + local words = files.getWordsOfHead(uri, myHead) + if not words then + goto CONTINUE end - for _, str in ipairs(cache.commonWords[myHead] or {}) do + for _, str in ipairs(words) do if #results >= 100 then break end diff --git a/script/files.lua b/script/files.lua index e4729464..b84295bf 100644 --- a/script/files.lua +++ b/script/files.lua @@ -191,6 +191,7 @@ function m.setText(uri, text, isTrust, instance) file.text = newText file.trusted = isTrust file.originText = text + file.words = nil m.linesMap[uri] = nil m.originLinesMap[uri] = nil m.astMap[uri] = nil @@ -260,6 +261,48 @@ function m.setCachedRows(uri, rows) file.rows = rows end +function m.getWords(uri) + uri = getUriKey(uri) + local file = m.fileMap[uri] + if not file then + return + end + if file.words then + return file.words + end + local words = {} + file.words = words + local text = file.text + if not text then + return + 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] = {} + end + words[head][#words[head]+1] = word + end + end + return words +end + +function m.getWordsOfHead(uri, head) + uri = getUriKey(uri) + local file = m.fileMap[uri] + if not file then + return nil + end + local words = m.getWords(uri) + if not words then + return nil + end + return words[head] +end + --- 获取文件版本 function m.getVersion(uri) uri = getUriKey(uri) |