Skip to content

Commit 62e932d

Browse files
committed
fix #82 Handle Panel{SubType} types
1 parent bee16cd commit 62e932d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { apiDefinition as structApiDefinition, markup as structMarkup, json as s
66
import { markup as panelMarkup, apiDefinition as panelApiDefinition } from '../test-data/offline-sites/gmod-wiki/panel-slider';
77
import { markup as multiReturnFuncMarkup, apiDefinition as multiReturnFuncApiDefinition } from '../test-data/offline-sites/gmod-wiki/library-function-concommand-gettable';
88
import { markup as varargsFuncMarkup, apiDefinition as varargsFuncApiDefinition } from '../test-data/offline-sites/gmod-wiki/library-function-coroutine-resume';
9-
import { Enum, LibraryFunction, WikiPage, WikiPageMarkupScraper } from '../../src/scrapers/wiki-page-markup-scraper';
9+
import { Enum, LibraryFunction, PanelFunction, WikiPage, WikiPageMarkupScraper } from '../../src/scrapers/wiki-page-markup-scraper';
1010
import { GluaApiWriter } from '../../src/api-writer/glua-api-writer';
1111
import fetchMock from "jest-fetch-mock";
1212

@@ -107,12 +107,12 @@ describe('GLua API Writer', () => {
107107
url: 'na',
108108
arguments: [
109109
{
110-
args: [ {
110+
args: [{
111111
name: 'intensity',
112112
type: 'number',
113113
description: 'The intensity of the explosion.',
114114
default: '1000',
115-
} ]
115+
}]
116116
}
117117
],
118118
returns: [
@@ -397,6 +397,28 @@ describe('GLua API Writer', () => {
397397
expect(api).toEqual(`---![(Client)](https://github.com/user-attachments/assets/a5f6ba64-374d-42f0-b2f4-50e5c964e808) Returns where on the screen the specified position vector would appear.\n---\n---[View wiki](na)\n---@return ToScreenData # The created Structures/ToScreenData.\nfunction Vector.ToScreen() end\n\n`);
398398
});
399399

400+
it('should support Panel type', () => {
401+
const writer = new GluaApiWriter();
402+
const api = writer.writePage(<PanelFunction>{
403+
name: 'GetVBar',
404+
address: 'DScrollPanel.GetVBar',
405+
parent: 'DScrollPanel',
406+
isPanelFunction: 'yes',
407+
description: 'Returns the vertical scroll bar of the panel.',
408+
realm: 'client',
409+
type: 'panelfunc',
410+
url: 'na',
411+
returns: [
412+
{
413+
type: 'Panel{DVScrollBar}',
414+
description: 'The DVScrollBar.',
415+
},
416+
],
417+
});
418+
419+
expect(api).toEqual(`---![(Client)](https://github.com/user-attachments/assets/a5f6ba64-374d-42f0-b2f4-50e5c964e808) Returns the vertical scroll bar of the panel.\n---\n---[View wiki](na)\n---@return DVScrollBar # The DVScrollBar.\nfunction DScrollPanel:GetVBar() end\n\n`);
420+
});
421+
400422
// number{ENUM_NAME} -> ENUM_NAME
401423
it('should support enum type', () => {
402424
const writer = new GluaApiWriter();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ export class GluaApiWriter {
440440
if (!innerType) throw new Error(`Invalid table type: ${type}`);
441441

442442
return `${innerType}[]`;
443-
} else if (type.startsWith('table{')) {
443+
} else if (type.startsWith('table{') || type.startsWith('Panel{')) {
444444
// Convert `table{ToScreenData}` structures to `ToScreenData` class for LuaLS
445+
// Also converts `Panel{DVScrollBar}` to `DVScrollBar` class for LuaLS
445446
let innerType = type.match(/{([^}]+)}/)?.[1];
446447

447448
if (!innerType) throw new Error(`Invalid table type: ${type}`);

0 commit comments

Comments
 (0)