Skip to content

Commit 71d28cc

Browse files
committed
Support limited multiline annotations
1 parent 6b11e03 commit 71d28cc

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

changelog.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
55
* `FIX` A regression related to type narrow and generic param introduced since `v3.10.1`
6-
* `New` Support importing `enum` through class name suffix matching in quick fixes, allowing the import of `enum` from `table.table.enum; return table`.
6+
* `NEW` Support importing `enum` through class name suffix matching in quick fixes, allowing the import of `enum` from `table.table.enum; return table`.
7+
* `NEW` Support limited multiline annotations
8+
```lua
9+
---@type {
10+
--- x: number,
11+
--- y: number,
12+
--- z: number,
13+
---}
14+
local point --> local point: { x: number, y: number, z: number }
15+
```
716
* `FIX` Parse storagePath to improve reliability of resolving ${addons} placeholder
817
* `FIX` Reference should also look in tablefield
918
* `FIX` Determine that the index of `{...}` is an integer when iterating

script/parser/luadoc.lua

+35-5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,30 @@ local function parseIndexField(parent)
298298
return field
299299
end
300300

301+
local function slideToNextLine()
302+
if peekToken() then
303+
return
304+
end
305+
local nextComment = NextComment(0, true)
306+
if not nextComment then
307+
return
308+
end
309+
local currentComment = NextComment(-1, true)
310+
local currentLine = guide.rowColOf(currentComment.start)
311+
local nextLine = guide.rowColOf(nextComment.start)
312+
if currentLine + 1 ~= nextLine then
313+
return
314+
end
315+
if nextComment.text:sub(1, 1) ~= '-' then
316+
return
317+
end
318+
if nextComment.text:match '^%-%s*%@' then
319+
return
320+
end
321+
NextComment()
322+
parseTokens(nextComment.text:sub(2), nextComment.start + 2)
323+
end
324+
301325
local function parseTable(parent)
302326
if not checkToken('symbol', '{', 1) then
303327
return nil
@@ -311,6 +335,7 @@ local function parseTable(parent)
311335
}
312336

313337
while true do
338+
slideToNextLine()
314339
if checkToken('symbol', '}', 1) then
315340
nextToken()
316341
break
@@ -385,6 +410,7 @@ local function parseTuple(parent)
385410

386411
local index = 1
387412
while true do
413+
slideToNextLine()
388414
if checkToken('symbol', ']', 1) then
389415
nextToken()
390416
break
@@ -500,6 +526,7 @@ local function parseTypeUnitFunction(parent)
500526
return nil
501527
end
502528
while true do
529+
slideToNextLine()
503530
if checkToken('symbol', ')', 1) then
504531
nextToken()
505532
break
@@ -539,14 +566,17 @@ local function parseTypeUnitFunction(parent)
539566
break
540567
end
541568
end
569+
slideToNextLine()
542570
if checkToken('symbol', ':', 1) then
543571
nextToken()
572+
slideToNextLine()
544573
local needCloseParen
545574
if checkToken('symbol', '(', 1) then
546575
nextToken()
547576
needCloseParen = true
548577
end
549578
while true do
579+
slideToNextLine()
550580
local name
551581
try(function ()
552582
local returnName = parseName('doc.return.name', typeUnit)
@@ -2139,10 +2169,10 @@ local function bindDocs(state)
21392169
state.ast.docs.groups[#state.ast.docs.groups+1] = binded
21402170
end
21412171
binded[#binded+1] = doc
2142-
if doc.specialBindGroup then
2143-
bindDocWithSources(sources, doc.specialBindGroup)
2144-
binded = nil
2145-
elseif isTailComment(text, doc) and doc.type ~= "doc.class" and doc.type ~= "doc.field" then
2172+
if doc.specialBindGroup then
2173+
bindDocWithSources(sources, doc.specialBindGroup)
2174+
binded = nil
2175+
elseif isTailComment(text, doc) and doc.type ~= "doc.class" and doc.type ~= "doc.field" then
21462176
bindDocWithSources(sources, binded)
21472177
binded = nil
21482178
else
@@ -2278,7 +2308,7 @@ return {
22782308
doc.special = src
22792309
doc.originalComment = comment
22802310
doc.virtual = true
2281-
doc.specialBindGroup = group
2311+
doc.specialBindGroup = group
22822312
ast.state.pluginDocs = pluginDocs
22832313
return doc
22842314
end

0 commit comments

Comments
 (0)