From 98eca532379dc1c2f3200a1663127d1a333569e8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 25 Sep 2026 01:18:45 +0000 Subject: [PATCH] schema: handle typedefs without a parsed signature The tree-sitter parser emits parsedSignature: null for typedefs and typeset members that aren't function signatures, such as `typedef Address = int`, matching Option in libschema. The TS schema typed it as always present, so searching a bundle with one threw on `.arguments`. Type parsedSignature as nullable and index only the name when it's null. Bumps the schema to 0.1.19. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NLCPZBzDzF1cP5qKEEhEsg --- schema/package.json | 2 +- schema/src/classes/symbol/type_def.ts | 5 +++-- schema/src/classes/symbol/type_set.ts | 4 ++++ schema/src/interfaces/symbol/type_def.ts | 3 ++- schema/src/interfaces/symbol/type_set.ts | 3 ++- schema/src/tests/search_index.test.ts | 8 +++++++- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/schema/package.json b/schema/package.json index fd2baec..e1d2a6f 100644 --- a/schema/package.json +++ b/schema/package.json @@ -1,6 +1,6 @@ { "name": "@sourcemod-dev/schema", - "version": "0.1.18", + "version": "0.1.19", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/schema/src/classes/symbol/type_def.ts b/schema/src/classes/symbol/type_def.ts index bc2db77..8f3aa48 100644 --- a/schema/src/classes/symbol/type_def.ts +++ b/schema/src/classes/symbol/type_def.ts @@ -10,9 +10,10 @@ export class TypeDefinition extends Declaration implements ITypeDefinition, Sear /** * @brief Parsed function signature + * @note Null if type is not a function signature, such as `typedef Address = int` * @readonly */ - readonly parsedSignature: ITypeSignature; + readonly parsedSignature: ITypeSignature | null; readonly identifier: Identifier = Identifier.TypeDefinition; @@ -28,7 +29,7 @@ export class TypeDefinition extends Declaration implements ITypeDefinition, Sear const parents = [...options.parents, `${this.identifier}.${this.name}`]; - if (options.l1Only !== true) { + if (options.l1Only !== true && this.parsedSignature !== null) { for (const arg of this.parsedSignature.arguments) { ret.push({ name: arg.type, diff --git a/schema/src/classes/symbol/type_set.ts b/schema/src/classes/symbol/type_set.ts index 7dda3ff..6f39533 100644 --- a/schema/src/classes/symbol/type_set.ts +++ b/schema/src/classes/symbol/type_set.ts @@ -23,6 +23,10 @@ export class TypeSet extends Declaration implements ITypeSet, Searchable { if (options.l1Only !== true) { for (const type of Object.values(this.types)) { + if (type.parsedSignature === null) { + continue; + } + for (const arg of type.parsedSignature.arguments) { ret.push({ name: arg.name, diff --git a/schema/src/interfaces/symbol/type_def.ts b/schema/src/interfaces/symbol/type_def.ts index f65a827..31dbcc8 100644 --- a/schema/src/interfaces/symbol/type_def.ts +++ b/schema/src/interfaces/symbol/type_def.ts @@ -10,9 +10,10 @@ export interface ITypeDefinition extends IDeclaration { /** * @brief Parsed function signature + * @note Null if type is not a function signature, such as `typedef Address = int` * @readonly */ - readonly parsedSignature: ITypeSignature; + readonly parsedSignature: ITypeSignature | null; } export interface ITypeSignature { diff --git a/schema/src/interfaces/symbol/type_set.ts b/schema/src/interfaces/symbol/type_set.ts index abad50a..0fabdb7 100644 --- a/schema/src/interfaces/symbol/type_set.ts +++ b/schema/src/interfaces/symbol/type_set.ts @@ -13,9 +13,10 @@ export interface IType extends IDocumentation { /** * @brief Parsed function signature + * @note Null if type is not a function signature, such as `typedef Address = int` * @readonly */ - readonly parsedSignature: ITypeSignature; + readonly parsedSignature: ITypeSignature | null; } export interface ITypeSet extends IDeclaration { diff --git a/schema/src/tests/search_index.test.ts b/schema/src/tests/search_index.test.ts index 39c0d51..d084cfe 100644 --- a/schema/src/tests/search_index.test.ts +++ b/schema/src/tests/search_index.test.ts @@ -91,6 +91,7 @@ const data = { ...decl('SQLQueryCallback'), types: { a: { ...decl(''), type: 'function void (Database db)', parsedSignature: sig('void', [['db', 'Database']]) }, + b: { ...decl(''), type: 'int', parsedSignature: null }, }, }, }, @@ -100,6 +101,11 @@ const data = { type: 'function Action (int client, const char[] command)', parsedSignature: sig('Action', [['client', 'int'], ['command', 'const char[]']]), }, + Address: { + ...decl('Address'), + type: 'int', + parsedSignature: null, + }, }, }, }, @@ -109,7 +115,7 @@ const needles = [ '', 'a', 'A', ' ', 'int', 'INT', 'void', 'char[]', 'const char[]', 'constchar[]', 'const char[]', 'ArrayList', 'arraylist', 'Array List', 'Array', 'GetClientName', 'getclientname', 'GetClient', 'ClientName', 'GetClinetName', 'NetFlow', 'netflow_in', 'MAX', 'max_name', 'userid', 'Player', - 'Database', 'Action', 'Length', 'xyzzy', 'Q', + 'Database', 'Action', 'Length', 'Address', 'xyzzy', 'Q', ]; // Score every entry, as search did before indexing