MCPcopy Index your code
hub / github.com/github/copilot-sdk / generate

Function generate

scripts/codegen/rust.ts:2150–2229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2148}
2149
2150async function generate(): Promise<void> {
2151 console.log("Loading schemas...");
2152
2153 const schemaArgs = parseSchemaArgs();
2154 const sessionEventsSchemaPath =
2155 schemaArgs.sessionEventsSchemaPath || (await getSessionEventsSchemaPath());
2156 const apiSchemaPath = await getApiSchemaPath(schemaArgs.apiSchemaPath);
2157
2158 const sessionEventsRaw = normalizeSchemaBrandCasing(
2159 JSON.parse(await fs.readFile(sessionEventsSchemaPath, "utf-8")),
2160 );
2161 const apiRaw = normalizeSchemaBrandCasing(
2162 JSON.parse(await fs.readFile(apiSchemaPath, "utf-8")) as ApiSchema,
2163 );
2164
2165 const sessionEventsSchema = propagateInternalVisibility(
2166 postProcessSchema(
2167 stripBooleanLiterals(sessionEventsRaw) as JSONSchema7,
2168 ),
2169 );
2170 const apiSchema = propagateInternalVisibility(
2171 postProcessSchema(
2172 stripBooleanLiterals(apiRaw) as JSONSchema7,
2173 ),
2174 ) as unknown as ApiSchema;
2175
2176 // Ensure output directory exists
2177 await fs.mkdir(GENERATED_DIR, { recursive: true });
2178
2179 // Generate session events
2180 console.log("Generating session_events.rs...");
2181 const sessionEventsCode = generateSessionEventsCode(sessionEventsSchema);
2182 const sharedDefinitions = findSharedSchemaDefinitions(
2183 apiSchema as unknown as Record<string, unknown>,
2184 sessionEventsSchema as unknown as Record<string, unknown>,
2185 );
2186 const reachableDefinitions = collectReachableDefinitionNames(
2187 sessionEventsSchema as unknown as Record<string, unknown>,
2188 );
2189 for (const name of [...sharedDefinitions]) {
2190 const declarationPattern = new RegExp(`\\bpub\\s+(?:struct|enum)\\s+${name}\\b`);
2191 if (!reachableDefinitions.has(name) || !declarationPattern.test(sessionEventsCode)) {
2192 sharedDefinitions.delete(name);
2193 }
2194 }
2195 const apiSchemaForGeneration = rewriteSharedDefinitionReferences(
2196 apiSchema,
2197 sharedDefinitions,
2198 "session-events.schema.json",
2199 );
2200 const sessionEventsPath = path.join(GENERATED_DIR, "session_events.rs");
2201 await fs.writeFile(sessionEventsPath, sessionEventsCode, "utf-8");
2202 await rustfmt(sessionEventsPath);
2203
2204 // Generate API types
2205 console.log("Generating api_types.rs...");
2206 const apiTypesCode = generateApiTypesCode(
2207 apiSchemaForGeneration,

Callers 1

rust.tsFile · 0.70

Calls 15

parseSchemaArgsFunction · 0.85
postProcessSchemaFunction · 0.85
stripBooleanLiteralsFunction · 0.85
rustfmtFunction · 0.85
generateApiTypesCodeFunction · 0.85
generateModRsFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…