From 7d546aeb0c78d2790a583809ceabfa620fdbde3c 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, 15 Jul 2022 23:48:13 +0800 Subject: resolve #1230 show enums for variables --- script/core/hover/description.lua | 16 ++++++++++++---- test/crossfile/hover.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 32a0a798..e32d204c 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -349,15 +349,23 @@ local function getFunctionComment(source) end local function tryDocComment(source) + local md = markdown() if source.type == 'function' then local comment = getFunctionComment(source) - if comment then - return comment - end + md:add('md', comment) source = source.parent end local comment = lookUpDocComments(source) - return comment + md:add('md', comment) + if source.type == 'doc.alias' then + local enums = buildEnumChunk(source, source.alias[1], guide.getUri(source)) + md:add('lua', enums) + end + local result = md:string() + if result == '' then + return nil + end + return result end local function tryDocOverloadToComment(source) diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index f412183c..60a962e9 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -1471,3 +1471,29 @@ function A() comments]] } + +TEST { + { + path = 'a.lua', + content = [[ + ---@alias A + ---| 1 # comment1 + ---| 2 # comment2 + + ---@type A + local + ]] + }, + hover = [[ +```lua +local x: 1|2 +``` + +--- + +```lua +A: + | 1 -- comment1 + | 2 -- comment2 +```]] +} -- cgit v1.2.3