MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / generateWshClientApiMethod_Call

Function generateWshClientApiMethod_Call

pkg/tsgen/tsgen.go:483–501  ·  view source on GitHub ↗
(methodDecl *wshrpc.WshRpcMethodDecl, tsTypesMap map[reflect.Type]string)

Source from the content-addressed store, hash-verified

481}
482
483func generateWshClientApiMethod_Call(methodDecl *wshrpc.WshRpcMethodDecl, tsTypesMap map[reflect.Type]string) string {
484 var sb strings.Builder
485 sb.WriteString(fmt.Sprintf(" // command %q [%s]\n", methodDecl.Command, methodDecl.CommandType))
486 rtnType := "Promise<void>"
487 if methodDecl.DefaultResponseDataType != nil {
488 rtnTypeName, _ := TypeToTSType(methodDecl.DefaultResponseDataType, tsTypesMap)
489 rtnType = fmt.Sprintf("Promise<%s>", rtnTypeName)
490 }
491 methodSigDataParams, dataName := getTsWshMethodDataParamsAndExpr(methodDecl, tsTypesMap)
492 if methodSigDataParams == "" {
493 sb.WriteString(fmt.Sprintf(" %s(client: WshClient, opts?: RpcOpts): %s {\n", methodDecl.MethodName, rtnType))
494 } else {
495 sb.WriteString(fmt.Sprintf(" %s(client: WshClient, %s, opts?: RpcOpts): %s {\n", methodDecl.MethodName, methodSigDataParams, rtnType))
496 }
497 sb.WriteString(fmt.Sprintf(" if (this.mockClient) return this.mockClient.mockWshRpcCall(client, %q, %s, opts);\n", methodDecl.Command, dataName))
498 sb.WriteString(fmt.Sprintf(" return client.wshRpcCall(%q, %s, opts);\n", methodDecl.Command, dataName))
499 sb.WriteString(" }\n")
500 return sb.String()
501}
502
503func getTsWshMethodDataParamsAndExpr(methodDecl *wshrpc.WshRpcMethodDecl, tsTypesMap map[reflect.Type]string) (string, string) {
504 dataTypes := methodDecl.GetCommandDataTypes()

Callers 1

Calls 4

TypeToTSTypeFunction · 0.85
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected