@@ -59,8 +59,12 @@ interface Module {
5959
6060// ── Parsing ────────────────────────────────────────────────────────
6161
62- /** Match a type that may contain generics and union pipes: table<string, string>, string|string[] */
63- const TYPE_RE = / (?: \S + < [ ^ > ] + > | \S + (?: \| (?: \S + < [ ^ > ] + > | \S + ) ) * ) /
62+ /** Match a LuaLS type annotation:
63+ * - fun(tbl: table): table — function signatures with parens/spaces
64+ * - table<string, string> — generics with angle brackets
65+ * - string|string[] — union types
66+ */
67+ const TYPE_RE = / (?: f u n \( [ ^ ) ] * \) (?: \s * : \s * \S + ) ? | \S + < [ ^ > ] + > | \S + (?: \| (?: \S + < [ ^ > ] + > | \S + ) ) * ) /
6468
6569function parseFile ( filepath : string , root : string ) : Module | null {
6670 const rel = relative ( root , filepath )
@@ -205,29 +209,42 @@ function renderBlock(block: DocBlock, mod: Module): string {
205209 }
206210
207211 if ( block . params . length ) {
208- for ( const p of block . params ) {
209- const classDef = mod . classes . get ( p . type )
210- if ( classDef ) {
211- out . push ( `**\`${ p . name } \`** \`${ escapeCell ( p . type ) } \` — ${ escapeCell ( p . desc ) } ` )
212- out . push ( "" )
213- renderFields ( out , classDef . fields )
214- out . push ( "" )
215- } else {
216- out . push ( "**Parameters:**" )
217- out . push ( "" )
218- out . push ( "| Name | Type | Description |" )
219- out . push ( "|------|------|-------------|" )
212+ // Split params into class-typed (expanded inline) and plain
213+ const classParams = block . params . filter ( ( p ) => mod . classes . has ( p . type ) )
214+ const plainParams = block . params . filter ( ( p ) => ! mod . classes . has ( p . type ) )
215+
216+ if ( plainParams . length ) {
217+ out . push ( "**Parameters:**" )
218+ out . push ( "" )
219+ out . push ( "| Name | Type | Description |" )
220+ out . push ( "|------|------|-------------|" )
221+ for ( const p of plainParams ) {
220222 out . push ( `| \`${ p . name } \` | \`${ escapeCell ( p . type ) } \` | ${ escapeCell ( p . desc ) } |` )
221- out . push ( "" )
222223 }
224+ out . push ( "" )
225+ }
226+
227+ for ( const p of classParams ) {
228+ const classDef = mod . classes . get ( p . type ) !
229+ out . push ( `**\`${ p . name } \`** \`${ escapeCell ( p . type ) } \` — ${ escapeCell ( p . desc ) } ` )
230+ out . push ( "" )
231+ renderFields ( out , classDef . fields )
232+ out . push ( "" )
223233 }
224234 }
225235
226236 if ( block . returns . length ) {
227- out . push ( "**Returns:** " , "" )
237+ out . push ( "**Returns:**" , "" )
228238 for ( const r of block . returns ) {
229- const desc = r . desc ? ` — ${ r . desc } ` : ""
230- out . push ( `- \`${ escapeCell ( r . type ) } \`${ desc } ` )
239+ const classDef = mod . classes . get ( r . type )
240+ if ( classDef ) {
241+ out . push ( `- \`${ escapeCell ( r . type ) } \`${ r . desc ? ` — ${ r . desc } ` : "" } ` )
242+ out . push ( "" )
243+ renderFields ( out , classDef . fields )
244+ } else {
245+ const desc = r . desc ? ` — ${ r . desc } ` : ""
246+ out . push ( `- \`${ escapeCell ( r . type ) } \`${ desc } ` )
247+ }
231248 }
232249 out . push ( "" )
233250 }
0 commit comments