(schemaPath?: string, sessionEventsSchema?: JSONSchema7)
| 476 | } |
| 477 | |
| 478 | async function generateRpc(schemaPath?: string, sessionEventsSchema?: JSONSchema7): Promise<void> { |
| 479 | console.log("TypeScript: generating RPC types..."); |
| 480 | |
| 481 | const resolvedPath = schemaPath ?? (await getApiSchemaPath()); |
| 482 | let schema = fixNullableRequiredRefsInApiSchema((await loadSchemaJson(resolvedPath)) as ApiSchema); |
| 483 | if (sessionEventsSchema) { |
| 484 | const sharedDefinitions = findSharedSchemaDefinitions( |
| 485 | schema as unknown as Record<string, unknown>, |
| 486 | sessionEventsSchema as unknown as Record<string, unknown> |
| 487 | ); |
| 488 | const reachableDefinitions = collectReachableDefinitionNames(sessionEventsSchema as unknown as Record<string, unknown>); |
| 489 | for (const name of [...sharedDefinitions]) { |
| 490 | if (!reachableDefinitions.has(name)) { |
| 491 | sharedDefinitions.delete(name); |
| 492 | } |
| 493 | } |
| 494 | schema = rewriteSharedDefinitionReferences(schema, sharedDefinitions, "session-events.schema.json"); |
| 495 | } |
| 496 | |
| 497 | const lines: string[] = []; |
| 498 | lines.push(`/** |
| 499 | * AUTO-GENERATED FILE - DO NOT EDIT |
| 500 | * Generated from: api.schema.json |
| 501 | */ |
| 502 | |
| 503 | import type { MessageConnection } from "vscode-jsonrpc/node.js"; |
| 504 | `); |
| 505 | |
| 506 | const externalSchemaRefs = collectExternalSchemaRefNames(schema); |
| 507 | for (const [schemaFile, typeNames] of externalSchemaRefs) { |
| 508 | const importPath = EXTERNAL_SCHEMA_TS_IMPORT[schemaFile]; |
| 509 | if (importPath) { |
| 510 | lines.push(`import type { ${[...typeNames].sort().join(", ")} } from "${importPath}";`); |
| 511 | } |
| 512 | } |
| 513 | if (externalSchemaRefs.size > 0) { |
| 514 | lines.push(""); |
| 515 | } |
| 516 | |
| 517 | const allMethods = [...collectRpcMethods(schema.server || {}), ...collectRpcMethods(schema.session || {})]; |
| 518 | const clientSessionMethods = collectRpcMethods(schema.clientSession || {}); |
| 519 | const clientGlobalMethods = collectRpcMethods(schema.clientGlobal || {}); |
| 520 | const rpcMethods = [...allMethods, ...clientSessionMethods, ...clientGlobalMethods]; |
| 521 | const seenBlocks = new Map<string, string>(); |
| 522 | |
| 523 | // Build a single combined schema with shared definitions and all method types. |
| 524 | // This ensures $ref-referenced types are generated exactly once. |
| 525 | rpcDefinitions = collectDefinitionCollections(schema as Record<string, unknown>); |
| 526 | const combinedSchema = withSharedDefinitions( |
| 527 | { |
| 528 | $schema: "http://json-schema.org/draft-07/schema#", |
| 529 | type: "object", |
| 530 | }, |
| 531 | rpcDefinitions |
| 532 | ); |
| 533 | |
| 534 | // Track which type names come from experimental methods for JSDoc annotations. |
| 535 | const experimentalTypes = experimentalDefinitionNames(collectDefinitionCollections(combinedSchema as Record<string, unknown>)); |
no test coverage detected
searching dependent graphs…