From cc69d7a9b7e27ab02a147a2c5a8a074940eed340 Mon Sep 17 00:00:00 2001 From: luttje <2738114+luttje@users.noreply.github.com> Date: Sat, 29 Jul 2023 18:08:40 -0700 Subject: [PATCH] Revert "Feature/deprecated annotation" --- .../gmod-wiki/struct-custom-entity-fields.ts | 90 ++++--------------- custom/class.Color.lua | 3 +- custom/class.ENT.lua | 3 +- custom/class.NPC.lua | 3 +- custom/class.Player.lua | 3 +- custom/class.SWEP.lua | 3 +- src/api-writer/glua-api-writer.ts | 61 +++---------- src/scrapers/wiki-page-markup-scraper.ts | 43 ++------- src/utils/string.ts | 10 --- 9 files changed, 45 insertions(+), 174 deletions(-) diff --git a/__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts b/__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts index eb40029..3585768 100644 --- a/__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts +++ b/__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts @@ -46,77 +46,25 @@ This can also be set from map, see Sandbox Specific Mapping `; -export const apiDefinition = -`---@class Custom_Entity_Fields -local Custom_Entity_Fields = {} - ----\`Serverside\`, Sandbox and Sandbox derived only. Called by the Drive property to override the default drive type, which is \`drive_sandbox\`. ----@type function -Custom_Entity_Fields.GetEntityDriveMode = nil - ----Documented at ENTITY:OnEntityCopyTableFinish. ----@type function -Custom_Entity_Fields.OnEntityCopyTableFinish = nil - ----Documented at ENTITY:PostEntityCopy. ----@type function -Custom_Entity_Fields.PostEntityCopy = nil - ----Documented at ENTITY:PostEntityPaste. ----@type function -Custom_Entity_Fields.PostEntityPaste = nil - ----Documented at ENTITY:PreEntityCopy. ----@type function -Custom_Entity_Fields.PreEntityCopy = nil - ----Documented at ENTITY:OnDuplicated. ----@type function -Custom_Entity_Fields.OnDuplicated = nil - ----\`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 ----@type boolean -Custom_Entity_Fields.PhysgunDisabled = nil - ----\`Shared\`, Sandbox or Sandbox derived only. Called from GM:PhysgunPickup, overrides \`PhysgunDisabled\` ----@type function -Custom_Entity_Fields.PhysgunPickup = nil - ----\`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 ----@type table -Custom_Entity_Fields.m_tblToolsAllowed = nil - ----Documented at ENTITY:GravGunPickupAllowed. ----@type function -Custom_Entity_Fields.GravGunPickupAllowed = nil - ----Documented at ENTITY:GravGunPunt. ----@type function -Custom_Entity_Fields.GravGunPunt = nil - ----Documented at ENTITY:CanProperty. ----@type function -Custom_Entity_Fields.CanProperty = nil - ----Documented at ENTITY:CanTool. ----@type function -Custom_Entity_Fields.CanTool = nil - ----Documented at ENTITY:CalcAbsolutePosition. ----@type function -Custom_Entity_Fields.CalcAbsolutePosition = nil - ----Documented at ENTITY:RenderOverride. ----@type function -Custom_Entity_Fields.RenderOverride = nil - ----(Clientside) Do not use. ----@type Vector -Custom_Entity_Fields.m_RenderOrigin = nil - ----(Clientside) Do not use. ----@type Angle -Custom_Entity_Fields.m_RenderAngles = nil\n\n`; +export const apiDefinition = `---@class Custom_Entity_Fields +---@field GetEntityDriveMode function \`Serverside\`, Sandbox and Sandbox derived only. Called by the Drive property to override the default drive type, which is \`drive_sandbox\`. +---@field OnEntityCopyTableFinish function Documented at ENTITY:OnEntityCopyTableFinish. +---@field PostEntityCopy function Documented at ENTITY:PostEntityCopy. +---@field PostEntityPaste function Documented at ENTITY:PostEntityPaste. +---@field PreEntityCopy function Documented at ENTITY:PreEntityCopy. +---@field OnDuplicated function Documented at ENTITY:OnDuplicated. +---@field PhysgunDisabled boolean \`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 +---@field PhysgunPickup function \`Shared\`, Sandbox or Sandbox derived only. Called from GM:PhysgunPickup, overrides \`PhysgunDisabled\` +---@field m_tblToolsAllowed table \`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 +---@field GravGunPickupAllowed function Documented at ENTITY:GravGunPickupAllowed. +---@field GravGunPunt function Documented at ENTITY:GravGunPunt. +---@field CanProperty function Documented at ENTITY:CanProperty. +---@field CanTool function Documented at ENTITY:CanTool. +---@field CalcAbsolutePosition function Documented at ENTITY:CalcAbsolutePosition. +---@field RenderOverride function Documented at ENTITY:RenderOverride. +---@field m_RenderOrigin Vector (Clientside) Do not use. +---@field m_RenderAngles Angle (Clientside) Do not use. +local Custom_Entity_Fields = {}\n\n`; export const json = { name: 'Custom_Entity_Fields', diff --git a/custom/class.Color.lua b/custom/class.Color.lua index fe562d7..0550050 100644 --- a/custom/class.Color.lua +++ b/custom/class.Color.lua @@ -3,6 +3,5 @@ ---@field g number The green component of the color. ---@field b number The blue component of the color. ---@field a number The alpha component of the color. +---{{CLASS_FIELDS}} local Color = {} - ----{{CLASS_FIELDS}} \ No newline at end of file diff --git a/custom/class.ENT.lua b/custom/class.ENT.lua index c53f8bf..8a31e3a 100644 --- a/custom/class.ENT.lua +++ b/custom/class.ENT.lua @@ -1,4 +1,3 @@ ---@class ENT : Entity +---{{CLASS_FIELDS}} ENT = {} - ----{{CLASS_FIELDS}} \ No newline at end of file diff --git a/custom/class.NPC.lua b/custom/class.NPC.lua index 86adf94..37e9bb3 100644 --- a/custom/class.NPC.lua +++ b/custom/class.NPC.lua @@ -1,4 +1,3 @@ ---@class NPC : Entity +---{{CLASS_FIELDS}} local NPC = {} - ----{{CLASS_FIELDS}} \ No newline at end of file diff --git a/custom/class.Player.lua b/custom/class.Player.lua index 22c7324..23c1c16 100644 --- a/custom/class.Player.lua +++ b/custom/class.Player.lua @@ -1,4 +1,3 @@ ---@class Player : Entity +---{{CLASS_FIELDS}} local Player = {} - ----{{CLASS_FIELDS}} \ No newline at end of file diff --git a/custom/class.SWEP.lua b/custom/class.SWEP.lua index b20bfe2..c3047ef 100644 --- a/custom/class.SWEP.lua +++ b/custom/class.SWEP.lua @@ -1,4 +1,3 @@ ---@class SWEP : WEAPON +---{{CLASS_FIELDS}} SWEP = {} - ----{{CLASS_FIELDS}} \ No newline at end of file diff --git a/src/api-writer/glua-api-writer.ts b/src/api-writer/glua-api-writer.ts index 1861f89..5cc2b46 100644 --- a/src/api-writer/glua-api-writer.ts +++ b/src/api-writer/glua-api-writer.ts @@ -1,5 +1,5 @@ import { ClassFunction, Enum, Function, HookFunction, LibraryFunction, Panel, PanelFunction, Realm, Struct, WikiPage, isPanel } from '../scrapers/wiki-page-markup-scraper.js'; -import { escapeSingleQuotes, putCommentBeforeEachLine, removeNewlines, safeFileName, toLowerCamelCase } from '../utils/string.js'; +import { putCommentBeforeEachLine, removeNewlines, safeFileName, toLowerCamelCase } from '../utils/string.js'; import { isClassFunction, isHookFunction, @@ -69,12 +69,12 @@ export class GluaApiWriter { const fileSafeAddress = safeFileName(page.address, '.'); if (this.pageOverrides.has(fileSafeAddress)) { let api = ''; - + if (isClassFunction(page)) - api += this.writeClass(page.parent, undefined, undefined, page.deprecated); + api += this.writeClass(page.parent); else if (isLibraryFunction(page)) api += this.writeLibraryGlobal(page); - + api += this.pageOverrides.get(fileSafeAddress); return `${api}\n\n`; @@ -94,26 +94,23 @@ export class GluaApiWriter { return this.writeStruct(page); } - private writeClass(className: string, parent?: string, classFields: string = '', deprecated?: string ) { + private writeClass(className: string, parent?: string, classFields: string = '') { let api: string = ''; if (!this.writtenClasses.has(className)) { const classOverride = `class.${className}`; if (this.pageOverrides.has(classOverride)) { api += this.pageOverrides.get(classOverride)!.replace(/\n$/g, '') + '\n\n'; - api = api.replace('---{{CLASS_FIELDS}}', classFields); + api = api.replace('---{{CLASS_FIELDS}}\n', classFields); } else { - if (deprecated) - api += `---@deprecated ${deprecated ?? ''}\n` - api += `---@class ${className}`; if (parent) api += ` : ${parent}`; api += '\n'; - api += `local ${className} = {}\n\n`; api += classFields; + api += `local ${className} = {}\n\n`; } this.writtenClasses.add(className); @@ -124,12 +121,7 @@ export class GluaApiWriter { private writeLibraryGlobal(func: LibraryFunction) { if (!func.dontDefineParent && !this.writtenLibraryGlobals.has(func.parent)) { - let global = ''; - - if(func.deprecated) - global += `---@deprecated ${func.deprecated ?? ''}\n`; - - global += `${func.parent} = {}\n\n`; + const global = `${func.parent} = {}\n\n`; this.writtenLibraryGlobals.add(func.parent); @@ -140,7 +132,7 @@ export class GluaApiWriter { } private writeClassFunction(func: ClassFunction) { - let api: string = this.writeClass(func.parent, undefined, undefined, func.deprecated); + let api: string = this.writeClass(func.parent); api += this.writeFunctionLuaDocComment(func, func.realm); api += this.writeFunctionDeclaration(func, func.realm, ':'); @@ -162,7 +154,7 @@ export class GluaApiWriter { } private writePanel(panel: Panel) { - return this.writeClass(panel.name, panel.parent, undefined, panel.deprecated); + return this.writeClass(panel.name, panel.parent); } private writePanelFunction(func: PanelFunction) { @@ -178,9 +170,6 @@ export class GluaApiWriter { let api: string = ''; const isContainedInTable = _enum.items[0]?.key.includes('.') ?? false; - if (_enum.deprecated) - api += `---@deprecated ${_enum.deprecated ?? ''}\n`; - api += `---@enum ${_enum.name}\n`; if (isContainedInTable) @@ -191,10 +180,8 @@ export class GluaApiWriter { key = key.split('.')[1]; api += ` ${key} = ${item.value}, ` + (item.description ? `--[[ ${item.description} ]]` : '') + '\n'; } else { - api += item.description ? `${putCommentBeforeEachLine(item.description, false)}\n` : '' - if (item.deprecated) - api += `---@deprecated ${item.deprecated ?? ''}\n`; - api += `${key} = ${item.value}\n`; + const comment = item.description ? `${putCommentBeforeEachLine(item.description, false)}\n` : ''; + api += `${comment}${key} = ${item.value}\n`; } }; @@ -209,31 +196,14 @@ export class GluaApiWriter { return api; } - private writeType(type: string, value: any) { - if (type === 'string') - return `'${escapeSingleQuotes(value)}'`; - - if (type === 'Vector') - return `Vector${value}`; - - return value; - } - private writeStruct(struct: Struct) { let fields: string = ''; for (const field of struct.fields) { - if (field.deprecated) - fields += `---@deprecated ${field.deprecated ?? ''}\n`; - - fields += `---${removeNewlines(field.description).replace(/\s+/g, ' ')}\n`; - - const type = this.transformType(field.type) - fields += `---@type ${type}\n` - fields += `${struct.name}.${GluaApiWriter.safeName(field.name)} = ${field.default ? this.writeType(type, field.default) : 'nil'}\n\n`; + fields += `---@field ${GluaApiWriter.safeName(field.name)} ${this.transformType(field.type)} ${removeNewlines(field.description!)}\n`; } - return this.writeClass(struct.name, undefined, fields, struct.deprecated); + return this.writeClass(struct.name, undefined, fields); } public writePages(pages: WikiPage[]) { @@ -284,9 +254,6 @@ export class GluaApiWriter { }); } - if (func.deprecated) - luaDocComment += `---@deprecated ${func.deprecated ?? ''}\n`; - return luaDocComment; } diff --git a/src/scrapers/wiki-page-markup-scraper.ts b/src/scrapers/wiki-page-markup-scraper.ts index c09cb11..94175a1 100644 --- a/src/scrapers/wiki-page-markup-scraper.ts +++ b/src/scrapers/wiki-page-markup-scraper.ts @@ -11,7 +11,6 @@ export type CommonWikiProperties = { description: string; realm: Realm; url: string; - deprecated?: string; } export type WikiIdentifier = { @@ -51,7 +50,6 @@ export type EnumValue = { key: string; value: string; description: string; - deprecated?: string; }; export type Enum = CommonWikiProperties & { @@ -64,7 +62,6 @@ export type StructField = { type: string; default?: any; description: string; - deprecated?: string; }; export type Struct = CommonWikiProperties & { @@ -128,32 +125,15 @@ export class WikiPageMarkupScraper extends Scraper { const isFunction = $('function').length > 0; const isPanel = $('panel').length > 0; const mainElement = $(isEnum ? 'enum' : isStruct ? 'struct' : isPanel ? 'panel' : 'function'); - const isDeprecated = $('deprecated').length > 0; const address = response.url.split('/').pop()!.split('?')[0]; - let deprecated: string | undefined = undefined; - if (isDeprecated && !isEnum && !isStruct) { - deprecated = $('deprecated').map(function() { - const $el = $(this); - return $el.text().trim(); - }).get().join(' - ') - - $('deprecated').remove(); - } - if (isEnum) { const items = $('items item').map(function () { const $el = $(this); - const deprecated = $el.find('deprecated').map(function() { - const $el = $(this); - return $el.text().trim(); - }).get().join(' - '); - return { key: $el.attr('key')!, value: $el.attr('value')!, - description: $el.text(), - deprecated: deprecated || undefined, + description: $el.text() }; }).get(); @@ -168,17 +148,11 @@ export class WikiPageMarkupScraper extends Scraper { } else if (isStruct) { const fields = $('fields item').map(function () { const $el = $(this); - const deprecated = $el.find('deprecated').map(function() { - const $el = $(this); - return $el.text().trim(); - }).get().join(' - '); - return { name: $el.attr('name')!, type: $el.attr('type')!, default: $el.attr('default'), - description: $el.text(), - deprecated: deprecated || undefined, + description: $el.text() }; }).get(); @@ -188,8 +162,7 @@ export class WikiPageMarkupScraper extends Scraper { address: address, description: $('description').text(), realm: $('realm').text() as Realm, - fields, - deprecated + fields }; } else if (isPanel) { return { @@ -198,8 +171,7 @@ export class WikiPageMarkupScraper extends Scraper { address: address, description: $('description').text(), realm: $('realm').text() as Realm, - parent: $('parent').text(), - deprecated + parent: $('parent').text() }; } else if (isFunction) { const isClassFunction = mainElement.attr('type') === 'classfunc'; @@ -217,7 +189,7 @@ export class WikiPageMarkupScraper extends Scraper { if ($el.attr('default')) argument.default = $el.attr('default')!; - + return argument; }).get(); @@ -238,8 +210,7 @@ export class WikiPageMarkupScraper extends Scraper { description: $('description:first').text(), realm: $('realm:first').text() as Realm, arguments: arguments_, - returns, - deprecated + returns }; if (isClassFunction) { @@ -252,7 +223,7 @@ export class WikiPageMarkupScraper extends Scraper { base.parent = '_G'; (base).dontDefineParent = true; } - + return { ...base, type: 'libraryfunc' diff --git a/src/utils/string.ts b/src/utils/string.ts index d43428b..a9dcaa4 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -39,14 +39,4 @@ export function putCommentBeforeEachLine(text: string, skipLineOne: boolean = tr */ export function safeFileName(str: string, replacement: string = '_') { return str.replace(/[^a-z0-9_\-\. ]/gi, replacement); -} - -/** - * Escapes all single quotes in a string - * - * @param str The string to escape - * @returns The escaped string - */ -export function escapeSingleQuotes(str: string) { - return str.replace(/'/g, '\\\''); } \ No newline at end of file