Skip to content

Commit 271fe58

Browse files
authored
Merge pull request #52 from robotboy655/patch33
More various improvements to the output
2 parents 0e6c5d4 + a047daa commit 271fe58

14 files changed

+149
-66
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const json = {
1212
parent: 'Weapon',
1313
name: 'AllowsAutoSwitchTo',
1414
address: 'Weapon:AllowsAutoSwitchTo',
15-
description: 'Returns whether the weapon allows to being switched to when a better ( Weapon:GetWeight ) weapon is being picked up.',
15+
description: 'Returns whether the weapon allows to being switched to when a better ( [Weapon:GetWeight](https://wiki.facepunch.com/gmod/Weapon:GetWeight) ) weapon is being picked up.',
1616
realm: 'Shared',
1717
arguments: [],
1818
returns: [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const json = {
1414
type: 'enum',
1515
name: 'USE',
1616
address: 'USE',
17-
description: `\nEnumerations used by ENTITY:Use.\n\nNot to be confused with Enums/_USE used by Entity:SetUseType.\n`,
17+
description: `\nEnumerations used by [ENTITY:Use](https://wiki.facepunch.com/gmod/ENTITY:Use).\n\nNot to be confused with [Enums/_USE](https://wiki.facepunch.com/gmod/Enums/_USE) used by [Entity:SetUseType](https://wiki.facepunch.com/gmod/Entity:SetUseType).\n`,
1818
realm: 'Shared',
1919
items: [
2020
{

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ export const json = {
8585
description: `
8686
Called when the player spawns for the first time.
8787
88-
See GM:PlayerSpawn for a hook called every player spawn.
88+
See [GM:PlayerSpawn](https://wiki.facepunch.com/gmod/GM:PlayerSpawn) for a hook called every player spawn.
8989
90-
This hook is called before the player has fully loaded, when the player is still in seeing the \`Starting Lua\` screen. For example, trying to use the Entity:GetModel function will return the default model (\`models/player.mdl\`).
90+
**NOTE**: This hook is called before the player has fully loaded, when the player is still in seeing the \`Starting Lua\` screen. For example, trying to use the [Entity:GetModel](https://wiki.facepunch.com/gmod/Entity:GetModel) function will return the default model (\`models/player.mdl\`).
9191
92-
You can send net messages starting from the player_activate event (see Game_Events).
9392
94-
Due to the above note, sending net messages to the spawned player in this hook are highly unreliable, and they most likely won't be received (more information here: https://github.com/Facepunch/garrysmod-requests/issues/718).
93+
**NOTE**: You can send [net](https://wiki.facepunch.com/gmod/net) messages starting from the player_activate event (see [Game_Events](https://wiki.facepunch.com/gmod/Game_Events)).
94+
95+
96+
**WARNING**: Due to the above note, sending [net](https://wiki.facepunch.com/gmod/net) messages to the spawned player in this hook are highly unreliable, and they most likely won't be received (more information here: https://github.com/Facepunch/garrysmod-requests/issues/718).
9597
9698
Workaround without networking:
9799
\`\`\`
@@ -148,13 +150,13 @@ GM = {}
148150
149151
---[SERVER] Called when the player spawns for the first time.
150152
---
151-
--- See GM:PlayerSpawn for a hook called every player spawn.
153+
--- See [GM:PlayerSpawn](https://wiki.facepunch.com/gmod/GM:PlayerSpawn) for a hook called every player spawn.
152154
---
153-
--- This hook is called before the player has fully loaded, when the player is still in seeing the \`Starting Lua\` screen. For example, trying to use the Entity:GetModel function will return the default model (\`models/player.mdl\`).
155+
--- **NOTE**: This hook is called before the player has fully loaded, when the player is still in seeing the \`Starting Lua\` screen. For example, trying to use the [Entity:GetModel](https://wiki.facepunch.com/gmod/Entity:GetModel) function will return the default model (\`models/player.mdl\`).
154156
---
155-
--- You can send net messages starting from the player_activate event (see Game_Events).
157+
--- **NOTE**: You can send [net](https://wiki.facepunch.com/gmod/net) messages starting from the player_activate event (see [Game_Events](https://wiki.facepunch.com/gmod/Game_Events)).
156158
---
157-
--- Due to the above note, sending net messages to the spawned player in this hook are highly unreliable, and they most likely won't be received (more information here: https://github.com/Facepunch/garrysmod-requests/issues/718).
159+
--- **WARNING**: Due to the above note, sending [net](https://wiki.facepunch.com/gmod/net) messages to the spawned player in this hook are highly unreliable, and they most likely won't be received (more information here: https://github.com/Facepunch/garrysmod-requests/issues/718).
158160
---
159161
--- Workaround without networking:
160162
--- \`\`\`
@@ -173,7 +175,6 @@ GM = {}
173175
--- end)
174176
--- \`\`\`
175177
---
176-
---
177178
--- With networking:
178179
--- \`\`\`
179180
--- -- CLIENT

__tests__/test-data/offline-sites/gmod-wiki/library-function-concommand-gettable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const apiDefinition =
1313
`--- Missing description.
1414
concommand = {}
1515
16-
---[SHARED AND MENU] Returns the tables of all console command callbacks, and autocomplete functions, that were added to the game with concommand.Add.
16+
---[SHARED AND MENU] Returns the tables of all console command callbacks, and autocomplete functions, that were added to the game with [concommand.Add](https://wiki.facepunch.com/gmod/concommand.Add).
1717
---
1818
---[(View on wiki)](https://wiki.facepunch.com/gmod/concommand.GetTable)
1919
---@return table # Table of command callback functions.

__tests__/test-data/offline-sites/gmod-wiki/library-function-coroutine-resume.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const apiDefinition =
1515
`--- Missing description.
1616
coroutine = {}
1717
18-
---[SHARED AND MENU] Resumes the given coroutine and passes the given vararg to either the function arguments or the coroutine.yield that is inside that function and returns whatever yield is called with the next time or by the final return in the function.
18+
---[SHARED AND MENU] Resumes the given coroutine and passes the given vararg to either the function arguments or the [coroutine.yield](https://wiki.facepunch.com/gmod/coroutine.yield) that is inside that function and returns whatever yield is called with the next time or by the final return in the function.
1919
---
2020
---[(View on wiki)](https://wiki.facepunch.com/gmod/coroutine.resume)
2121
---@param coroutine thread Coroutine to resume.

__tests__/test-data/offline-sites/gmod-wiki/panel-slider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const apiDefinition =
4141
---
4242
---
4343
--- A simple slider featuring an numeric display.
44-
--- Creates a slider atop a DFrame which prints its value as it's being dragged.
44+
---
4545
---@deprecated Panel:SetActionFunction and Panel:PostMessage. Use DNumSlider instead.
4646
---@class Slider : Panel
4747
local Slider = {}\n\n`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const json = {
1414
type: 'struct',
1515
name: 'AngPos',
1616
address: 'AngPos',
17-
description: 'Table used by various functions, such as Entity:GetAttachment.',
17+
description: 'Table used by various functions, such as [Entity:GetAttachment](https://wiki.facepunch.com/gmod/Entity:GetAttachment).',
1818
realm: 'Shared',
1919
fields: [
2020
{

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ export const apiDefinition =
5050
`---
5151
--- Information about custom fields **all** entities can have.
5252
---
53-
--- See also Structures/ENT
53+
--- See also [Structures/ENT](https://wiki.facepunch.com/gmod/Structures/ENT)
5454
---
5555
---@class Custom_Entity_Fields
5656
local Custom_Entity_Fields = {}
5757
58-
---\`Serverside\`, Sandbox and Sandbox derived only. Called by the Drive property to override the default drive type, which is \`drive_sandbox\`.
58+
---\`Serverside\`, Sandbox and Sandbox derived only.
59+
---
60+
--- Called by the Drive property to override the default drive type, which is \`drive_sandbox\`.
5961
---@type function
6062
Custom_Entity_Fields.GetEntityDriveMode = nil
6163
@@ -79,15 +81,23 @@ Custom_Entity_Fields.PreEntityCopy = nil
7981
---@type function
8082
Custom_Entity_Fields.OnDuplicated = nil
8183
82-
---\`Shared\`, Sandbox or Sandbox derived only. If set to \`true\`, physgun will not be able to pick this entity up. This can also be set from map, see Sandbox Specific Mapping
84+
---\`Shared\`, Sandbox or Sandbox derived only.
85+
---
86+
--- If set to \`true\`, physgun will not be able to pick this entity up. This can also be set from map, see Sandbox Specific Mapping
8387
---@type boolean
8488
Custom_Entity_Fields.PhysgunDisabled = nil
8589
86-
---\`Shared\`, Sandbox or Sandbox derived only. Called from GM:PhysgunPickup, overrides \`PhysgunDisabled\`
90+
---\`Shared\`, Sandbox or Sandbox derived only.
91+
---
92+
--- Called from GM:PhysgunPickup, overrides \`PhysgunDisabled\`
8793
---@type function
8894
Custom_Entity_Fields.PhysgunPickup = nil
8995
90-
---\`Shared\`, Sandbox or Sandbox derived only. Controls 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. This can also be set from map, see Sandbox Specific Mapping
96+
---\`Shared\`, Sandbox or Sandbox derived only.
97+
---
98+
--- Controls 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.
99+
---
100+
--- This can also be set from map, see Sandbox Specific Mapping
91101
---@type table
92102
Custom_Entity_Fields.m_tblToolsAllowed = nil
93103

__tests__/utils/string.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('putCommentBeforeEachLine', () => {
3232
['hello\r\nworld', '--- hello\n--- world'],
3333
['hello\n\nworld', '--- hello\n---\n--- world'],
3434
['hello\r\n\r\nworld', '--- hello\n---\n--- world'],
35-
['hello\n\n\n\nworld', '--- hello\n---\n---\n---\n--- world'],
36-
['hello\r\n\r\n\r\n\r\nworld', '--- hello\n---\n---\n---\n--- world'],
35+
['hello\n\n\n\nworld', '--- hello\n---\n--- world'],
36+
['hello\r\n\r\n\r\n\r\nworld', '--- hello\n---\n--- world'],
3737
])('should put a comment before each line', (input, expected, skipFirstLine = false) => {
3838
expect(putCommentBeforeEachLine(input, skipFirstLine)).toBe(expected);
3939
});

custom/class.ENT.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
---@class ENT : Entity
1+
---@class ENT : ENTITY
22
ENT = {}

custom/class.TOOL.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
--- The **TOOL** table is used in Sandbox tool creation. You can find a list of callbacks on the page and a list of methods on the page. Do note that some of the fields below have no effect on server-side operations.
3+
---
4+
--- The tool information box drawn on the HUD while your tool is selected has 2 values that are set by [language.Add](https://wiki.facepunch.com/gmod/language.Add).
5+
--- * `tool.[tool mode].name` - The tool name (Note this is NOT the same as TOOL.Name)
6+
--- * `tool.[tool mode].desc` - The tool description
7+
---
8+
--- Ensure that all tool file names are entirely lowercase. Including capital letters can lead to unintended behavior.
9+
---
10+
---@class TOOL : Tool
11+
TOOL = {}

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class GluaApiWriter {
158158
if (!this.writtenLibraryGlobals.has(page.name)) {
159159
let api = '';
160160

161-
api += page.description ? `${putCommentBeforeEachLine(page.description, false)}\n` : '';
161+
api += page.description ? `${putCommentBeforeEachLine(page.description.trim(), false)}\n` : '';
162162

163163
if (page.deprecated)
164164
api += `---@deprecated ${removeNewlines(page.deprecated)}\n`;
@@ -232,9 +232,8 @@ export class GluaApiWriter {
232232

233233
api += `---@enum ${_enum.name}\n`;
234234

235-
if (isContainedInTable)
236-
{
237-
api += _enum.description ? `${putCommentBeforeEachLine(_enum.description, false)}\n` : '';
235+
if (isContainedInTable) {
236+
api += _enum.description ? `${putCommentBeforeEachLine(_enum.description.trim(), false)}\n` : '';
238237
api += `${_enum.name} = {\n`;
239238
}
240239

@@ -243,7 +242,7 @@ export class GluaApiWriter {
243242
key = key.split('.')[1];
244243
api += ` ${key} = ${item.value}, ` + (item.description ? `--[[ ${item.description} ]]` : '') + '\n';
245244
} else {
246-
api += item.description ? `${putCommentBeforeEachLine(item.description, false)}\n` : '';
245+
api += item.description ? `${putCommentBeforeEachLine(item.description.trim(), false)}\n` : '';
247246
if (item.deprecated)
248247
api += `---@deprecated ${removeNewlines(item.deprecated)}\n`;
249248
api += `${key} = ${item.value}\n`;
@@ -278,9 +277,9 @@ export class GluaApiWriter {
278277
if (field.deprecated)
279278
api += `---@deprecated ${removeNewlines(field.deprecated)}\n`;
280279

281-
api += `---${removeNewlines(field.description).replace(/\s+/g, ' ')}\n`;
280+
api += `---${putCommentBeforeEachLine(field.description.trim())}\n`;
282281

283-
const type = this.transformType(field.type)
282+
const type = this.transformType(field.type, field.callback);
284283
api += `---@type ${type}\n`;
285284
api += `${struct.name}.${GluaApiWriter.safeName(field.name)} = ${field.default ? this.writeType(type, field.default) : 'nil'}\n\n`;
286285
}
@@ -335,15 +334,21 @@ export class GluaApiWriter {
335334
let cbStr = `fun(`;
336335

337336
for (const arg of callback.arguments || []) {
338-
cbStr += `${GluaApiWriter.safeName(arg.name)}: ${this.transformType(arg.type)}, `;
337+
if (!arg.name) arg.name = arg.type;
338+
if (arg.type === 'vararg') arg.name = '...';
339+
340+
cbStr += `${GluaApiWriter.safeName(arg.name)}: ${this.transformType(arg.type)}${arg.default !== undefined ? `?` : ''}, `;
339341
}
340342
if (cbStr.endsWith(", ")) cbStr = cbStr.substring(0, cbStr.length-2);
341343
cbStr += ")";
342344

343-
if (callback.returns && callback.returns.length > 0) {
344-
const ret = callback.returns[0];
345-
cbStr += `: ${this.transformType(ret.type)}`;
345+
for (const ret of callback.returns || []) {
346+
if (!ret.name) ret.name = ret.type;
347+
if (ret.type === 'vararg') ret.name = '...';
348+
349+
cbStr += `: ${this.transformType(ret.type)}${ret.default !== undefined ? `?` : ''}, `;
346350
}
351+
if (cbStr.endsWith(", ")) cbStr = cbStr.substring(0, cbStr.length-2);
347352

348353
return cbStr;
349354
}
@@ -366,20 +371,20 @@ export class GluaApiWriter {
366371
let types = this.transformType(arg.type, arg.callback);
367372
if (arg.altType) types += "|" + this.transformType(arg.altType);
368373

369-
luaDocComment += `---@param ${GluaApiWriter.safeName(arg.name)}${arg.default !== undefined ? `?` : ''} ${types} ${putCommentBeforeEachLine(arg.description!)}\n`;
374+
luaDocComment += `---@param ${GluaApiWriter.safeName(arg.name)}${arg.default !== undefined ? `?` : ''} ${types} ${putCommentBeforeEachLine(arg.description!.trimEnd())}\n`;
370375
});
371376
}
372377

373378
if (func.returns) {
374379
func.returns.forEach(ret => {
375-
const description = removeNewlines(ret.description ?? '');
380+
const description = putCommentBeforeEachLine(ret.description!.trimEnd());
376381

377382
luaDocComment += `---@return `;
378383

379384
if (ret.type === 'vararg')
380385
luaDocComment += 'any ...';
381386
else
382-
luaDocComment += `${this.transformType(ret.type)}`;
387+
luaDocComment += `${this.transformType(ret.type, ret.callback)}`;
383388

384389
luaDocComment += ` # ${description}\n`;
385390
});

0 commit comments

Comments
 (0)