summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/hover/description.lua98
-rw-r--r--test/crossfile/hover.lua2
2 files changed, 50 insertions, 50 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
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index 9259b593..3715ba9c 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -481,7 +481,7 @@ function f(x: string, y: table)
@*return* `name` — comment 2
-@*return* `#2` — comment 3]],
+@*return* — comment 3]],
}
}