summaryrefslogtreecommitdiff
path: root/server/src/core/hover.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-16 16:32:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-16 16:32:53 +0800
commit4cff67f7bee4304aecd1c4ce6f142eb030412bcf (patch)
tree5fca00cc728b7ef90d81f61f30b76f9ac3246279 /server/src/core/hover.lua
parent6e92a326b61686cb029ef773128a6040b7aa6125 (diff)
downloadlua-language-server-4cff67f7bee4304aecd1c4ce6f142eb030412bcf.zip
亲自指定参数位置
Diffstat (limited to 'server/src/core/hover.lua')
-rw-r--r--server/src/core/hover.lua33
1 files changed, 28 insertions, 5 deletions
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index 9a2500f0..b40c6fa4 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -29,7 +29,6 @@ local function buildLibArgs(lib, oo, select)
start = 1
end
local strs = {}
- local argLabel
for i = start, #lib.args do
local arg = lib.args[i]
if arg.optional then
@@ -44,6 +43,9 @@ local function buildLibArgs(lib, oo, select)
end
local argStr = {}
+ if i == select then
+ argStr[#argStr+1] = '@ARG'
+ end
if arg.name then
argStr[#argStr+1] = ('%s: '):format(arg.name)
end
@@ -55,6 +57,9 @@ local function buildLibArgs(lib, oo, select)
if arg.default then
argStr[#argStr+1] = ('(%q)'):format(arg.default)
end
+ if i == select then
+ argStr[#argStr+1] = '@ARG'
+ end
for _, str in ipairs(argStr) do
strs[#strs+1] = str
@@ -62,16 +67,29 @@ local function buildLibArgs(lib, oo, select)
if arg.optional == 'self' then
strs[#strs+1] = ']'
end
- if i == select then
- argLabel = table.concat(argStr)
- end
end
for _, arg in ipairs(lib.args) do
if arg.optional == 'after' then
strs[#strs+1] = ']'
end
end
- return table.concat(strs), argLabel
+ local text = table.concat(strs)
+ local argLabel = {}
+ for i = 1, 2 do
+ local pos = text:find('@ARG', 1, true)
+ if pos then
+ if i == 1 then
+ argLabel[i] = pos
+ else
+ argLabel[i] = pos - 1
+ end
+ text = text:sub(1, pos-1) .. text:sub(pos+4)
+ end
+ end
+ if #argLabel == 0 then
+ argLabel = nil
+ end
+ return text, argLabel
end
local function buildLibReturns(lib)
@@ -177,7 +195,12 @@ local function getFunctionHoverAsLib(name, lib, oo, select)
local returns = buildLibReturns(lib)
local enum = buildEnum(lib)
local tip = lib.description
+ local headLen = #('function %s('):format(name)
local title = ('function %s(%s)%s'):format(name, args, returns)
+ if argLabel then
+ argLabel[1] = argLabel[1] + headLen
+ argLabel[2] = argLabel[2] + headLen
+ end
return {
label = title,
description = tip,