diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-10 14:46:31 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-10 14:46:31 +0800 |
commit | b204653f81c4139fa1933ba0bdbc3ffe9678e82e (patch) | |
tree | e1eccea76d975122104e7ff47021c25613afe214 /script-beta/core/completion.lua | |
parent | ee07ad02720ea8e36f08e1f7981d2b41cb7e9f07 (diff) | |
download | lua-language-server-b204653f81c4139fa1933ba0bdbc3ffe9678e82e.zip |
使用 completion/resolve 来分散计算压力
Diffstat (limited to 'script-beta/core/completion.lua')
-rw-r--r-- | script-beta/core/completion.lua | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 2dae0b90..b3e5fe28 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -10,6 +10,26 @@ local getArg = require 'core.hover.arg' local config = require 'config' local util = require 'utility' +local stackID = 0 +local stacks = {} +local function stack(callback) + stackID = stackID + 1 + stacks[stackID] = callback + return stackID +end + +local function clearStack() + stacks = {} +end + +local function resolveStack(id) + local callback = stacks[id] + if not callback then + return nil + end + return callback() +end + local function isSpace(char) if char == ' ' or char == '\n' @@ -79,7 +99,11 @@ local function checkLocal(ast, word, offset, results) results[#results+1] = { label = name, kind = ckind.Variable, - detail = getLabel(source), + id = stack(function () + return { + detail = getLabel(source), + } + end), } end end @@ -151,8 +175,12 @@ local function checkLibrary(ast, text, word, offset, results) buildFunction(results, lib, false, { label = name, kind = ckind.Function, - documentation = lib.description, - detail = getLabel(lib), + id = stack(function () + return { + detail = getLabel(lib), + documentation = lib.description, + } + end), }) end end @@ -198,11 +226,12 @@ local function tryWord(ast, text, offset, results) checkCommon(word, text, results) end -return function (uri, offset) +local function completion(uri, offset) local ast = files.getAst(uri) if not ast then return nil end + clearStack() local text = files.getText(uri) local results = {} @@ -213,3 +242,12 @@ return function (uri, offset) end return results end + +local function resolve(id) + return resolveStack(id) +end + +return { + completion = completion, + resolve = resolve, +} |