From 33ad259343e0710acd009bdf7159c013c160128e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 14 Dec 2018 18:40:23 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/libs/lua53/basic.lni | 102 +++++++++++++++++++++++++++++++++++++++++++ server/src/matcher/hover.lua | 27 ++++++++++-- server/test/hover/init.lua | 6 +-- 3 files changed, 129 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/libs/lua53/basic.lni b/server/libs/lua53/basic.lni index 09092026..7ddc1831 100644 --- a/server/libs/lua53/basic.lni +++ b/server/libs/lua53/basic.lni @@ -203,16 +203,58 @@ name = 'result' type = '...' [print] +[[.args]] +type = '...' [rawequal] +[[.args]] +name = 'v1' +[[.args]] +name = 'v2' +[[.returns]] +type = 'boolean' [rawget] +[[.args]] +name = 'table' +type = 'table' +[[.args]] +name = 'index' +[[.returns]] [rawlen] +[[.args]] +name = 'v' +type = {'table', 'string'} +[[.returns]] +name = 'len' +type = 'integer' [rawset] +[[.args]] +name = 'table' +type = 'table' +[[.args]] +name = 'index' +[[.args]] +name = 'value' +[[.returns]] +name = 'table' +type = 'table' [select] +[[.args]] +name = 'index' +type = {'string', 'integer'} +[[.args]] +type = '...' +[[.returns]] +[[.enums]] +name = 'index' +enum = '#' +[[.enums]] +name = 'index' +code = 'integer' [setmetatable] special = 'setmetatable' @@ -226,13 +268,73 @@ type = 'table' type = 'table' [tonumber] +[[.args]] +name = 'e' +type = {'string', 'number'} +[[.args]] +name = 'base' +type = 'integer' +optional = 'self' +[[.returns]] +type = 'number' [tostring] +[[.args]] +name = 'v' +[[.returns]] +type = 'string' [type] +[[.args]] +name = 'v' +[[.returns]] +name = 'type' +type = 'string' +[[.enums]] +name = 'type' +enum = 'nil' +[[.enums]] +name = 'type' +enum = 'number' +[[.enums]] +name = 'type' +enum = 'string' +[[.enums]] +name = 'type' +enum = 'boolean' +[[.enums]] +name = 'type' +enum = 'table' +[[.enums]] +name = 'type' +enum = 'function' +[[.enums]] +name = 'type' +enum = 'thread' +[[.enums]] +name = 'type' +enum = 'userdata' [_VERSION] type = 'string' value = 'Lua5.3' [xpcall] +[[.args]] +name = 'f' +type = 'function' +[[.args]] +name = 'msgh' +type = 'function' +[[.args]] +name = 'arg1' +optional = 'after' +[[.args]] +type = '...' +[[.returns]] +name = 'success' +type = 'boolean' +[[.returns]] +name = 'result' +[[.returns]] +type = '...' diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua index af657225..f546734a 100644 --- a/server/src/matcher/hover.lua +++ b/server/src/matcher/hover.lua @@ -101,7 +101,7 @@ local function buildEnum(lib) end local container = table.container() for _, enum in ipairs(lib.enums) do - if not enum.name or not enum.enum then + if not enum.name or (not enum.enum and not enum.code) then goto NEXT_ENUM end if not container[enum.name] then @@ -114,20 +114,41 @@ local function buildEnum(lib) end end end + if lib.returns then + for _, rtn in ipairs(lib.returns) do + if rtn.name == enum.name then + container[enum.name].type = rtn.type + break + end + end + end end table.insert(container[enum.name], enum) ::NEXT_ENUM:: end local strs = {} for name, enums in pairs(container) do - strs[#strs+1] = ('\n%s: %s'):format(name, enums.type or '') + local tp + if type(enums.type) == 'table' then + tp = table.concat(enums.type, '/') + else + tp = enums.type + end + strs[#strs+1] = ('\n%s: %s'):format(name, tp or 'any') for _, enum in ipairs(enums) do 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 '') + if enum.code then + strs[#strs+1] = tostring(enum.code) + else + strs[#strs+1] = ('%q'):format(enum.enum) + end + if enum.description then + strs[#strs+1] = ' -- ' .. enum.description + end end end return table.concat(strs) diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua index 870b4dc1..8bbde91f 100644 --- a/server/test/hover/init.lua +++ b/server/test/hover/init.lua @@ -168,7 +168,7 @@ function load(chunk: string/function [, chunkname: string [, mode: string [, env -> function, error_message: string mode: string - | "b" -- - | "t" -- - | "bt" -- + | "b" + | "t" + | "bt" ]=] -- cgit v1.2.3