Skip to content

Commit

Permalink
feat: add protoc-insertion-point
Browse files Browse the repository at this point in the history
In order for other plugins to generate extra code in the index.ts file
protoc_insertion_point can be used. This commit adds one insertion point
at the end of the file.

From docs:
> If non-empty, indicates that the named file should already exist, and the
> content here is to be inserted into that file at a defined insertion
> point.  This feature allows a code generator to extend the output
> produced by another code generator.  The original generator may provide
> insertion points by placing special annotations in the file that look
> like:
>   @@protoc_insertion_point(NAME)
  • Loading branch information
ericwenn committed Apr 28, 2021
1 parent c4f2a30 commit 0032998
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,5 @@ export function createFreightServiceClient(
},
};
}

// @@protoc_insertion_point(typescript-http-eof)
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,5 @@ export function createSyntaxServiceClient(
},
};
}

// @@protoc_insertion_point(typescript-http-eof)
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,5 @@ export type einrideexamplesyntaxv1_Message_NestedMessage = {
export type einrideexamplesyntaxv1_Message_NestedEnum =
// NESTEDENUM_UNSPECIFIED
"NESTEDENUM_UNSPECIFIED";

// @@protoc_insertion_point(typescript-http-eof)
2 changes: 2 additions & 0 deletions internal/plugin/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func Generate(request *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorRe
if err := (packageGenerator{pkg: pkg, files: files}).Generate(&index); err != nil {
return nil, fmt.Errorf("generate package '%s': %w", pkg, err)
}
index.P()
index.P("// @@protoc_insertion_point(typescript-http-eof)")
res.File = append(res.File, &pluginpb.CodeGeneratorResponse_File{
Name: proto.String(path.Join(indexPathElems...)),
Content: proto.String(string(index.Content())),
Expand Down

0 comments on commit 0032998

Please sign in to comment.