summaryrefslogtreecommitdiff
path: root/server
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
parent979676be219b83c7295409824ee8280a3335cc5a (diff)
downloadlua-language-server-d670882f016ee5a879f2fe3fa4a7bd2eff581bb0.zip
显示表的内容
Diffstat (limited to 'server')
-rw-r--r--server/libs/lua53/basic.lni122
-rw-r--r--server/src/matcher/hover.lua28
2 files changed, 146 insertions, 4 deletions
diff --git a/server/libs/lua53/basic.lni b/server/libs/lua53/basic.lni
index 4963887a..163c7fdb 100644
--- a/server/libs/lua53/basic.lni
+++ b/server/libs/lua53/basic.lni
@@ -15,12 +15,13 @@ type = 'string'
optional = 'after'
[[.args]]
name = 'arg'
-type = 'number'
+type = 'integer'
optional = 'self'
[[.returns]]
[[.enums]]
name = 'opt'
enum = 'collect'
+default = true
[[.enums]]
name = 'opt'
enum = 'stop'
@@ -44,11 +45,130 @@ name = 'opt'
enum = 'isrunning'
[dofile]
+[[.args]]
+name = 'filename'
+type = 'string'
+optional = 'self'
+[[.returns]]
[error]
+[[.args]]
+name = 'message'
+[[.args]]
+name = 'level'
+type = 'integer'
+optional = 'self'
[_G]
type = 'table'
+[[.fields]]
+field = '_G'
+type = 'table'
+[[.fields]]
+field = '_VERSION'
+type = 'string'
+[[.fields]]
+field = 'arg'
+type = 'table'
+[[.fields]]
+field = 'assert'
+type = 'function'
+[[.fields]]
+field = 'collectgarbage'
+type = 'function'
+[[.fields]]
+field = 'coroutine'
+type = 'table'
+[[.fields]]
+field = 'debug'
+type = 'table'
+[[.fields]]
+field = 'dofile'
+type = 'function'
+[[.fields]]
+field = 'error'
+type = 'function'
+[[.fields]]
+field = 'fs'
+type = 'table'
+[[.fields]]
+field = 'getmetatable'
+type = 'function'
+[[.fields]]
+field = 'io'
+type = 'table'
+[[.fields]]
+field = 'ipairs'
+type = 'function'
+[[.fields]]
+field = 'load'
+type = 'function'
+[[.fields]]
+field = 'loadfile'
+type = 'function'
+[[.fields]]
+field = 'math'
+type = 'table'
+[[.fields]]
+field = 'next'
+type = 'function'
+[[.fields]]
+field = 'os'
+type = 'table'
+[[.fields]]
+field = 'package'
+type = 'table'
+[[.fields]]
+field = 'pairs'
+type = 'function'
+[[.fields]]
+field = 'pcall'
+type = 'function'
+[[.fields]]
+field = 'print'
+type = 'function'
+[[.fields]]
+field = 'rawequal'
+type = 'function'
+[[.fields]]
+field = 'rawget'
+type = 'function'
+[[.fields]]
+field = 'rawlen'
+type = 'function'
+[[.fields]]
+field = 'rawset'
+type = 'function'
+[[.fields]]
+field = 'require'
+type = 'function'
+[[.fields]]
+field = 'select'
+type = 'function'
+[[.fields]]
+field = 'setmetatable'
+type = 'function'
+[[.fields]]
+field = 'string'
+type = 'table'
+[[.fields]]
+field = 'table'
+type = 'table'
+[[.fields]]
+field = 'tonumber'
+type = 'function'
+[[.fields]]
+field = 'tostring'
+type = 'function'
+[[.fields]]
+field = 'type'
+type = 'function'
+[[.fields]]
+field = 'utf8'
+type = 'table'
+[[.fields]]
+field = 'xpcall'
+type = 'function'
[getmetatable]
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