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

Function emitMethod

scripts/codegen/go.ts:4127–4227  ·  view source on GitHub ↗
(lines: string[], receiver: string, name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, fields: Map<string, Map<string, GoExtractedField>>, unionInfos: Map<string, GoDiscriminatedUnionInfo>, groupExperimental = false, isWrapper = false, groupDeprecated = false)

Source from the content-addressed store, hash-verified

4125}
4126
4127function emitMethod(lines: string[], receiver: string, name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, fields: Map<string, Map<string, GoExtractedField>>, unionInfos: Map<string, GoDiscriminatedUnionInfo>, groupExperimental = false, isWrapper = false, groupDeprecated = false): void {
4128 const methodName = toPascalCase(name);
4129 const resultSchema = getMethodResultSchema(method);
4130 const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined;
4131 const resultType = nullableInner
4132 ? resolveType(goNullableResultTypeName(method, nullableInner))
4133 : resolveType(goResultTypeName(method));
4134 const resultUnion = unionInfos.get(resultType);
4135 const returnType = resultUnion ? resultType : `*${resultType}`;
4136
4137 const effectiveParams = getMethodParamsSchema(method);
4138 const paramProps = effectiveParams?.properties || {};
4139 const requiredParams = new Set(effectiveParams?.required || []);
4140 const nonSessionParams = Object.keys(paramProps)
4141 .filter((k) => k !== "sessionId")
4142 .sort((left, right) => compareGoFieldNames(toGoFieldName(left), toGoFieldName(right)));
4143 const hasParams = isSession ? nonSessionParams.length > 0 : hasSchemaPayload(effectiveParams);
4144 const paramsType = hasParams ? resolveType(goParamsTypeName(method)) : "";
4145 const hasRequiredNonSessionParams = nonSessionParams.some((name) => requiredParams.has(name));
4146 const paramsAreOptional = hasParams && !!method.params && !!getNullableInner(method.params) && !hasRequiredNonSessionParams;
4147
4148 // For wrapper-level methods, access fields through a.common; for service type aliases, use a directly
4149 const clientRef = isWrapper ? "a.common.client" : "a.client";
4150 const sessionIDRef = isWrapper ? "a.common.sessionID" : "a.sessionID";
4151
4152 pushGoRpcMethodComment(
4153 lines,
4154 methodName,
4155 method,
4156 resultSchema,
4157 hasParams ? goRpcParamsDescription(method, effectiveParams) : undefined
4158 );
4159 if (method.deprecated && !groupDeprecated) {
4160 pushGoComment(lines, `Deprecated: ${methodName} is deprecated and will be removed in a future version.`);
4161 }
4162 if (method.stability === "experimental" && !groupExperimental) {
4163 pushGoExperimentalMethodComment(lines, methodName);
4164 }
4165 if (method.visibility === "internal") {
4166 pushGoComment(lines, `Internal: ${methodName} is part of the SDK's internal handshake/plumbing; external callers should not use it.`);
4167 }
4168 const sig = hasParams
4169 ? `func (a *${receiver}) ${methodName}(ctx context.Context, params ${paramsAreOptional ? "..." : ""}*${paramsType}) (${returnType}, error)`
4170 : `func (a *${receiver}) ${methodName}(ctx context.Context) (${returnType}, error)`;
4171
4172 lines.push(sig + ` {`);
4173 const paramsRef = paramsAreOptional ? "requestParams" : "params";
4174 if (paramsAreOptional) {
4175 lines.push(`\tvar requestParams *${paramsType}`);
4176 lines.push(`\tif len(params) > 0 {`);
4177 lines.push(`\t\trequestParams = params[0]`);
4178 lines.push(`\t}`);
4179 }
4180
4181 if (isSession) {
4182 lines.push(`\treq := map[string]any{"sessionId": ${sessionIDRef}}`);
4183 if (hasParams) {
4184 lines.push(`\tif ${paramsRef} != nil {`);

Callers 2

emitApiGroupFunction · 0.70
emitRpcWrapperFunction · 0.70

Calls 15

getNullableInnerFunction · 0.85
goNullableResultTypeNameFunction · 0.85
goResultTypeNameFunction · 0.85
compareGoFieldNamesFunction · 0.85
toGoFieldNameFunction · 0.85
hasSchemaPayloadFunction · 0.85
goParamsTypeNameFunction · 0.85
pushGoRpcMethodCommentFunction · 0.85
goRpcParamsDescriptionFunction · 0.85
pushGoCommentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…