summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authoractboy168 <actboy168@gmail.com>2020-12-03 11:51:01 +0800
committeractboy168 <actboy168@gmail.com>2020-12-03 11:51:12 +0800
commitc08d501b7bdea16d87998d3ef28c2b708515cd10 (patch)
tree1780adfdeac21997eb2a175ef1086d717ab047e7 /script
parent2619ece52b59c64805b17b00deb1106ffa0e0cfe (diff)
downloadlua-language-server-c08d501b7bdea16d87998d3ef28c2b708515cd10.zip
hover尊重luadoc中各项的次序,除了enum
Diffstat (limited to 'script')
-rw-r--r--script/core/hover/description.lua98
1 files changed, 49 insertions, 49 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index d6450fd3..7be50947 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -187,76 +187,59 @@ local function tryDocFieldUpComment(source)
return comment
end
-local function getBindParamComments(source, bindDocs)
- if not isFunction(source) then
- return
+local function getFunctionComment(source)
+ local docGroup = source.bindDocs
+
+ local has_return_comment = false
+ for _, doc in ipairs(docGroup) do
+ if doc.type == 'doc.return' and doc.comment then
+ has_return_comment = true
+ break
+ end
end
local comments = {}
- for _, doc in ipairs(bindDocs) do
- if doc.type == 'doc.param' then
+ for _, doc in ipairs(docGroup) do
+ if doc.type == 'doc.comment' then
+ comments[#comments+1] = doc.comment.text:sub(2)
+ elseif doc.type == 'doc.param' then
if doc.comment then
comments[#comments+1] = ('@*param* `%s` — %s'):format(
doc.param[1],
doc.comment.text
)
end
- end
- end
- if #comments == 0 then
- return nil
- end
- return table.concat(comments, '\n\n')
-end
-
-local function getBindReturnComments(source, bindDocs)
- if not isFunction(source) then
- return
- end
-
- local comments = {}
- local index = 0
- for _, doc in ipairs(bindDocs) do
- if doc.type == 'doc.return' then
- for _, rtn in ipairs(doc.returns) do
- index = index + 1
- if doc.comment then
- local name = rtn.name and rtn.name[1] or ('#' .. index)
+ elseif doc.type == 'doc.return' then
+ if has_return_comment and doc.comment then
+ local name = {}
+ for _, rtn in ipairs(doc.returns) do
+ if rtn.name then
+ name[#name+1] = rtn.name[1]
+ end
+ end
+ if #name == 0 then
+ comments[#comments+1] = ('@*return* — %s'):format(
+ doc.comment.text
+ )
+ else
comments[#comments+1] = ('@*return* `%s` — %s'):format(
- name,
+ table.concat(name, ','),
doc.comment.text
)
end
end
end
end
- if #comments == 0 then
- return nil
- end
- return table.concat(comments, '\n\n')
-end
+ comments = table.concat(comments, "\n\n")
-local function tryDocComment(source)
- if not source.bindDocs then
- return
- end
- local comment = getBindComment(source, source.bindDocs)
- local params = getBindParamComments(source, source.bindDocs)
- local returns = getBindReturnComments(source, source.bindDocs)
- local enums = getBindEnums(source, source.bindDocs)
- if not comment and not params and not returns and not enums then
+ local enums = getBindEnums(source, docGroup)
+ if comments == "" and not enums then
return
end
local md = markdown()
md:add('md', "---")
- if comment then
- md:add('md', comment)
- end
- if params then
- md:add('md', params)
- end
- if returns then
- md:add('md', returns)
+ if comments ~= "" then
+ md:add('md', comments)
end
if enums then
md:add('lua', enums)
@@ -264,6 +247,23 @@ local function tryDocComment(source)
return md:string()
end
+local function tryDocComment(source)
+ if not source.bindDocs then
+ return
+ end
+ if not isFunction(source) then
+ local comment = getBindComment(source, source.bindDocs)
+ if not comment then
+ return
+ end
+ local md = markdown()
+ md:add('md', "---")
+ md:add('md', comment)
+ return md:string()
+ end
+ return getFunctionComment(source)
+end
+
local function tryDocOverloadToComment(source)
if source.type ~= 'doc.type.function' then
return