Skip to content

Commit

Permalink
feat: add enable_type_names (#85)
Browse files Browse the repository at this point in the history
* feat: add enable_type_names

* tests: add enable_type_names to buf gen example

* docs: add documentation for the new parameter

* docs: update CHANGELOG

---------

Co-authored-by: jinwei.zheng <[email protected]>
Co-authored-by: Marcus Griep <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent 8f7dbc6 commit 4aa6052
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This changelog is based on the format from [Keep a Changelog](https://keepachang

## [Unreleased]

### Added

- (prost) Added support for `enable_type_names` ([#85])

[#85]: https://github.com/neoeinstein/protoc-gen-prost/pull/85

## [2024-02-14]

- `protoc-gen-prost` 0.3.0
Expand Down
1 change: 1 addition & 0 deletions example/build-with-buf/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins:
- compile_well_known_types
- extern_path=.google.protobuf=::pbjson_types
- file_descriptor_set
- enable_type_names
- plugin: prost-serde
#path: ../../target/debug/protoc-gen-prost-serde
out: src/gen
Expand Down
1 change: 1 addition & 0 deletions protoc-gen-prost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ from that crate:
* `retain_enum_prefix(=<boolean>)`: [retain_enum_prefix](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.retain_enum_prefix)
* `field_attribute=<proto_path>=<attribute>`: [field_attribute](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.field_attribute)
* `type_attribute=<proto_path>=<attribute>`: [type_attribute](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.type_attribute)
* `enable_type_names(=<boolean>)`: [enable_type_names](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.enable_type_names)

In addition, the following options can also be specified:

Expand Down
20 changes: 19 additions & 1 deletion protoc-gen-prost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ struct ProstParameters {
message_attribute: Vec<(String, String)>,
compile_well_known_types: bool,
retain_enum_prefix: bool,
enable_type_names: bool,
}

impl ProstParameters {
Expand Down Expand Up @@ -259,6 +260,9 @@ impl ProstParameters {
if self.retain_enum_prefix {
config.retain_enum_prefix();
}
if self.enable_type_names {
config.enable_type_names();
}

config
}
Expand Down Expand Up @@ -347,6 +351,17 @@ impl ProstParameters {
prefix.to_string(),
module.replace(r"\,", ",").replace(r"\\", r"\"),
)),
Param::Parameter {
param: "enable_type_names",
}
| Param::Value {
param: "enable_type_names",
value: "true",
} => self.enable_type_names = true,
Param::Value {
param: "enable_type_names",
value: "false",
} => (),
_ => return Err(param),
}

Expand Down Expand Up @@ -526,9 +541,12 @@ mod tests {

#[test]
fn compiler_option_string_with_three_plus_equals_parses_correctly() {
const INPUT: &str = r#"compile_well_known_types,disable_comments=.,extern_path=.google.protobuf=::pbjson_types,type_attribute=.=#[cfg(all(feature = "test"\, feature = "orange"))]"#;
const INPUT: &str = r#"enable_type_names,compile_well_known_types,disable_comments=.,extern_path=.google.protobuf=::pbjson_types,type_attribute=.=#[cfg(all(feature = "test"\, feature = "orange"))]"#;

let expected: &[Param] = &[
Param::Parameter {
param: "enable_type_names",
},
Param::Parameter {
param: "compile_well_known_types",
},
Expand Down

0 comments on commit 4aa6052

Please sign in to comment.