summaryrefslogtreecommitdiff
path: root/script/core/completion.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-27 16:24:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-27 16:24:02 +0800
commit219c802e4e6a67aa9c4a1b4a5bd7886f8181b7c4 (patch)
tree4acfbd7290555928768f866085c5567499b85f82 /script/core/completion.lua
parentb436b123d67e1c5aa3945da404109fbeb12bdb53 (diff)
downloadlua-language-server-219c802e4e6a67aa9c4a1b4a5bd7886f8181b7c4.zip
improve performance of completion
Diffstat (limited to 'script/core/completion.lua')
-rw-r--r--script/core/completion.lua54
1 files changed, 52 insertions, 2 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 00e5d8f7..1a750923 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1690,6 +1690,39 @@ local function tryComment(ast, text, offset, results)
checkCommon(ast, word, text, offset, results)
end
+local function makeCache(uri, offset, results)
+ local cache = workspace.getCache 'completion'
+ if not uri then
+ cache.results = nil
+ return
+ end
+ local text = files.getText(uri)
+ local word = findWord(text, offset)
+ if not word or #word <= 2 then
+ cache.results = nil
+ return
+ end
+ cache.results = results
+ cache.offset = offset
+ cache.word = word
+end
+
+local function getCache(uri, offset)
+ local cache = workspace.getCache 'completion'
+ if not cache.results then
+ return nil
+ end
+ local text = files.getText(uri)
+ local word = findWord(text, offset)
+ if not word or #word <= 2 then
+ return nil
+ end
+ if word:sub(1, #cache.word) ~= cache.word then
+ return nil
+ end
+ return cache.results
+end
+
local function completion(uri, offset)
tracy.ZoneBeginN 'completion.getAst'
local ast = files.getAst(uri)
@@ -1729,7 +1762,24 @@ local function resolve(id)
return resolveStack(id)
end
+local function resolveCache(item)
+ local cache = workspace.getCache 'completion'
+ if not cache.results then
+ return
+ end
+ for i, res in ipairs(cache.results) do
+ if res.data and res.data.id == item.data.id then
+ item.data.id = nil
+ cache.results[i] = item
+ break
+ end
+ end
+end
+
return {
- completion = completion,
- resolve = resolve,
+ completion = completion,
+ resolve = resolve,
+ makeCache = makeCache,
+ getCache = getCache,
+ resolveCache = resolveCache,
}