summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-04-30 17:59:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-04-30 17:59:09 +0800
commit4ad097f786df90286c6212c8fc3c6472e8fd1368 (patch)
tree664ca8a9116d5008964cfcfa197ba49d356b6271
parente30e02d51f80b0d48e85fcc110d907ae4a6cbccd (diff)
downloadlua-language-server-4ad097f786df90286c6212c8fc3c6472e8fd1368.zip
stash
-rw-r--r--script/config.lua1
-rw-r--r--script/core/completion.lua36
-rw-r--r--test/completion/init.lua12
3 files changed, 39 insertions, 10 deletions
diff --git a/script/config.lua b/script/config.lua
index 8bc05b98..97df7c17 100644
--- a/script/config.lua
+++ b/script/config.lua
@@ -165,6 +165,7 @@ local ConfigTemplate = {
displayContext = {6, Integer},
workspaceWord = {true, Boolean},
autoRequire = {true, Boolean},
+ showParams = {true, Boolean},
},
signatureHelp = {
enable = {true, Boolean},
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 98a9250f..6f1a2952 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -199,7 +199,6 @@ local function buildFunction(results, source, oop, data)
if snipType == 'Both' or snipType == 'Replace' then
local snipData = util.deepCopy(data)
snipData.kind = define.CompletionItemKind.Snippet
- snipData.label = snipData.label .. '()'
snipData.insertText = buildFunctionSnip(source, oop)
snipData.insertTextFormat = 2
snipData.id = stack(function ()
@@ -401,7 +400,8 @@ end
local function checkFieldThen(name, src, word, start, offset, parent, oop, results)
local value = guide.getObjectValue(src) or src
local kind = define.CompletionItemKind.Field
- if value.type == 'function' then
+ if value.type == 'function'
+ or value.type == 'doc.type.function' then
if oop then
kind = define.CompletionItemKind.Method
else
@@ -453,6 +453,20 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul
}
end
+local function getParams(func)
+ local args = {}
+ for _, arg in ipairs(func.args) do
+ if arg.type == '...' then
+ args[#args+1] = '...'
+ elseif arg.type == 'doc.type.arg' then
+ args[#args+1] = arg.name[1]
+ else
+ args[#args+1] = arg[1]
+ end
+ end
+ return '(' .. table.concat(args, ', ') .. ')'
+end
+
local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals, isGlobal)
local fields = {}
local count = 0
@@ -470,8 +484,20 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res
if not matchKey(word, name, count >= 100) then
goto CONTINUE
end
+ local funcLabel
+ if config.config.completion.showParams then
+ local value = guide.getObjectValue(src) or src
+ if value.type == 'function'
+ or value.type == 'doc.type.function' then
+ funcLabel = name .. getParams(value)
+ fields[funcLabel] = src
+ fields[name] = false
+ count = count + 1
+ goto CONTINUE
+ end
+ end
local last = fields[name]
- if not last then
+ if last == nil then
fields[name] = src
count = count + 1
goto CONTINUE
@@ -491,7 +517,9 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res
::CONTINUE::
end
for name, src in util.sortPairs(fields) do
- checkFieldThen(name, src, word, start, offset, parent, oop, results)
+ if src then
+ checkFieldThen(name, src, word, start, offset, parent, oop, results)
+ end
end
end
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 22103896..1344d3af 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -175,11 +175,11 @@ ass$
]]
{
{
- label = 'assert',
+ label = 'assert(v, message)',
kind = define.CompletionItemKind.Function,
},
{
- label = 'assert()',
+ label = 'assert(v, message)',
kind = define.CompletionItemKind.Snippet,
},
}
@@ -201,11 +201,11 @@ _G.ass$
]]
{
{
- label = 'assert',
+ label = 'assert(v, message)',
kind = define.CompletionItemKind.Function,
},
{
- label = 'assert()',
+ label = 'assert(v, message)',
kind = define.CompletionItemKind.Snippet,
},
}
@@ -217,11 +217,11 @@ ff$
]]
{
{
- label = 'ffff',
+ label = 'assert(a, b)',
kind = define.CompletionItemKind.Function,
},
{
- label = 'ffff()',
+ label = 'assert(a, b)',
kind = define.CompletionItemKind.Snippet,
}
}