summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-02 14:57:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-02 14:57:23 +0800
commitff4513f65d5c09fb84544263a6a90aa7b8197a4e (patch)
tree9315d57b4f311446cf79a9c24221636cb42cddf8 /script
parent7360b34f9a6f9bf51a5843b065431f7f4eeef42b (diff)
downloadlua-language-server-ff4513f65d5c09fb84544263a6a90aa7b8197a4e.zip
update
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua47
-rw-r--r--script/core/infer.lua19
2 files changed, 46 insertions, 20 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 7b8113f1..064dcc28 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1244,7 +1244,30 @@ function (%s)\
end"):format(table.concat(args, ', '))
end
-local function getCallEnums(source, index)
+local function pushCallEnumsAndFuncs(defs)
+ local results = {}
+ for _, def in ipairs(defs) do
+ if def.type == 'doc.type.enum'
+ or def.type == 'doc.resume' then
+ results[#results+1] = {
+ label = def[1],
+ description = def.comment,
+ kind = define.CompletionItemKind.EnumMember,
+ }
+ end
+ if def.type == 'doc.type.function' then
+ results[#results+1] = {
+ label = infer.viewDocFunction(def),
+ description = def.comment,
+ kind = define.CompletionItemKind.Function,
+ insertText = buildInsertDocFunction(def),
+ }
+ end
+ end
+ return results
+end
+
+local function getCallEnumsAndFuncs(source, index)
if source.type == 'function' and source.bindDocs then
if not source.args then
return
@@ -1263,26 +1286,10 @@ local function getCallEnums(source, index)
for _, doc in ipairs(source.bindDocs) do
if doc.type == 'doc.param'
and doc.param[1] == arg[1] then
- local enums = {}
- for _, enum in ipairs(vm.getDocEnums(doc.extends)) do
- enums[#enums+1] = {
- label = enum[1],
- description = enum.comment,
- kind = define.CompletionItemKind.EnumMember,
- }
- end
- return enums
+ return pushCallEnumsAndFuncs(vm.getDefs(doc.extends))
elseif doc.type == 'doc.vararg'
and arg.type == '...' then
- local enums = {}
- for _, enum in ipairs(vm.getDocEnums(doc.vararg)) do
- enums[#enums+1] = {
- label = enum[1],
- description = enum.comment,
- kind = define.CompletionItemKind.EnumMember,
- }
- end
- return enums
+ return pushCallEnumsAndFuncs(vm.getDefs(doc.vararg))
end
end
end
@@ -1420,7 +1427,7 @@ local function tryCallArg(ast, text, offset, results)
local defs = vm.getDefs(call.node)
for _, def in ipairs(defs) do
def = searcher.getObjectValue(def) or def
- local enums = getCallEnums(def, argIndex)
+ local enums = getCallEnumsAndFuncs(def, argIndex)
if enums then
mergeEnums(myResults, enums, arg)
end
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 9aebf8b0..c3e507cc 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -365,6 +365,25 @@ function m.getDocName(doc)
end
end
+function m.viewDocFunction(doc)
+ if doc.type ~= 'doc.type.function' then
+ return ''
+ end
+ local args = {}
+ for i, arg in ipairs(doc.args) do
+ args[i] = ('%s: %s'):format(arg.name[1], m.viewDocName(arg.extends))
+ end
+ local label = ('fun(%s)'):format(table.concat(args, ', '))
+ if #doc.returns > 0 then
+ local returns = {}
+ for i, rtn in ipairs(doc.returns) do
+ returns[i] = m.viewDocName(rtn)
+ end
+ label = ('%s:%s'):format(label, table.concat(returns))
+ end
+ return label
+end
+
---显示对象的推断类型
---@param source parser.guide.object
---@return string