@@ -1713,10 +1713,9 @@ local function trimTailComment(text)
17131713end
17141714
17151715local 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
0 commit comments