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/provider | |
parent | ee07ad02720ea8e36f08e1f7981d2b41cb7e9f07 (diff) | |
download | lua-language-server-b204653f81c4139fa1933ba0bdbc3ffe9678e82e.zip |
使用 completion/resolve 来分散计算压力
Diffstat (limited to 'script-beta/provider')
-rw-r--r-- | script-beta/provider/completion.lua | 2 | ||||
-rw-r--r-- | script-beta/provider/init.lua | 29 |
2 files changed, 24 insertions, 7 deletions
diff --git a/script-beta/provider/completion.lua b/script-beta/provider/completion.lua index d2df44d2..3db8b9de 100644 --- a/script-beta/provider/completion.lua +++ b/script-beta/provider/completion.lua @@ -23,7 +23,7 @@ local function enable() id = 'completion', method = 'textDocument/completion', registerOptions = { - resolveProvider = false, + resolveProvider = true, triggerCharacters = allWords(), }, }, diff --git a/script-beta/provider/init.lua b/script-beta/provider/init.lua index 1965f820..15731b46 100644 --- a/script-beta/provider/init.lua +++ b/script-beta/provider/init.lua @@ -304,7 +304,7 @@ proto.on('textDocument/completion', function (params) local lines = files.getLines(uri) local text = files.getText(uri) local offset = define.offset(lines, text, params.position) - local result = core(uri, offset) + local result = core.completion(uri, offset) local passed = os.clock() - clock if passed > 0.1 then log.warn(('Completion takes %.3f sec.'):format(passed)) @@ -317,16 +317,33 @@ proto.on('textDocument/completion', function (params) items[i] = { label = res.label, kind = res.kind, - detail = res.detail, - documentation = { - value = res.documentation, - kind = 'markdown', + data = res.id and { + version = files.globalVersion, + id = res.id, }, sortText = ('%04d'):format(i), insertText = res.insertText, insertTextFormat = res.insertTextFormat, } end - return items end) + +proto.on('completionItem/resolve', function (item) + local core = require 'core.completion' + if not item.data then + return item + end + local globalVersion = item.data.version + local id = item.data.id + if globalVersion ~= files.globalVersion then + return item + end + local resolved = core.resolve(id) + item.detail = resolved.detail + item.documentation = resolved.documentation and { + value = resolved.documentation, + kind = 'markdown', + } + return item +end) |