Skip to content

Commit

Permalink
Add raw descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NyakoFox committed Nov 25, 2023
1 parent 8c4aca0 commit 5a468a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions script/cli/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ local function packObject(source, mark)
end
if source.type == 'function.return' then
new['desc'] = source.comment and getDesc(source.comment)
new['rawdesc'] = source.comment and getDesc(source.comment, true)
end
if source.type == 'doc.type.table' then
new['fields'] = packObject(source.fields, mark)
Expand All @@ -82,6 +83,7 @@ local function packObject(source, mark)
end
if source.bindDocs then
new['desc'] = getDesc(source)
new['rawdesc'] = getDesc(source, true)
end
new['view'] = new['view'] or vm.getInfer(source):view(ws.rootUri)
end
Expand Down Expand Up @@ -115,6 +117,7 @@ local function collectTypes(global, results)
name = global.name,
type = 'type',
desc = nil,
rawdesc = nil,
defines = {},
fields = {},
}
Expand All @@ -131,6 +134,7 @@ local function collectTypes(global, results)
extends = getExtends(set),
}
result.desc = result.desc or getDesc(set)
result.rawdesc = result.rawdesc or getDesc(set, true)
::CONTINUE::
end
if #result.defines == 0 then
Expand Down Expand Up @@ -163,6 +167,7 @@ local function collectTypes(global, results)
field.start = source.start
field.finish = source.finish
field.desc = getDesc(source)
field.rawdesc = getDesc(source, true)
field.extends = packObject(source.extends)
return
end
Expand All @@ -180,6 +185,7 @@ local function collectTypes(global, results)
field.start = source.start
field.finish = source.finish
field.desc = getDesc(source)
field.rawdesc = getDesc(source, true)
field.extends = packObject(source.value)
return
end
Expand All @@ -199,6 +205,7 @@ local function collectTypes(global, results)
field.start = source.start
field.finish = source.finish
field.desc = getDesc(source)
field.rawdesc = getDesc(source, true)
field.extends = packObject(source.value)
return
end
Expand Down Expand Up @@ -237,6 +244,7 @@ local function collectVars(global, results)
extends = packObject(set.value),
}
result.desc = result.desc or getDesc(set)
result.rawdesc = result.rawdesc or getDesc(set, true)
end
end
if #result.defines == 0 then
Expand Down
20 changes: 10 additions & 10 deletions script/core/hover/description.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ local function tryDocFieldComment(source)
end
end

local function getFunctionComment(source)
local function getFunctionComment(source, raw)
local docGroup = source.bindDocs
if not docGroup then
return
Expand All @@ -356,14 +356,14 @@ local function getFunctionComment(source)
if doc.type == 'doc.comment' then
local comment = normalizeComment(doc.comment.text, uri)
md:add('md', comment)
elseif doc.type == 'doc.param' then
elseif doc.type == 'doc.param' and not raw then
if doc.comment then
md:add('md', ('@*param* `%s` — %s'):format(
doc.param[1],
doc.comment.text
))
end
elseif doc.type == 'doc.return' then
elseif doc.type == 'doc.return' and not raw then
if hasReturnComment then
local name = {}
for _, rtn in ipairs(doc.returns) do
Expand Down Expand Up @@ -401,13 +401,13 @@ local function getFunctionComment(source)
end

---@async
local function tryDocComment(source)
local function tryDocComment(source, raw)
local md = markdown()
if source.value and source.value.type == 'function' then
source = source.value
end
if source.type == 'function' then
local comment = getFunctionComment(source)
local comment = getFunctionComment(source, raw)
md:add('md', comment)
source = source.parent
end
Expand All @@ -429,7 +429,7 @@ local function tryDocComment(source)
end

---@async
local function tryDocOverloadToComment(source)
local function tryDocOverloadToComment(source, raw)
if source.type ~= 'doc.type.function' then
return
end
Expand All @@ -438,7 +438,7 @@ local function tryDocOverloadToComment(source)
or not doc.bindSource then
return
end
local md = tryDocComment(doc.bindSource)
local md = tryDocComment(doc.bindSource, raw)
if md then
return md
end
Expand Down Expand Up @@ -529,7 +529,7 @@ local function tryDocEnum(source)
end

---@async
return function (source)
return function (source, raw)
if source.type == 'string' then
return asString(source)
end
Expand All @@ -539,10 +539,10 @@ return function (source)
if source.type == 'field' then
source = source.parent
end
return tryDocOverloadToComment(source)
return tryDocOverloadToComment(source, raw)
or tryDocFieldComment(source)
or tyrDocParamComment(source)
or tryDocComment(source)
or tryDocComment(source, raw)
or tryDocClassComment(source)
or tryDocModule(source)
or tryDocEnum(source)
Expand Down

0 comments on commit 5a468a1

Please sign in to comment.