From b204653f81c4139fa1933ba0bdbc3ffe9678e82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 10 Dec 2019 14:46:31 +0800 Subject: =?UTF-8?q?=E4=BD=BF=E7=94=A8=20completion/resolve=20=E6=9D=A5?= =?UTF-8?q?=E5=88=86=E6=95=A3=E8=AE=A1=E7=AE=97=E5=8E=8B=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/provider/completion.lua | 2 +- script-beta/provider/init.lua | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'script-beta/provider') 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) -- cgit v1.2.3