summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-11-27 11:40:40 +0800
committerGitHub <noreply@github.com>2023-11-27 11:40:40 +0800
commit2792f9a66bdf25a95899aab99d4397c5644c171d (patch)
treedf2fcc6c6e973d13ef51273f2cdc9b372abc4101
parent8c4aca0fb664b7f7e383441e318b000e6cf971de (diff)
parent5a468a1a41535ff408490595ec694c65f337c6ba (diff)
downloadlua-language-server-2792f9a66bdf25a95899aab99d4397c5644c171d.zip
Merge pull request #2430 from NyakoFox/rawdesc
Add a `rawdesc` field to exported docs
-rw-r--r--script/cli/doc.lua8
-rw-r--r--script/core/hover/description.lua20
2 files changed, 18 insertions, 10 deletions
diff --git a/script/cli/doc.lua b/script/cli/doc.lua
index c643deea..9140a258 100644
--- a/script/cli/doc.lua
+++ b/script/cli/doc.lua
@@ -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)
@@ -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
@@ -115,6 +117,7 @@ local function collectTypes(global, results)
name = global.name,
type = 'type',
desc = nil,
+ rawdesc = nil,
defines = {},
fields = {},
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 58fb9fbe..75189b06 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)