summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-28 15:40:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-28 15:40:17 +0800
commit224c6b3c4c33402398805d2f04cff6d259bd98e3 (patch)
tree341d85898c5999c9268a24d43765f128b34cad14
parenta080b2516d2ce2efb65ad0fd26126cdfa6f6e4f8 (diff)
downloadlua-language-server-224c6b3c4c33402398805d2f04cff6d259bd98e3.zip
整理代码
-rw-r--r--server/src/core/hover.lua36
1 files changed, 20 insertions, 16 deletions
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index 4d64647d..02671eed 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -281,21 +281,11 @@ local function buildValueReturns(func)
return '\n -> ' .. table.concat(strs, ', ')
end
-local function getFunctionHover(name, func, source, lib, oo, select)
- local args = ''
- local returns
- local enum
- local tip
- local argLabel
- if lib then
- args, argLabel = buildLibArgs(lib, oo, select)
- returns = buildLibReturns(lib)
- enum = buildEnum(lib)
- tip = lib.description
- else
- args, argLabel = buildValueArgs(func, source, select)
- returns = buildValueReturns(func)
- end
+local function getFunctionHoverAsLib(name, lib, oo, select)
+ local args, argLabel = buildLibArgs(lib, oo, select)
+ local returns = buildLibReturns(lib)
+ local enum = buildEnum(lib)
+ local tip = lib.description
local title = ('function %s(%s)%s'):format(name, args, returns)
return {
label = title,
@@ -305,6 +295,16 @@ local function getFunctionHover(name, func, source, lib, oo, select)
}
end
+local function getFunctionHover(name, func, source, select)
+ local args, argLabel = buildValueArgs(func, source, select)
+ local returns = buildValueReturns(func)
+ local title = ('function %s(%s)%s'):format(name, args, returns)
+ return {
+ label = title,
+ argLabel = argLabel,
+ }
+end
+
local function findClass(result)
-- 根据部分字段尝试找出自定义类型
local metatable = result.value.metatable
@@ -468,7 +468,11 @@ return function (result, source, lsp, select)
local name = fullKey or buildValueName(result, source)
local hover
if valueType == 'function' then
- hover = getFunctionHover(name, result.value, source, lib, oo, select)
+ if lib then
+ hover = getFunctionHoverAsLib(name, lib, oo, select)
+ else
+ hover = getFunctionHover(name, result.value, source, select)
+ end
else
hover = getValueHover(name, valueType, result, source, lib)
end