diff options
-rw-r--r-- | script-beta/core/hover/init.lua | 32 | ||||
-rw-r--r-- | script-beta/core/hover/label.lua | 15 | ||||
-rw-r--r-- | test-beta/definition/luadoc.lua | 6 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 26 |
4 files changed, 70 insertions, 9 deletions
diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index d0873c98..3876ab58 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -79,7 +79,20 @@ local function getHoverAsValue(source) } end +local function getHoverAsDocName(source) + local label = getLabel(source) + local desc = getDesc(source) + return { + label = label, + source = source, + description = desc, + } +end + local function getHover(source) + if source.type == 'doc.type.name' then + return getHoverAsDocName(source) + end vm.setSearchLevel(5) local isFunction = vm.hasInferType(source, 'function', 'deep') if isFunction then @@ -90,15 +103,16 @@ local function getHover(source) end local accept = { - ['local'] = true, - ['setlocal'] = true, - ['getlocal'] = true, - ['setglobal'] = true, - ['getglobal'] = true, - ['field'] = true, - ['method'] = true, - ['string'] = true, - ['number'] = true, + ['local'] = true, + ['setlocal'] = true, + ['getlocal'] = true, + ['setglobal'] = true, + ['getglobal'] = true, + ['field'] = true, + ['method'] = true, + ['string'] = true, + ['number'] = true, + ['doc.type.name'] = true, } local function getHoverByUri(uri, offset) diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua index 6ce8ef8e..b96421b1 100644 --- a/script-beta/core/hover/label.lua +++ b/script-beta/core/hover/label.lua @@ -29,6 +29,19 @@ local function asDocFunction(source) return table.concat(lines, '\n') end +local function asDocTypeName(source) + for _, doc in ipairs(vm.getDocTypes(source[1])) do + if doc.type == 'doc.class.name' then + return 'class ' .. source[1] + end + if doc.type == 'doc.alias.name' then + local extends = doc.parent.extends + -- TODO + return '展开为 ' .. vm.getInferType(extends) + end + end +end + local function asValue(source, title) local name = buildName(source) local infers = vm.getInfers(source, 'deep') @@ -175,5 +188,7 @@ return function (source, oop) return asLibrary(source) elseif source.type == 'doc.type.function' then return asDocFunction(source) + elseif source.type == 'doc.type.name' then + return asDocTypeName(source) end end diff --git a/test-beta/definition/luadoc.lua b/test-beta/definition/luadoc.lua index 675495ef..41331c48 100644 --- a/test-beta/definition/luadoc.lua +++ b/test-beta/definition/luadoc.lua @@ -121,6 +121,12 @@ local mt = {} mt.<?name?> ]] +TEST [[ +---@alias <!A!> string + +---@type <?A?> +]] + -- TODO do return end TEST [[ diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index 43a81fa3..420e4c1d 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -1257,3 +1257,29 @@ local t: Class { z: string, } ]] + +TEST [[ +---@class A + +---@type <?A?> +]] +[[ +class A +]] + +TEST [[ +---@type string | "'enum1'" | "'enum2'" +local <?t?> +]] +[[ +local t: string|'enum1'|'enum2' +]] + +TEST [[ +---@alias A string | "'enum1'" | "'enum2'" + +---@type <?A?> +]] +[[ +展开为 string|'enum1'|'enum2' +]] |