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

Function generateGoRpcTypeCode

scripts/codegen/go.ts:3059–3096  ·  view source on GitHub ↗
(definitions: Record<string, JSONSchema7>, definitionCollections: DefinitionCollections)

Source from the content-addressed store, hash-verified

3057}
3058
3059function generateGoRpcTypeCode(definitions: Record<string, JSONSchema7>, definitionCollections: DefinitionCollections): GoGeneratedTypeCode {
3060 const ctx: GoCodegenCtx = {
3061 structs: [],
3062 encoding: [],
3063 enums: [],
3064 enumsByName: new Map(),
3065 discriminatedUnions: new Map(),
3066 generatedNames: new Set(),
3067 definitions: definitionCollections,
3068 packageName: "rpc",
3069 };
3070 ctx.skipDefinitionTypeNames = collectGoDiscriminatedUnionVariantDefinitionTypeNames(definitions, ctx);
3071 const schemaKeysByTypeName = new Map<string, string>();
3072 const entries = Object.entries(definitions)
3073 .sort(([left], [right]) => goDefinitionName(left).localeCompare(goDefinitionName(right)));
3074
3075 for (const [definitionName, definition] of entries) {
3076 const typeName = goDefinitionName(definitionName);
3077 if (ctx.skipDefinitionTypeNames.has(typeName)) continue;
3078 const schemaKey = stableStringify(resolveSchema(definition, definitionCollections) ?? definition);
3079 const existingSchemaKey = schemaKeysByTypeName.get(typeName);
3080 if (existingSchemaKey && existingSchemaKey !== schemaKey) {
3081 throw new Error(`Conflicting Go RPC type name "${typeName}" for different schemas. Add a schema title/withTypeName to disambiguate.`);
3082 }
3083 schemaKeysByTypeName.set(typeName, schemaKey);
3084 emitGoRpcDefinition(definitionName, definition, ctx);
3085 }
3086
3087 const lines: string[] = [];
3088 pushGoCodeBlocks(lines, sortedGoDeclaredTypeBlocks(ctx.structs));
3089 pushGoCodeBlocks(lines, sortedGoDeclaredTypeBlocks(ctx.enums));
3090
3091 return {
3092 typeCode: joinGoCode(lines),
3093 encodingCode: goEncodingBlocksCode(ctx.encoding),
3094 discriminatedUnions: new Map(ctx.discriminatedUnions),
3095 };
3096}
3097
3098function goDeclaredTypeName(code: string): string {
3099 return /^type\s+(\w+)\b/m.exec(code)?.[1] ?? code;

Callers 1

generateRpcFunction · 0.85

Calls 11

goDefinitionNameFunction · 0.85
resolveSchemaFunction · 0.85
emitGoRpcDefinitionFunction · 0.85
pushGoCodeBlocksFunction · 0.85
joinGoCodeFunction · 0.85
goEncodingBlocksCodeFunction · 0.85
stableStringifyFunction · 0.70
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…