diff --git a/changelog.md b/changelog.md index 1c5d74f7c53ef24994405ad6d374ec0a1cb4d423..492e79cc9eb486d954b5814d88a0544995ba403c 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ + `Lua.completion.showWord` + `Lua.completion.requireSeparator` * `CHG` hover: improve showing multi defines +* `CHG` hover: improve showing multi comments at enums * `CHG` hint: `Lua.hint.paramName` now supports `Disable`, `Literal` and `All` * `CHG` no longer ignore file names case in Windows * `CHG` watching library changes diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 9ec5cd726b5fb3ede57c9e21cce75e0135e4e2bf..fc220c74d3fd85310d076606a497e0e6916bb812 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -166,13 +166,25 @@ local function buildEnumChunk(docType, name) end lines[#lines+1] = ('%s: %s'):format(name, table.concat(types)) for _, enum in ipairs(enums) do - lines[#lines+1] = (' %s %s%s'):format( - (enum.default and '->') + local enumDes = (' %s %s'):format( + (enum.default and '->') or (enum.additional and '+>') or ' |', - enum[1], - enum.comment and (' -- %s'):format(enum.comment) or '' + enum[1] ) + if enum.comment then + local first = true + local len = #enumDes + for comm in enum.comment:gmatch '[^\r\n]+' do + if first then + first = false + enumDes = ('%s -- %s'):format(enumDes, comm) + else + enumDes = ('%s\n%s -- %s'):format(enumDes, (' '):rep(len), comm) + end + end + end + lines[#lines+1] = enumDes end return table.concat(lines, '\n') end diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 2ceeb597c79116d17cebdc174a58a4e2022bf151..a877d2263408222fe14889cf62c9c0831d1fcc1e 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -954,3 +954,34 @@ local t: string|fun():string function t() -> string ```]]} + +TEST {{ path = 'a.lua', content = '', }, { + path = 'b.lua', + content = [[ +---@alias T +---comment 1 +---comment 2 +---| 'a' +---comment 3 +---comment 4 +---| 'b' + +---@param p T +local function <?f?>(p) +end +]] +}, +hover = [[ +```lua +function f(p: a|b) +``` + +--- + +```lua +p: T + | a -- comment 1 + -- comment 2 + | b -- comment 3 + -- comment 4 +```]]}