Skip to content

Commit 9ba27a6

Browse files
committed
#3028. Fix calculating the comment over doc not text in buildLuaDoc, sync with semantic logic. Fix crash 'comment.clong' type for /*, fix typo docGeneric.
1 parent cb964c6 commit 9ba27a6

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
```
1414
* `NEW` Test CLI: `--name=<testname>` `-n=<testname>`: run specify unit test
1515
* `FIX` Fixed the error that the configuration file pointed to by the `--configpath` option was not read and loaded.
16+
* `FIX` Fixed the comment calculating in docs `---@param a string?Comment` - now its `Comment` instead of `omment`.
1617

1718
## 3.13.5
1819
`2024-12-20`

script/core/semantic-tokens.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -902,23 +902,23 @@ return function (uri, start, finish)
902902
return
903903
end
904904
if start <= comm.start and comm.finish <= finish then
905+
-- the same logic as in buildLuaDoc
905906
local headPos = (comm.type == 'comment.short' and comm.text:match '^%-%s*[@|]()')
906907
or (comm.type == 'comment.long' and comm.text:match '^@()')
907908
if headPos then
908-
local atPos
909-
if comm.type == 'comment.short' then
910-
atPos = headPos + 2
911-
else
912-
atPos = headPos + #comm.mark
909+
-- absolute position of `@` symbol
910+
local startOffset = comm.start + headPos
911+
if comm.type == 'comment.long' then
912+
startOffset = comm.start + headPos + #comm.mark - 2
913913
end
914914
results[#results+1] = {
915915
start = comm.start,
916-
finish = comm.start + atPos - 2,
916+
finish = startOffset,
917917
type = define.TokenTypes.comment,
918918
}
919919
results[#results+1] = {
920-
start = comm.start + atPos - 2,
921-
finish = comm.start + atPos - 1 + #comm.text:match('%S*', headPos),
920+
start = startOffset,
921+
finish = startOffset + #comm.text:match('%S*', headPos) + 1,
922922
type = define.TokenTypes.keyword,
923923
modifieres = define.TokenModifiers.documentation,
924924
}

script/parser/compile.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ local function skipComment(isAction)
590590
local result, right = resolveLongString '*/'
591591
pushLongCommentError(left, right)
592592
State.comms[#State.comms+1] = {
593-
type = 'comment.long',
593+
type = 'comment.clong',
594594
start = left,
595595
finish = right,
596596
text = result,

script/parser/luadoc.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,10 +1713,9 @@ local function trimTailComment(text)
17131713
end
17141714

17151715
local function buildLuaDoc(comment)
1716-
local text = comment.text
1717-
local startPos = (comment.type == 'comment.short' and text:match '^%-%s*@()')
1718-
or (comment.type == 'comment.long' and text:match '^@()')
1719-
if not startPos then
1716+
local headPos = (comment.type == 'comment.short' and comment.text:match '^%-%s*@()')
1717+
or (comment.type == 'comment.long' and comment.text:match '^@()')
1718+
if not headPos then
17201719
return {
17211720
type = 'doc.comment',
17221721
start = comment.start,
@@ -1725,14 +1724,15 @@ local function buildLuaDoc(comment)
17251724
comment = comment,
17261725
}
17271726
end
1728-
local startOffset = comment.start
1727+
-- absolute position of `@` symbol
1728+
local startOffset = comment.start + headPos
17291729
if comment.type == 'comment.long' then
1730-
startOffset = startOffset + #comment.mark - 2
1730+
startOffset = comment.start + headPos + #comment.mark - 2
17311731
end
17321732

1733-
local doc = text:sub(startPos)
1733+
local doc = comment.text:sub(headPos)
17341734

1735-
parseTokens(doc, startOffset + startPos)
1735+
parseTokens(doc, startOffset)
17361736
local result, rests = convertTokens(doc)
17371737
if result then
17381738
result.range = math.max(comment.finish, result.finish)
@@ -1743,14 +1743,14 @@ local function buildLuaDoc(comment)
17431743
finish = rest.firstFinish or result.finish
17441744
end
17451745
end
1746-
local cstart = text:find('%S', finish - comment.start)
1747-
if cstart and cstart < comment.finish then
1746+
local cstart = doc:find('%S', finish - startOffset)
1747+
if cstart then
17481748
result.comment = {
17491749
type = 'doc.tailcomment',
1750-
start = cstart + comment.start,
1750+
start = startOffset + cstart,
17511751
finish = comment.finish,
17521752
parent = result,
1753-
text = trimTailComment(text:sub(cstart)),
1753+
text = trimTailComment(doc:sub(cstart)),
17541754
}
17551755
if rests then
17561756
for _, rest in ipairs(rests) do

script/vm/sign.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local vm = require 'vm.vm'
55
---@class vm.sign
66
---@field parent parser.object
77
---@field signList vm.node[]
8-
---@field docGenric parser.object[]
8+
---@field docGeneric parser.object[]
99
local mt = {}
1010
mt.__index = mt
1111
mt.type = 'sign'
@@ -17,7 +17,7 @@ end
1717

1818
---@param doc parser.object
1919
function mt:addDocGeneric(doc)
20-
self.docGenric[#self.docGenric+1] = doc
20+
self.docGeneric[#self.docGeneric+1] = doc
2121
end
2222

2323
---@param uri uri
@@ -268,7 +268,7 @@ end
268268
function vm.createSign()
269269
local genericMgr = setmetatable({
270270
signList = {},
271-
docGenric = {},
271+
docGeneric = {},
272272
}, mt)
273273
return genericMgr
274274
end

0 commit comments

Comments
 (0)