Skip to content

Commit f5d381f

Browse files
authored
Merge pull request #12 from luttje/bugfix/hardcoded-overloads
Bugfix/hardcoded overloads
2 parents f607544 + 8db0ff6 commit f5d381f

23 files changed

+412
-35
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ jobs:
2121
- name: Check if there have been changes to the wiki
2222
id: wiki_confirm_no_changes
2323
continue-on-error: true
24-
run: npm run cli:wiki-check-changed $(git tag -l --sort=-v:refname)
24+
run: npm run wiki-check-changed $(git tag -l --sort=-v:refname)
2525
- name: Install zip
2626
if: ${{ steps.wiki_confirm_no_changes.outcome == 'failure' }}
2727
uses: montudor/action-zip@v1
2828
- name: Scrape wiki
2929
if: ${{ steps.wiki_confirm_no_changes.outcome == 'failure' }}
30-
run: npm run cli:scrape-wiki
30+
run: npm run scrape-wiki
3131
- name: Format the output with StyLua
3232
uses: JohnnyMorganz/stylua-action@v2
3333
with:
@@ -36,7 +36,7 @@ jobs:
3636
args: output/
3737
- name: Pack release
3838
if: ${{ steps.wiki_confirm_no_changes.outcome == 'failure' }}
39-
run: npm run cli:pack-release
39+
run: npm run pack-release
4040
- name: Get release files and version
4141
if: ${{ steps.wiki_confirm_no_changes.outcome == 'failure' }}
4242
id: release_json
@@ -72,7 +72,7 @@ jobs:
7272
artifacts: ${{ join(fromJson(env.releaseJson).releaseFiles, ',') }}
7373
- name: Publish Lua Language Server Library
7474
if: ${{ steps.wiki_confirm_no_changes.outcome == 'failure' }}
75-
run: npm run cli:publish-library
75+
run: npm run publish-library
7676
- name: Copy library to it's own branch
7777
if: ${{ steps.wiki_confirm_no_changes.outcome == 'failure' }}
7878
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can clone this repository and run the scraper yourself. This is useful if yo
4949

5050
2. Install the dependencies with `npm install`
5151

52-
3. Run the scraper with `npm run cli:scrape-wiki`
52+
3. Run the scraper with `npm run scrape-wiki`
5353

5454
### Testing the project
5555

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { apiDefinition as hookApiDefinition, json as hookJson } from '../test-data/offline-sites/gmod-wiki/hook-player-initial-spawn';
22
// import { apiDefinition as classFunctionApiDefinition, json as classFunctionJson } from '../test-data/offline-sites/gmod-wiki/class-function-weapon-allowsautoswitchto';
33
// import { apiDefinition as libraryFunctionApiDefinition, json as libraryFunctionJson } from '../test-data/offline-sites/gmod-wiki/library-function-ai-getscheduleid';
4-
// import { apiDefinition as structApiDefinition, json as structJson } from '../test-data/offline-sites/gmod-wiki/struct-ang-pos';
5-
import { apiDefinition as structApiDefinition, markup as structMarkup } from '../test-data/offline-sites/gmod-wiki/struct-custom-entity-fields';
4+
import { apiDefinition as structApiDefinition, markup as structMarkup, json as structJson } from '../test-data/offline-sites/gmod-wiki/struct-custom-entity-fields';
65
// import { apiDefinition as enumApiDefinition, json as enumJson } from '../test-data/offline-sites/gmod-wiki/enums-use';
76
import { WikiPage, WikiPageMarkupScraper } from '../../src/scrapers/wiki-page-markup-scraper';
87
import { GluaApiWriter } from '../../src/api-writer/glua-api-writer';
@@ -36,6 +35,28 @@ describe('GLua API Writer', () => {
3635
expect(api).toEqual(structApiDefinition);
3736
});
3837

38+
it('should allow overriding specific page addresses', () => {
39+
const writer = new GluaApiWriter();
40+
const override = Math.random().toString(36).substring(7);
41+
writer.addOverride(hookJson.address, override);
42+
43+
const api = writer.writePages([<WikiPage>hookJson]);
44+
45+
expect(api).toEqual(override);
46+
});
47+
48+
it('should allow overriding specific class declarations', () => {
49+
const writer = new GluaApiWriter();
50+
const overrideStart = `---@class Custom_Entity_Fields : Parent`;
51+
const override = `${overrideStart}\n---{{CLASS_FIELDS}}\nlocal Custom_Entity_Fields = {}`;
52+
writer.addOverride('class.Custom_Entity_Fields', override);
53+
54+
const api = writer.writePages([<WikiPage>structJson]);
55+
56+
expect(api).toMatch(new RegExp(`^${overrideStart}`));
57+
});
58+
59+
3960
// it('should be able to write Annotated API files directly from wiki pages', async () => {
4061
// const baseUrl = 'https://wiki.facepunch.com/gmod/GM:AcceptInput';
4162
// fetchMock.mockResponseOnce(html, { url: baseUrl });

__tests__/test-data/offline-sites/gmod-wiki/class-function-weapon-allowsautoswitchto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const json = {
1111
type: 'classfunc',
1212
parent: 'Weapon',
1313
name: 'AllowsAutoSwitchTo',
14+
address: 'Weapon:AllowsAutoSwitchTo',
1415
description: 'Returns whether the weapon allows to being switched to when a better ( Weapon:GetWeight ) weapon is being picked up.',
1516
realm: 'Shared',
1617
arguments: [],

__tests__/test-data/offline-sites/gmod-wiki/enums-use.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const json = {
1313
url: 'https://wiki.facepunch.com/gmod/Enums/USE',
1414
type: 'enum',
1515
name: 'USE',
16+
address: 'USE',
1617
description: `\nEnumerations used by ENTITY:Use.\n\nNot to be confused with Enums/_USE used by Entity:SetUseType.\n`,
1718
realm: 'Shared',
1819
items: [

__tests__/test-data/offline-sites/gmod-wiki/hook-player-initial-spawn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const json = {
8181
type: 'hook',
8282
parent: 'GM',
8383
name: 'PlayerInitialSpawn',
84+
address: 'GM:PlayerInitialSpawn',
8485
description: `
8586
Called when the player spawns for the first time.
8687

__tests__/test-data/offline-sites/gmod-wiki/library-function-ai-getscheduleid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const json = {
1414
type: 'libraryfunc',
1515
parent: 'ai',
1616
name: 'GetScheduleID',
17+
address: 'ai.GetScheduleID',
1718
description: 'Translates a schedule name to its corresponding ID.',
1819
realm: 'Server',
1920
arguments: [

__tests__/test-data/offline-sites/gmod-wiki/struct-ang-pos.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const json = {
1313
url: 'https://wiki.facepunch.com/gmod/Structures/AngPos',
1414
type: 'struct',
1515
name: 'AngPos',
16+
address: 'AngPos',
1617
description: 'Table used by various functions, such as Entity:GetAttachment.',
1718
realm: 'Shared',
1819
fields: [

__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,97 @@ export const apiDefinition = `---@class Custom_Entity_Fields
6464
---@field RenderOverride function Documented at ENTITY:RenderOverride.
6565
---@field m_RenderOrigin Vector (Clientside) Do not use.
6666
---@field m_RenderAngles Angle (Clientside) Do not use.
67-
local Custom_Entity_Fields = {}\n\n`;
67+
local Custom_Entity_Fields = {}\n\n`;
68+
69+
export const json = {
70+
name: 'Custom_Entity_Fields',
71+
address: 'Custom_Entity_Fields',
72+
type: 'struct',
73+
fields: [
74+
{
75+
name: 'GetEntityDriveMode',
76+
type: 'function',
77+
description: '`Serverside`, Sandbox and Sandbox derived only.\n\nCalled by the Drive property to override the default drive type, which is `drive_sandbox`.',
78+
},
79+
{
80+
name: 'OnEntityCopyTableFinish',
81+
type: 'function',
82+
description: 'Documented at ENTITY:OnEntityCopyTableFinish.',
83+
},
84+
{
85+
name: 'PostEntityCopy',
86+
type: 'function',
87+
description: 'Documented at ENTITY:PostEntityCopy.',
88+
},
89+
{
90+
name: 'PostEntityPaste',
91+
type: 'function',
92+
description: 'Documented at ENTITY:PostEntityPaste.',
93+
},
94+
{
95+
name: 'PreEntityCopy',
96+
type: 'function',
97+
description: 'Documented at ENTITY:PreEntityCopy.',
98+
},
99+
{
100+
name: 'OnDuplicated',
101+
type: 'function',
102+
description: 'Documented at ENTITY:OnDuplicated.',
103+
},
104+
{
105+
name: 'PhysgunDisabled',
106+
type: 'boolean',
107+
description: '`Shared`, Sandbox or Sandbox derived only.\n\nIf set to `true`, physgun will not be able to pick this entity up. This can also be set from map, see Sandbox Specific Mapping',
108+
},
109+
{
110+
name: 'PhysgunPickup',
111+
type: 'function',
112+
description: '`Shared`, Sandbox or Sandbox derived only.\n\nCalled from GM:PhysgunPickup, overrides `PhysgunDisabled`',
113+
},
114+
{
115+
name: 'm_tblToolsAllowed',
116+
type: 'table',
117+
description: '`Shared`, Sandbox or Sandbox derived only.\n\nControls which tools **and** properties can be used on this entity. Format is a list of strings where each string is the tool or property classname.\n\nThis can also be set from map, see Sandbox Specific Mapping',
118+
},
119+
{
120+
name: 'GravGunPickupAllowed',
121+
type: 'function',
122+
description: 'Documented at ENTITY:GravGunPickupAllowed.',
123+
},
124+
{
125+
name: 'GravGunPunt',
126+
type: 'function',
127+
description: 'Documented at ENTITY:GravGunPunt.',
128+
},
129+
{
130+
name: 'CanProperty',
131+
type: 'function',
132+
description: 'Documented at ENTITY:CanProperty.',
133+
},
134+
{
135+
name: 'CanTool',
136+
type: 'function',
137+
description: 'Documented at ENTITY:CanTool.',
138+
},
139+
{
140+
name: 'CalcAbsolutePosition',
141+
type: 'function',
142+
description: 'Documented at ENTITY:CalcAbsolutePosition.',
143+
},
144+
{
145+
name: 'RenderOverride',
146+
type: 'function',
147+
description: 'Documented at ENTITY:RenderOverride.',
148+
},
149+
{
150+
name: 'm_RenderOrigin',
151+
type: 'Vector',
152+
description: '(Clientside) Do not use.',
153+
},
154+
{
155+
name: 'm_RenderAngles',
156+
type: 'Angle',
157+
description: '(Clientside) Do not use.',
158+
},
159+
],
160+
};

custom/_angle.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---@meta
2+
3+
---[SHARED AND MENU] Creates an Angle object.
4+
--- This function is very expensive when used in often running hooks or in operations requiring very frequent calls (like loops for example). It is better to store the angle in a variable or to use the [default angle](https://wiki.facepunch.com/gmod/Global_Variables#misc) available.
5+
---
6+
---[(View on wiki)](https://wiki.facepunch.com/gmod/Global.Angle)
7+
---@param angle string Will be parsed to an angle. If it fails, a 0 angle will be returned.
8+
---@return Angle #Created angle
9+
function _G.Angle(angle) end
10+
11+
---[SHARED AND MENU] Creates an Angle object.
12+
--- This function is very expensive when used in often running hooks or in operations requiring very frequent calls (like loops for example). It is better to store the angle in a variable or to use the [default angle](https://wiki.facepunch.com/gmod/Global_Variables#misc) available.
13+
---
14+
---[(View on wiki)](https://wiki.facepunch.com/gmod/Global.Angle)
15+
---@param angle Angle A copy of this angle will be returned.
16+
---@return Angle #Created angle
17+
function _G.Angle(angle) end

0 commit comments

Comments
 (0)