From d670882f016ee5a879f2fe3fa4a7bd2eff581bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 6 Dec 2018 18:27:22 +0800 Subject: =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=A1=A8=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/hover.lua | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'server/src/matcher') 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 -- cgit v1.2.3