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_function.lua | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'server/src/core/hover_function.lua') diff --git a/server/src/core/hover_function.lua b/server/src/core/hover_function.lua index 4573bcc2..42a5f766 100644 --- a/server/src/core/hover_function.lua +++ b/server/src/core/hover_function.lua @@ -12,7 +12,6 @@ local function buildValueArgs(func, oo, select) end end local strs = {} - local argLabel local start = 1 if oo then start = 2 @@ -27,21 +26,46 @@ local function buildValueArgs(func, oo, select) max = math.max(#names, #values) end for i = start, max do + if i > start then + strs[#strs+1] = ', ' + end local name = names[i] local value = values[i] or 'any' + if i == select then + strs[#strs+1] = '@ARG' + end if name then strs[#strs+1] = name .. ': ' .. value else strs[#strs+1] = value end if i == select then - argLabel = strs[#strs] + strs[#strs+1] = '@ARG' end end if func.hasDots then + if max > 0 then + strs[#strs+1] = ', ' + end strs[#strs+1] = '...' 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 buildValueReturns(func) @@ -63,7 +87,12 @@ end return function (name, func, oo, select) local args, argLabel = buildValueArgs(func, oo, select) local returns = buildValueReturns(func) + 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, argLabel = argLabel, -- cgit v1.2.3