summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/completion.lua80
-rw-r--r--script-beta/provider/provider.lua4
-rw-r--r--test-beta/completion/init.lua7
3 files changed, 86 insertions, 5 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 9a5e7584..8a43a8d3 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -748,9 +748,85 @@ local function trySymbol(ast, text, offset, results)
end
end
-local function tryCallArg(ast, text, offset, results)
- local parent, oop = findParent(ast, text, offset)
+local function getCallEnums(source, index)
+ if source.type == 'library' and source.value.type == 'function' then
+ local func = source.value
+ if not func then
+ return nil
+ end
+ if not func.args then
+ return nil
+ end
+ if not func.enums then
+ return nil
+ end
+ local arg = func.args[index]
+ if not arg then
+ return nil
+ end
+ local argName = arg.name
+ if not argName then
+ return nil
+ end
+ local enums = {}
+ for _, enum in ipairs(func.enums) do
+ if enum.name == argName then
+ enums[#enums+1] = {
+ label = enum.enum,
+ description = enum.description,
+ }
+ end
+ end
+ return enums
+ end
+end
+
+local function mergeEnums(a, b)
+ local mark = {}
+ for _, enum in ipairs(a) do
+ mark[enum.label] = true
+ end
+ for _, enum in ipairs(b) do
+ if not mark[enum.label] then
+ mark[enum.label] = true
+ a[#a+1] = enum
+ end
+ end
+end
+
+local function findCall(ast, text, offset)
+ local call
+ guide.eachSourceContain(ast.ast, offset, function (src)
+ if src.type == 'call' then
+ if not call or call.start < src.start then
+ call = src
+ end
+ end
+ end)
+ return call
+end
+local function tryCallArg(ast, text, offset, results)
+ local call = findCall(ast, text, offset)
+ if not call then
+ return
+ end
+ local myResults = {}
+ local argIndex = 1
+ local defs = vm.getDefs(call.node)
+ for _, def in ipairs(defs) do
+ local enums = getCallEnums(def, argIndex)
+ if enums then
+ mergeEnums(myResults, enums)
+ end
+ end
+ for _, enum in ipairs(myResults) do
+ results[#results+1] = {
+ label = enum.label,
+ description = enum.description,
+ kind = ckind.EnumMember,
+ }
+ end
end
local function completion(uri, offset)
diff --git a/script-beta/provider/provider.lua b/script-beta/provider/provider.lua
index 01695fb4..6916ff96 100644
--- a/script-beta/provider/provider.lua
+++ b/script-beta/provider/provider.lua
@@ -328,6 +328,10 @@ proto.on('textDocument/completion', function (params)
sortText = ('%04d'):format(i),
insertText = res.insertText,
insertTextFormat = res.insertTextFormat,
+ documentation = res.description and {
+ value = res.description,
+ kind = 'markdown',
+ },
}
if res.id then
if easy and os.clock() - clock < 0.05 then
diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua
index 828e0ac4..d73ec4f4 100644
--- a/test-beta/completion/init.lua
+++ b/test-beta/completion/init.lua
@@ -45,6 +45,7 @@ function TEST(script)
assert(result == nil)
return
end
+ assert(result ~= nil)
for _, item in ipairs(result) do
core.resolve(item.id)
for k in pairs(item) do
@@ -448,14 +449,14 @@ end
},
}
--- TODO
-do return end
-
TEST [[
collectgarbage($)
]]
(EXISTS)
+-- TODO
+do return end
+
TEST [[
collectgarbage('$')
]]