Skip to content

Commit ea210e0

Browse files
committed
Support structure type table{StructureName}
1 parent ee4ddf3 commit ea210e0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

__tests__/api-writer/glua-api-writer.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,28 @@ describe('GLua API Writer', () => {
297297
expect(api).toEqual(`---[SHARED] Just for testing.\n---\n---[(View on wiki)](na)\n---@param value table<string|number>|string The value to fake.\nfunction test.Fake(value) end\n\n`);
298298
});
299299

300+
it('should support structure table type', () => {
301+
const writer = new GluaApiWriter();
302+
const api = writer.writePage(<LibraryFunction>{
303+
name: 'ToScreen',
304+
address: 'Vector.ToScreen',
305+
parent: 'Vector',
306+
dontDefineParent: true,
307+
description: 'Returns where on the screen the specified position vector would appear.',
308+
realm: 'Client',
309+
type: 'libraryfunc',
310+
url: 'na',
311+
returns: [
312+
{
313+
type: 'table{ToScreenData}',
314+
description: 'The created Structures/ToScreenData.',
315+
},
316+
],
317+
});
318+
319+
expect(api).toEqual(`---[CLIENT] Returns where on the screen the specified position vector would appear.\n---\n---[(View on wiki)](na)\n---@return ToScreenData # The created Structures/ToScreenData.\nfunction Vector.ToScreen() end\n\n`);
320+
});
321+
300322
// it('should be able to write Annotated API files directly from wiki pages', async () => {
301323
// const baseUrl = 'https://wiki.facepunch.com/gmod/GM:AcceptInput';
302324
// fetchMock.mockResponseOnce(html, { url: baseUrl });

src/api-writer/glua-api-writer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ export class GluaApiWriter {
358358
if (!innerType) throw new Error(`Invalid table type: ${type}`);
359359

360360
return `${innerType}[]`;
361+
} else if (type.startsWith('table{')) {
362+
// Convert table{ToScreenData} structures to ToScreenData class for LuaLS
363+
let innerType = type.match(/{([^}]+)}/)?.[1];
364+
365+
if (!innerType) throw new Error(`Invalid table type: ${type}`);
366+
367+
return innerType;
361368
}
362369

363370
return type;

0 commit comments

Comments
 (0)