From 4aa60529546883a70480e892c417b46cceb4ecdc Mon Sep 17 00:00:00 2001 From: Jinwei Date: Fri, 16 Feb 2024 01:47:42 +0800 Subject: [PATCH] feat: add enable_type_names (#85) * 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 Co-authored-by: Marcus Griep --- CHANGELOG.md | 6 ++++++ example/build-with-buf/buf.gen.yaml | 1 + protoc-gen-prost/README.md | 1 + protoc-gen-prost/src/lib.rs | 20 +++++++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f4824..f5cff6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example/build-with-buf/buf.gen.yaml b/example/build-with-buf/buf.gen.yaml index 83ddc38..0eb08c4 100644 --- a/example/build-with-buf/buf.gen.yaml +++ b/example/build-with-buf/buf.gen.yaml @@ -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 diff --git a/protoc-gen-prost/README.md b/protoc-gen-prost/README.md index d9be595..9c2101a 100644 --- a/protoc-gen-prost/README.md +++ b/protoc-gen-prost/README.md @@ -39,6 +39,7 @@ from that crate: * `retain_enum_prefix(=)`: [retain_enum_prefix](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.retain_enum_prefix) * `field_attribute==`: [field_attribute](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.field_attribute) * `type_attribute==`: [type_attribute](https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.type_attribute) +* `enable_type_names(=)`: [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: diff --git a/protoc-gen-prost/src/lib.rs b/protoc-gen-prost/src/lib.rs index 2098949..3927a87 100644 --- a/protoc-gen-prost/src/lib.rs +++ b/protoc-gen-prost/src/lib.rs @@ -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 { @@ -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 } @@ -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), } @@ -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", },