diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-21 21:42:06 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-21 21:42:06 +0800 |
commit | 079847053a3020600a9fd0c35e12a9f7e8d57f16 (patch) | |
tree | a991917bef281a4ecab8356634c678292ea13128 /server | |
parent | 736373ad83a7505aa2f088c889c45a518695e571 (diff) | |
download | lua-language-server-079847053a3020600a9fd0c35e12a9f7e8d57f16.zip |
简化 signature
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/hover/emmy_function.lua | 11 | ||||
-rw-r--r-- | server/src/core/hover/function.lua | 11 | ||||
-rw-r--r-- | server/src/core/hover/lib_function.lua | 11 | ||||
-rw-r--r-- | server/src/core/signature.lua | 22 | ||||
-rw-r--r-- | server/src/method/textDocument/signatureHelp.lua | 3 | ||||
-rw-r--r-- | server/test/crossfile/hover.lua | 14 | ||||
-rw-r--r-- | server/test/signature/init.lua | 30 |
7 files changed, 46 insertions, 56 deletions
diff --git a/server/src/core/hover/emmy_function.lua b/server/src/core/hover/emmy_function.lua index e14e88c5..37b44a79 100644 --- a/server/src/core/hover/emmy_function.lua +++ b/server/src/core/hover/emmy_function.lua @@ -124,15 +124,10 @@ return function (name, emmy, object, select) local returns = buildEmmyReturns(emmy) local enum, rawEnum = buildEnum(emmy) local tip = emmy.description - local headLen = #('function %s('):format(name) - local title = ('function %s(%s)'):format(name, argStr) - if argLabel then - argLabel[1] = argLabel[1] + headLen - argLabel[2] = argLabel[2] + headLen - end return { - label = title .. returns, - title = title, + label = ('function %s(%s)%s'):format(name, argStr, returns), + name = name, + argStr = argStr, returns = returns, description = tip, enum = enum, diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index 25796d60..8796be57 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -228,15 +228,10 @@ return function (name, func, object, select) local enum, rawEnum = buildEnum(func) local comment = getComment(func) local overloads = getOverLoads(name, func, object, select) - local headLen = #('function %s('):format(name) - local title = ('function %s(%s)'):format(name, argStr) - if argLabel then - argLabel[1] = argLabel[1] + headLen - argLabel[2] = argLabel[2] + headLen - end return { - label = title .. returns, - title = title, + label = ('function %s(%s)%s'):format(name, argStr, returns), + name = name, + argStr = argStr, returns = returns, description = comment, enum = enum, diff --git a/server/src/core/hover/lib_function.lua b/server/src/core/hover/lib_function.lua index 3c693961..bd9cddaa 100644 --- a/server/src/core/hover/lib_function.lua +++ b/server/src/core/hover/lib_function.lua @@ -207,15 +207,10 @@ return function (name, lib, object, select) local enum, rawEnum = buildEnum(lib) local tip = lib.description local doc = buildDoc(lib) - local headLen = #('function %s('):format(name) - local title = ('function %s(%s)'):format(name, argStr) - if argLabel then - argLabel[1] = argLabel[1] + headLen - argLabel[2] = argLabel[2] + headLen - end return { - label = title .. returns, - title = title, + label = ('function %s(%s)%s'):format(name, argStr, returns), + name = name, + argStr = argStr, returns = returns, description = tip, enum = enum, diff --git a/server/src/core/signature.lua b/server/src/core/signature.lua index 3c9e696c..bbe35ffa 100644 --- a/server/src/core/signature.lua +++ b/server/src/core/signature.lua @@ -47,7 +47,7 @@ local function getFunctionSource(call) return nil end -local function hovers(call, pos) +local function getHover(call, pos) local args = call:bindCall() if not args then return nil @@ -82,10 +82,7 @@ local function hovers(call, pos) end end end - if not hover then - return nil - end - return { hover } + return hover end local function isInFunctionOrTable(call, pos) @@ -119,7 +116,18 @@ return function (vm, pos) return nil end - local hovers = hovers(nearCall, pos) + local hover = getHover(nearCall, pos) + if not hover then + return nil + end - return hovers + -- skip `name(` + local head = #hover.name + 1 + hover.label = ('%s(%s)'):format(hover.name, hover.argStr) + if hover.argLabel then + hover.argLabel[1] = hover.argLabel[1] + head + hover.argLabel[2] = hover.argLabel[2] + head + end + + return { hover } end diff --git a/server/src/method/textDocument/signatureHelp.lua b/server/src/method/textDocument/signatureHelp.lua index e898d32f..01d6289d 100644 --- a/server/src/method/textDocument/signatureHelp.lua +++ b/server/src/method/textDocument/signatureHelp.lua @@ -14,13 +14,12 @@ return function (lsp, params) local hover = hovers[1] local desc = {} - desc[#desc+1] = '```lua\n' .. hover.label .. '\n```\n' desc[#desc+1] = hover.description local active local signatures = {} for i, hover in ipairs(hovers) do local signature = { - label = hover.title, + label = hover.label, documentation = { kind = 'markdown', value = table.concat(desc, '\n'), diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua index dc6df615..b0e5a55f 100644 --- a/server/test/crossfile/hover.lua +++ b/server/test/crossfile/hover.lua @@ -123,7 +123,7 @@ TEST { label = 'function f(a: any, b: any)', name = 'f', args = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, } } @@ -147,7 +147,7 @@ TEST { label = 'function (a: any, b: any)', name = '', args = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, } } @@ -179,7 +179,7 @@ TEST { label = 'function mt:add(a: any, b: any)', name = 'mt:add', args = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, }, } @@ -251,7 +251,7 @@ TEST { name = 'f', description = 'abc', args = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, } } @@ -294,7 +294,7 @@ TEST { name = 'f', args = EXISTS, rawEnum = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, enum = [[ @@ -324,7 +324,7 @@ TEST { name = 'f', args = EXISTS, rawEnum = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, enum = [[ @@ -351,7 +351,7 @@ TEST { label = 'function f(x: string, y: string)', name = 'f', args = EXISTS, - title = EXISTS, + argStr = EXISTS, returns = EXISTS, description = [[ + `x`*(string)*: aaaa diff --git a/server/test/signature/init.lua b/server/test/signature/init.lua index a2a647e7..d5bc19c0 100644 --- a/server/test/signature/init.lua +++ b/server/test/signature/init.lua @@ -36,8 +36,8 @@ end x($ ]] { - label = "function x(a: any, b: any)", - arg = {12, 17}, + label = "x(a: any, b: any)", + arg = {3, 8}, } TEST [[ @@ -47,8 +47,8 @@ end x($) ]] { - label = "function x(a: any, b: any)", - arg = {12, 17}, + label = "x(a: any, b: any)", + arg = {3, 8}, } TEST [[ @@ -58,8 +58,8 @@ end x(xxx$) ]] { - label = "function x(a: any, b: any)", - arg = {12, 17}, + label = "x(a: any, b: any)", + arg = {3, 8}, } TEST [[ @@ -69,8 +69,8 @@ end x(xxx, $) ]] { - label = "function x(a: any, b: any)", - arg = {20, 25}, + label = "x(a: any, b: any)", + arg = {11, 16}, } TEST [[ @@ -80,8 +80,8 @@ end mt:f($ ]] { - label = 'function mt:f(a: any)', - arg = {15, 20}, + label = 'mt:f(a: any)', + arg = {6, 11}, } TEST [[ @@ -89,10 +89,9 @@ TEST [[ ]] { label = [[ -function *string:sub(i: integer [, j: integer(-1)]) - -> string +*string:sub(i: integer [, j: integer(-1)]) ]], - arg = {22, 31}, + arg = {13, 22}, } TEST [[ @@ -125,10 +124,9 @@ zzzz($) ]] { label = [[ -function zzzz(x: number, y: number) - -> boolean +zzzz(x: number, y: number) ]], - arg = {15, 23}, + arg = {6, 14}, } TEST [[ |