summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/completion.lua46
-rw-r--r--script-beta/provider/completion.lua2
-rw-r--r--script-beta/provider/init.lua29
3 files changed, 66 insertions, 11 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,
+}
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)