diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-16 16:32:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-16 16:32:53 +0800 |
commit | 4cff67f7bee4304aecd1c4ce6f142eb030412bcf (patch) | |
tree | 5fca00cc728b7ef90d81f61f30b76f9ac3246279 /server/src/core/hover_function.lua | |
parent | 6e92a326b61686cb029ef773128a6040b7aa6125 (diff) | |
download | lua-language-server-4cff67f7bee4304aecd1c4ce6f142eb030412bcf.zip |
亲自指定参数位置
Diffstat (limited to 'server/src/core/hover_function.lua')
-rw-r--r-- | server/src/core/hover_function.lua | 35 |
1 files changed, 32 insertions, 3 deletions
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, |