summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-08-19 21:13:37 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-08-19 21:13:37 +0800
commit666d25e294d41d7ec7450ff34e5cc3eb1463d3da (patch)
tree027bd0a8e8f682809d8e330095eaa06876d9716a
parent7829753fb9951f2de05a3ebec0e94b3164eb6b46 (diff)
downloadlua-language-server-666d25e294d41d7ec7450ff34e5cc3eb1463d3da.zip
improve markdown
-rw-r--r--script/core/hover/description.lua44
-rw-r--r--script/provider/markdown.lua17
-rw-r--r--test/crossfile/hover.lua4
3 files changed, 25 insertions, 40 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index afeb1bb9..9ec5cd72 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -246,34 +246,23 @@ local function getFunctionComment(source)
end
end
- local comments = {}
- local isComment = true
+ local md = markdown()
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)
+ md:add('md', doc.comment.text:sub(2))
else
- comments[#comments+1] = doc.comment.text
+ md:add('md', 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(
+ md:add('md', ('@*param* `%s` — %s'):format(
doc.param[1],
doc.comment.text
- )
- 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
@@ -282,37 +271,24 @@ local function getFunctionComment(source)
end
if doc.comment then
if #name == 0 then
- comments[#comments+1] = ('@*return* — %s'):format(doc.comment.text)
+ md:add('md', ('@*return* — %s'):format(doc.comment.text))
else
- comments[#comments+1] = ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text)
+ md:add('md', ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text))
end
else
if #name == 0 then
- comments[#comments+1] = '@*return*'
+ md:add('md', '@*return*')
else
- comments[#comments+1] = ('@*return* `%s`'):format(table.concat(name, ','))
+ md:add('md', ('@*return* `%s`'):format(table.concat(name, ',')))
end
end
- comments[#comments+1] = '\n'
end
elseif doc.type == 'doc.overload' then
- comments[#comments+1] = '---'
+ md:splitLine()
end
end
- 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
- return
- end
- local md = markdown()
- md:add('md', comments)
md:add('lua', enums)
return md
end
diff --git a/script/provider/markdown.lua b/script/provider/markdown.lua
index 7b94157e..140267d7 100644
--- a/script/provider/markdown.lua
+++ b/script/provider/markdown.lua
@@ -58,9 +58,7 @@ function mt:string()
elseif obj.type == 'markdown' then
concat(obj.markdown)
else
- if obj.language == language then
- lines[#lines+1] = obj.text
- else
+ if obj.language ~= language then
if language ~= 'md' then
lines[#lines+1] = '```'
end
@@ -70,9 +68,18 @@ function mt:string()
if obj.language ~= 'md' then
lines[#lines+1] = '```' .. obj.language
end
- lines[#lines+1] = obj.text
- language = obj.language
end
+ if obj.language == 'md' and #lines > 0 then
+ local last = lines[#lines]
+ if obj.text:sub(1, 1) == '@'
+ or last:sub(1, 1) == '@' then
+ if lines[#lines] ~= '' then
+ lines[#lines+1] = ''
+ end
+ end
+ end
+ lines[#lines+1] = obj.text
+ language = obj.language
end
end
end
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index e673bc5f..04f7cc02 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -534,7 +534,9 @@ hover = {
name = 'f',
description = [[
@*param* `arg3` — comment3
+
---
+
@*param* `arg1` — comment1
@*param* `arg2` — comment2]]
@@ -592,7 +594,7 @@ function f()
-> boolean
2. string]],
name = 'f',
- description = nil
+ description = ''
}}
TEST {{ path = 'a.lua', content = '', }, {