diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-12-06 20:23:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-12-06 20:23:09 +0800 |
commit | 9471213c956223fc9746d77b2082cd970c6617f8 (patch) | |
tree | a2167b8117bf1d6a76d6bd16c3a7b50813347db4 /script/core/hover | |
parent | d060e870a5d24e3e575459a0e02d229d9234109a (diff) | |
download | lua-language-server-9471213c956223fc9746d77b2082cd970c6617f8.zip |
#842
Diffstat (limited to 'script/core/hover')
-rw-r--r-- | script/core/hover/arg.lua | 10 | ||||
-rw-r--r-- | script/core/hover/init.lua | 20 | ||||
-rw-r--r-- | script/core/hover/label.lua | 22 | ||||
-rw-r--r-- | script/core/hover/name.lua | 6 |
4 files changed, 26 insertions, 32 deletions
diff --git a/script/core/hover/arg.lua b/script/core/hover/arg.lua index 4e6a1ace..d03f55f2 100644 --- a/script/core/hover/arg.lua +++ b/script/core/hover/arg.lua @@ -55,7 +55,7 @@ local function asFunction(source, oop) end end -local function asDocFunction(source) +local function asDocFunction(source, oop) if not source.args then return '' end @@ -69,7 +69,11 @@ local function asDocFunction(source) arg.extends and infer.searchAndViewInfers(arg.extends) or 'any' ) end - return table.concat(args, ', ') + if oop then + return table.concat(args, ', ', 2) + else + return table.concat(args, ', ') + end end return function (source, oop) @@ -77,7 +81,7 @@ return function (source, oop) return asFunction(source, oop) end if source.type == 'doc.type.function' then - return asDocFunction(source) + return asDocFunction(source, oop) end return '' end diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua index 7d99a006..baa24139 100644 --- a/script/core/hover/init.lua +++ b/script/core/hover/init.lua @@ -6,6 +6,7 @@ local util = require 'utility' local findSource = require 'core.find-source' local markdown = require 'provider.markdown' local infer = require 'core.infer' +local guide = require 'parser.guide' ---@async local function getHover(source) @@ -15,14 +16,14 @@ local function getHover(source) local descMark = {} ---@async - local function addHover(def, checkLable) + local function addHover(def, checkLable, oop) if defMark[def] then return end defMark[def] = true if checkLable then - local label = getLabel(def) + local label = getLabel(def, oop) if not labelMark[tostring(label)] then labelMark[tostring(label)] = true md:add('lua', label) @@ -38,27 +39,34 @@ local function getHover(source) end end + local oop if infer.searchAndViewInfers(source) == 'function' then local hasFunc for _, def in ipairs(vm.getDefs(source)) do + if guide.isOOP(def) then + oop = true + end if def.type == 'function' or def.type == 'doc.type.function' then hasFunc = true - addHover(def, true) + addHover(def, true, oop) end end if not hasFunc then - addHover(source, true) + addHover(source, true, oop) end else - addHover(source, true) + addHover(source, true, oop) for _, def in ipairs(vm.getDefs(source)) do + if guide.isOOP(def) then + oop = true + end local isFunction if def.type == 'function' or def.type == 'doc.type.function' then isFunction = true end - addHover(def, isFunction) + addHover(def, isFunction, oop) end end diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index 8531ebb9..78756ea8 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -11,9 +11,6 @@ local files = require 'files' local guide = require 'parser.guide' local function asFunction(source, oop) - if oop == nil then - oop = guide.isOOP(source, oop) - end local name = buildName(source, oop) local arg = buildArg(source, oop) local rtn = buildReturn(source) @@ -28,20 +25,6 @@ local function asFunction(source, oop) return table.concat(lines, '\n') end -local function asDocFunction(source, oop) - local name = buildName(source, oop) - local arg = buildArg(source, oop) - local rtn = buildReturn(source) - local lines = {} - lines[1] = string.format('%s%s %s(%s)' - , '' - , oop and 'method' or 'function' - , name or '' - , arg) - lines[2] = rtn - return table.concat(lines, '\n') -end - local function asDocTypeName(source) local defs = vm.getDefs(source) for _, doc in ipairs(defs) do @@ -195,7 +178,8 @@ end ---@async return function (source, oop) - if source.type == 'function' then + if source.type == 'function' + or source.type == 'doc.type.function' then return asFunction(source, oop) elseif source.type == 'local' or source.type == 'getlocal' @@ -217,8 +201,6 @@ return function (source, oop) elseif source.type == 'number' or source.type == 'integer' then return asNumber(source) - elseif source.type == 'doc.type.function' then - return asDocFunction(source, oop) elseif source.type == 'doc.type.name' then return asDocTypeName(source) elseif source.type == 'doc.field.name' then diff --git a/script/core/hover/name.lua b/script/core/hover/name.lua index 2d1e361c..5d8f0b3d 100644 --- a/script/core/hover/name.lua +++ b/script/core/hover/name.lua @@ -46,14 +46,14 @@ local function asGlobal(source) return guide.getKeyName(source) end -local function asDocFunction(source) +local function asDocFunction(source, oop) local doc = guide.getParentType(source, 'doc.type') or guide.getParentType(source, 'doc.overload') if not doc or not doc.bindSources then return '' end for _, src in ipairs(doc.bindSources) do - local name = buildName(src) + local name = buildName(src, oop) if name ~= '' then return name end @@ -89,7 +89,7 @@ function buildName(source, oop) return asTableField(source) or '', oop end if source.type == 'doc.type.function' then - return asDocFunction(source), oop + return asDocFunction(source, oop), oop end if source.type == 'doc.field' then return asDocField(source), oop |