Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add enable_type_names #85

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading