From 4cff67f7bee4304aecd1c4ce6f142eb030412bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 16 Jan 2019 16:32:53 +0800 Subject: =?UTF-8?q?=E4=BA=B2=E8=87=AA=E6=8C=87=E5=AE=9A=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/hover.lua | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'server/src/core/hover.lua') 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, -- cgit v1.2.3