diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-04-06 18:04:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-04-06 18:04:25 +0800 |
commit | 862e4f06beb191bacc6db42f2592abc2851dd87d (patch) | |
tree | 4c04822e74ec309e2c985691e63c2f450a64e374 | |
parent | 66600bb4855fcb327ef160bdf2b79f6017c0ec9c (diff) | |
download | lua-language-server-862e4f06beb191bacc6db42f2592abc2851dd87d.zip |
fix #495
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/hover/description.lua | 30 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 3 |
3 files changed, 23 insertions, 11 deletions
diff --git a/changelog.md b/changelog.md index 8a9ebd58..d7db0b9c 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ `FIX` [#487](https://github.com/sumneko/lua-language-server/issues/487) `FIX` [#488](https://github.com/sumneko/lua-language-server/issues/488) `FIX` [#490](https://github.com/sumneko/lua-language-server/issues/490) +`FIX` [#495](https://github.com/sumneko/lua-language-server/issues/495) ## 1.20.2 `2021-4-2` diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 3766d2f4..72ff561f 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -244,22 +244,33 @@ local function getFunctionComment(source) end local comments = {} + local isComment = true for _, doc in ipairs(docGroup) do if doc.type == 'doc.comment' then + if not isComment then + comments[#comments+1] = '\n' + end + isComment = true if doc.comment.text:sub(1, 1) == '-' then comments[#comments+1] = doc.comment.text:sub(2) else comments[#comments+1] = doc.comment.text end + comments[#comments+1] = '\n' elseif doc.type == 'doc.param' then if doc.comment then + isComment = false + comments[#comments+1] = '\n' comments[#comments+1] = ('@*param* `%s` — %s'):format( doc.param[1], doc.comment.text:gsub('[\r\n]+', ' ') ) + comments[#comments+1] = '\n' end elseif doc.type == 'doc.return' then if hasReturnComment then + isComment = false + comments[#comments+1] = '\n' local name = {} for _, rtn in ipairs(doc.returns) do if rtn.name then @@ -279,24 +290,27 @@ local function getFunctionComment(source) comments[#comments+1] = ('@*return* `%s`'):format(table.concat(name, ',')) end end + comments[#comments+1] = '\n' end elseif doc.type == 'doc.overload' then comments[#comments+1] = '---' end end - comments = table.concat(comments, "\n\n") + if comments[1] == '\n' then + table.remove(comments, 1) + end + if comments[#comments] == '\n' then + table.remove(comments) + end + comments = table.concat(comments) local enums = getBindEnums(source, docGroup) - if comments == "" and not enums then + if comments == '' and not enums then return end local md = markdown() - if comments ~= "" then - md:add('md', comments) - end - if enums then - md:add('lua', enums) - end + md:add('md', comments) + md:add('lua', enums) return md:string() end diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index d0080ed9..c8c333f0 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -531,9 +531,7 @@ hover = { name = 'f', description = [[ @*param* `arg3` — comment3 - --- - @*param* `arg1` — comment1 @*param* `arg2` — comment2]] @@ -607,7 +605,6 @@ hover = { name = 'f', description = [[ comment1 - comment2]] }} |