summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-06-26 18:09:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-06-26 18:09:32 +0800
commit6fb028ef9e053076170ed03e46b9a4ab5d248e0c (patch)
tree0083af91c2dbdccfe44047db461a8b989ae8d788 /server
parentf8407a7ed2faa1892ab63fbaed5539420af90180 (diff)
downloadlua-language-server-6fb028ef9e053076170ed03e46b9a4ab5d248e0c.zip
参数提示支持多原型
Diffstat (limited to 'server')
-rw-r--r--server/src/core/signature.lua33
-rw-r--r--server/src/method/textDocument/signatureHelp.lua26
2 files changed, 38 insertions, 21 deletions
diff --git a/server/src/core/signature.lua b/server/src/core/signature.lua
index 92b44e32..62aa5b3c 100644
--- a/server/src/core/signature.lua
+++ b/server/src/core/signature.lua
@@ -47,15 +47,15 @@ local function getFunctionSource(call)
return nil
end
-local function getHover(call, pos)
+local function hovers(call, pos)
local args = call:bindCall()
if not args then
- return
+ return nil
end
local value = call:findCallFunction()
if not value then
- return
+ return nil
end
local select = getSelect(args, pos)
@@ -63,20 +63,29 @@ local function getHover(call, pos)
local object = source:get 'object'
local lib, fullkey = findLib(source)
local name = fullkey or buildValueName(source)
- local hover
+ local hovers = {}
if lib then
- hover = getFunctionHoverAsLib(name, lib, object, select)
+ hovers[#hovers+1] = getFunctionHoverAsLib(name, lib, object, select)
else
local emmy = value:getEmmy()
if emmy and emmy.type == 'emmy.functionType' then
- hover = getFunctionHoverAsEmmy(name, emmy, object, select)
+ hovers[#hovers+1] = getFunctionHoverAsEmmy(name, emmy, object, select)
else
- hover = getFunctionHover(name, value:getFunction(), object, select)
+ ---@type emmyFunction
+ local func = value:getFunction()
+ hovers[#hovers+1] = getFunctionHover(name, func, object, select)
+ local overLoads = func and func:getEmmyOverLoads()
+ if overLoads then
+ for _, ol in ipairs(overLoads) do
+ hovers[#hovers+1] = getFunctionHoverAsEmmy(name, ol, object, select)
+ end
+ end
end
end
- if hover and hover.argLabel then
- return hover
+ if #hovers == 0 then
+ return nil
end
+ return hovers
end
local function isInFunctionOrTable(call, pos)
@@ -109,12 +118,8 @@ return function (vm, pos)
if isInFunctionOrTable(nearCall, pos) then
return nil
end
- -- TODO 重构后改成显示多原型
- local hovers = { getHover(nearCall, pos) }
- if #hovers == 0 then
- return nil
- end
+ local hovers = hovers(nearCall, pos)
return hovers
end
diff --git a/server/src/method/textDocument/signatureHelp.lua b/server/src/method/textDocument/signatureHelp.lua
index 9829917d..fa8c91f6 100644
--- a/server/src/method/textDocument/signatureHelp.lua
+++ b/server/src/method/textDocument/signatureHelp.lua
@@ -12,28 +12,40 @@ return function (lsp, params)
return
end
+ local description = hovers[1].description
+ table.sort(hovers, function (a, b)
+ return a.label < b.label
+ end)
+
+ local active
local signatures = {}
for i, hover in ipairs(hovers) do
- signatures[i] = {
+ local signature = {
label = hover.label,
documentation = {
kind = 'markdown',
value = hover.description,
},
- parameters = {
+ }
+ if hover.argLabel then
+ if not active then
+ active = i
+ end
+ signature.parameters = {
{
label = {
hover.argLabel[1] - 1,
hover.argLabel[2],
- },
- },
- },
- }
+ }
+ }
+ }
+ end
+ signatures[i] = signature
end
local response = {
signatures = signatures,
- activeSignature = 0,
+ activeSignature = active and active - 1 or 0,
}
return response