diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 17:11:26 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 17:11:26 +0800 |
commit | f3260ceb043848c26dd7ef45d0a5210ea6d4a5ba (patch) | |
tree | 90a0faf0de315b175154f23ba3287c9ea86aaf95 /server/src/matcher/hover.lua | |
parent | 2b03350caa83e66d6bb4cd73be3809ac9cea2225 (diff) | |
download | lua-language-server-f3260ceb043848c26dd7ef45d0a5210ea6d4a5ba.zip |
hover支持变量对象
Diffstat (limited to 'server/src/matcher/hover.lua')
-rw-r--r-- | server/src/matcher/hover.lua | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua index 123dcfde..9faa426b 100644 --- a/server/src/matcher/hover.lua +++ b/server/src/matcher/hover.lua @@ -2,21 +2,29 @@ local findResult = require 'matcher.find_result' local findLib = require 'matcher.find_lib' local Cache = {} +local OoCache = {} -local function buildArgs(lib) +local function buildArgs(lib, oo) if not lib.args then return '' end + local start + if oo then + start = 2 + else + start = 1 + end local strs = {} - for i, arg in ipairs(lib.args) do + for i = start, #lib.args do + local arg = lib.args[i] if arg.optional then - if i > 1 then + if i > start then strs[#strs+1] = ' [' else strs[#strs+1] = '[' end end - if i > 1 then + if i > start then strs[#strs+1] = ', ' end if arg.name then @@ -111,8 +119,8 @@ local function buildEnum(lib) return table.concat(strs) end -local function buildFunctionHover(lib, name) - local title = ('function %s(%s)%s'):format(name, buildArgs(lib), buildReturns(lib)) +local function buildFunctionHover(lib, fullKey, oo) + local title = ('function %s(%s)%s'):format(fullKey, buildArgs(lib, oo), buildReturns(lib)) local enum = buildEnum(lib) local tip = lib.description or '' return ([[ @@ -137,8 +145,8 @@ local function buildField(lib) return table.concat(strs) end -local function buildTableHover(lib, name) - local title = ('table %s'):format(name) +local function buildTableHover(lib, fullKey) + local title = ('table %s'):format(fullKey) local field = buildField(lib) local tip = lib.description or '' return ([[ @@ -162,22 +170,24 @@ return function (results, pos) return nil end local var = result.var - local lib, name = findLib(var) + local lib, fullKey, oo = findLib(var) if not lib then return nil end - if not Cache[lib] then + local cache = oo and OoCache or Cache + + if not cache[lib] then if lib.type == 'function' then - Cache[lib] = buildFunctionHover(lib, name) or '' + cache[lib] = buildFunctionHover(lib, fullKey, oo) or '' elseif lib.type == 'table' then - Cache[lib] = buildTableHover(lib, name) or '' + cache[lib] = buildTableHover(lib, fullKey) or '' elseif lib.type == 'string' then - Cache[lib] = lib.description or '' + cache[lib] = lib.description or '' else - Cache[lib] = '' + cache[lib] = '' end end - return Cache[lib] + return cache[lib] end |