From 95ea163397963b52278b9eb70f2adfebe5490014 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= <sumneko@hotmail.com>
Date: Mon, 23 Aug 2021 11:27:28 +0800
Subject: [PATCH] resolve #586 improve showing multi comments at enums

---
 changelog.md                      |  1 +
 script/core/hover/description.lua | 20 ++++++++++++++++----
 test/crossfile/hover.lua          | 31 +++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/changelog.md b/changelog.md
index 1c5d74f7c..492e79cc9 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 9ec5cd726..fc220c74d 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 2ceeb597c..a877d2263 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
+```]]}
-- 
GitLab