summaryrefslogtreecommitdiff
path: root/server/src/matcher
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-06 18:27:22 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-06 18:27:22 +0800
commitd670882f016ee5a879f2fe3fa4a7bd2eff581bb0 (patch)
tree4ce49e7c32daabb7d11d2ecbf71e1a2441596c09 /server/src/matcher
parent979676be219b83c7295409824ee8280a3335cc5a (diff)
downloadlua-language-server-d670882f016ee5a879f2fe3fa4a7bd2eff581bb0.zip
显示表的内容
Diffstat (limited to 'server/src/matcher')
-rw-r--r--server/src/matcher/hover.lua28
1 files changed, 25 insertions, 3 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua
index 79a47ede..6a643851 100644
--- a/server/src/matcher/hover.lua
+++ b/server/src/matcher/hover.lua
@@ -98,7 +98,11 @@ local function buildEnum(lib)
for name, enums in pairs(container) do
strs[#strs+1] = ('\n%s:%s'):format(name, enums.type or '')
for _, enum in ipairs(enums) do
- strs[#strs+1] = '\n | '
+ if enum.default then
+ strs[#strs+1] = '\n -> '
+ else
+ strs[#strs+1] = '\n | '
+ end
strs[#strs+1] = ('%q: %s'):format(enum.enum, enum.description or '')
end
end
@@ -112,6 +116,25 @@ local function buildFunctionHover(lib, name)
return ('```lua\n%s%s\n```\n%s'):format(title, enum, tip)
end
+local function buildField(lib)
+ if not lib.fields then
+ return ''
+ end
+ local strs = {}
+ for _, field in ipairs(lib.fields) do
+ strs[#strs+1] = '\n | '
+ strs[#strs+1] = ('%s:%s: %s'):format(field.field, field.type, field.description or '')
+ end
+ return table.concat(strs)
+end
+
+local function buildTableHover(lib, name)
+ local title = ('table %s'):format(name)
+ local field = buildField(lib)
+ local tip = lib.description or ''
+ return ('```lua\n%s%s```\n%s'):format(title, field, tip)
+end
+
return function (results, pos)
local result = findResult(results, pos)
if not result then
@@ -130,8 +153,7 @@ return function (results, pos)
if lib.type == 'function' then
return buildFunctionHover(lib, name)
elseif lib.type == 'table' then
- local tip = lib.description or ''
- return ('%s'):format(tip)
+ return buildTableHover(lib, name)
elseif lib.type == 'string' then
return lib.description
end