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

Transition to quote + syn for code generation. #1026

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9486be6
prost-build: DRY up codegen with `resolve_prost_path`
gibbz00 Mar 30, 2024
2c444cf
prost_build: `BytesType and MapType` into a `collections` module.
gibbz00 Mar 31, 2024
1a1cd57
prost-build: Begin experimenting with using `quote!` + `syn`:
gibbz00 Mar 31, 2024
a62f90a
prost_build: place `EnumVariantMapping` inside a module.
gibbz00 Mar 31, 2024
97befa2
prost_build: minor `append_doc` rephrasing.
gibbz00 Mar 31, 2024
74fd774
prost_build: `location` -> `comments_from_location`:
gibbz00 Mar 31, 2024
ffd9a0e
prost_build: Temporarily remove `push_indent`:
gibbz00 Mar 31, 2024
4cc8e24
prost_build: Minor boxed string rephrasing.
gibbz00 Mar 31, 2024
148dee1
prost_build: Inline `deprecated` in codegen.
gibbz00 Mar 31, 2024
fb06be3
prost_build: Convert _type if else chain to a match statement.
gibbz00 Mar 31, 2024
6d87d7f
prost_build: Introduce a typeset `FullyQualifiedName`:
gibbz00 Apr 6, 2024
1faf874
prost_build: attributes with `quote` in `append_enum`
gibbz00 Apr 6, 2024
84c4d08
prost_build: generate enum variants with `syn` and `quote`
gibbz00 Apr 6, 2024
4c3c3f2
prost_build: use quote for the remaining parsts of `append_enum`
gibbz00 Apr 6, 2024
8dfed57
prost_build: rename `to_upper_camel_syn` to `to_syn_ident`
gibbz00 Apr 6, 2024
58843dd
prost_build: deprecate `append_enum_attributes`
gibbz00 Apr 6, 2024
379c64a
prost_build: deprecate `append_skip_debug`
gibbz00 Apr 6, 2024
e1212c2
prost_build: use `resolve_docs` in `append_oneof`
gibbz00 Apr 6, 2024
ef547e9
prost_build: oneof enum variants with `quote` + `syn`
gibbz00 Apr 6, 2024
6f114df
prost_build: use `matches!` for protobuf type checking
gibbz00 Apr 6, 2024
b0136dd
prost_build: clarify oneof type variables
gibbz00 Apr 6, 2024
8a07823
prost_build: reordes oneof_variants variables:
gibbz00 Apr 6, 2024
4b68780
prost_build: inline append_message_attributes
gibbz00 Apr 6, 2024
f0276bb
prost_build: use `resolve_docs` in `append_message`
gibbz00 Apr 6, 2024
c753237
prost_build: consolidate boxing checking into `should_box_field`
gibbz00 Apr 7, 2024
c0bd3f9
prost_build: begin using `quote` + `syn` in `append_map_field`
gibbz00 Apr 7, 2024
476c8b0
prost_build: complete `quote` + `syn` in `append_map_field`
gibbz00 Apr 7, 2024
4d07055
prost_build: complete `quote` + `syn` in `append_oneof_field`
gibbz00 Apr 7, 2024
e524dfe
prost_build: deprecate `append_doc`
gibbz00 Apr 7, 2024
bfa5e9a
prost_build: insert deprecated attribute with quote in `append_field`
gibbz00 Apr 7, 2024
67b4f50
prost_build: avoid relying on debug output for string quotation
gibbz00 Apr 7, 2024
9571d58
prost_build: begin using `quote` + `syn` for `append_field` attributes
gibbz00 Apr 13, 2024
ed25a75
prost_build: deprecate `append_field_attributes`
gibbz00 Apr 13, 2024
7a8e6a5
prost_build: use `quote` + `syn` for remainder of `append_field`
gibbz00 Apr 13, 2024
22df9f0
prost_build: continued transition of using `TokenStream` returns
gibbz00 Apr 13, 2024
9e87a77
prost_build: define message struct `quote`
gibbz00 Apr 13, 2024
8495efa
prost_build: separate nested declaration generation
gibbz00 Apr 13, 2024
b9b9cfe
prost_build: continued transition of using `TokenStream` returns
gibbz00 Apr 13, 2024
7e2dc5f
prost_build: separate `Codegen` constructor
gibbz00 Apr 13, 2024
376bffa
prost_build: split out message, enum and service generation in generate
gibbz00 Apr 13, 2024
2e45a69
prost_build: move service generation into a `services` module
gibbz00 Apr 14, 2024
9a73501
prost_build: begin moving enum generation into a `enums` module
gibbz00 Apr 14, 2024
05130de
prost_build: extract `services` and `enums` modules to separate files:
gibbz00 Apr 14, 2024
b11998f
prost_build: `impl From<Option<&str>> for Syntax`
gibbz00 Apr 14, 2024
cf1291a
prost_build: place `Syntax` in an extracted module
gibbz00 Apr 14, 2024
3d9c8f5
prost_build: move `EnumVariantMapping` to `enums.rs`
gibbz00 Apr 14, 2024
41d4500
prost_build: extract methods `oneof` and `messages` modules
gibbz00 Apr 14, 2024
b27c54f
prost_build: move message helpers to the respective module
gibbz00 Apr 14, 2024
8ab2a34
prost_build: move message type aliases to the respective module
gibbz00 Apr 14, 2024
8f3432a
prost-build: Begin replacing location magic numbers with consts.
gibbz00 Apr 14, 2024
53e4876
prost-build: move nested enums generation to `messages` module
gibbz00 Apr 14, 2024
daa75f0
prost-build: add `DescriptorLocations::ENUM_TYPE`
gibbz00 Apr 14, 2024
e96f4d5
prost-build: add `EnumDescriptorLocations::VALUE`
gibbz00 Apr 14, 2024
618c985
prost-build: add `DescriptorLocations::NESTED_TYPE`
gibbz00 Apr 14, 2024
e30102b
prost-build: add `ServiceDescriptorProtoLocations::METHOD`
gibbz00 Apr 19, 2024
5695061
prost-build: add `DescriptorLocations::ONEOF_DECL`
gibbz00 Apr 19, 2024
1535c74
prost-build: add `DescriptorLocations::FIELD`
gibbz00 Apr 19, 2024
5d4978b
prost-build: extract `locations` module a separate file
gibbz00 Apr 19, 2024
2f1d686
prost-build: add `SynHelpers.parse_syn`
gibbz00 Apr 20, 2024
a176f13
prost-build: add `SynHelpers.parse_outer_attributes`
gibbz00 Apr 20, 2024
6ca1b9a
prost-build: use `parse_syn()` over `syn::parse_str::<syn::Arm>`
gibbz00 Apr 20, 2024
b75f7a8
prost-build: replace `parse_syn()` with remaining `syn::parse_str`
gibbz00 Apr 20, 2024
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
7 changes: 5 additions & 2 deletions prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rust-version = "1.70"

[features]
default = ["format"]
format = ["dep:prettyplease", "dep:syn"]
format = ["dep:prettyplease"]
cleanup-markdown = ["dep:pulldown-cmark", "dep:pulldown-cmark-to-cmark"]

[dependencies]
Expand All @@ -27,18 +27,21 @@ itertools = { version = ">=0.10, <=0.12", default-features = false, features = [
log = "0.4.4"
multimap = { version = ">=0.8, <=0.10", default-features = false }
petgraph = { version = "0.6", default-features = false }
proc-macro2 = "1"
prost = { version = "0.12.4", path = "..", default-features = false }
prost-types = { version = "0.12.4", path = "../prost-types", default-features = false }
quote = "1"
syn = { version = "2", features = ["full", "extra-traits"] }
tempfile = "3"
once_cell = "1.17.1"
regex = { version = "1.8.1", default-features = false, features = ["std", "unicode-bool"] }

prettyplease = { version = "0.2", optional = true }
syn = { version = "2", features = ["full"], optional = true }

# These two must be kept in sync, used for `cleanup-markdown` feature.
pulldown-cmark = { version = "0.9.1", optional = true, default-features = false }
pulldown-cmark-to-cmark = { version = "10.0.1", optional = true }

[dev-dependencies]
env_logger = { version = "0.10", default-features = false }
pretty_assertions = "1"
20 changes: 4 additions & 16 deletions prost-build/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ impl Comments {
/// Appends the comments to a buffer with indentation.
///
/// Each level of indentation corresponds to four space (' ') characters.
pub fn append_with_indent(&self, indent_level: u8, buf: &mut String) {
pub fn append_with_indent(&self, buf: &mut String) {
// Append blocks of detached comments.
for detached_block in &self.leading_detached {
for line in detached_block {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("//");
buf.push_str(&Self::sanitize_line(line));
buf.push('\n');
Expand All @@ -58,27 +55,18 @@ impl Comments {

// Append leading comments.
for line in &self.leading {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("///");
buf.push_str(&Self::sanitize_line(line));
buf.push('\n');
}

// Append an empty comment line if there are leading and trailing comments.
if !self.leading.is_empty() && !self.trailing.is_empty() {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("///\n");
}

// Append trailing comments.
for line in &self.trailing {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("///");
buf.push_str(&Self::sanitize_line(line));
buf.push('\n');
Expand Down Expand Up @@ -262,7 +250,7 @@ mod tests {
};

let mut actual = "".to_string();
input.append_with_indent(0, &mut actual);
input.append_with_indent(&mut actual);

assert_eq!(t.expected, actual, "failed {}", t.name);
}
Expand Down Expand Up @@ -306,7 +294,7 @@ mod tests {
};

let mut actual = "".to_string();
input.append_with_indent(0, &mut actual);
input.append_with_indent(&mut actual);

assert_eq!(t.expected, actual, "failed {}", t.name);
}
Expand Down Expand Up @@ -400,7 +388,7 @@ mod tests {
};

let mut actual = "".to_string();
input.append_with_indent(0, &mut actual);
input.append_with_indent(&mut actual);

assert_eq!(t.expected, actual, "failed {}", t.name);
}
Expand Down
Loading
Loading