forked from tailcallhq/tailcall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grpc): preserve comments from protobuf when generating config (t…
- Loading branch information
1 parent
a4056e8
commit f5bbc19
Showing
11 changed files
with
605 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod from_proto; | ||
mod generator; | ||
mod graphql_type; | ||
mod proto; | ||
mod source; | ||
pub use generator::Generator; | ||
pub use source::Source; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use prost_reflect::prost_types::SourceCodeInfo; | ||
|
||
pub struct CommentsBuilder { | ||
source_code_info: Option<SourceCodeInfo>, | ||
} | ||
|
||
impl CommentsBuilder { | ||
pub fn new(source_code_info: Option<SourceCodeInfo>) -> Self { | ||
Self { source_code_info } | ||
} | ||
|
||
pub fn get_comments(&self, path: &[i32]) -> Option<String> { | ||
self.source_code_info.as_ref().and_then(|info| { | ||
info.location | ||
.iter() | ||
.find(|loc| loc.path == path) | ||
.and_then(|loc| { | ||
loc.leading_comments.as_ref().map(|c| { | ||
c.lines() | ||
.map(|line| line.trim_start_matches('*').trim()) | ||
.filter(|line| !line.is_empty()) | ||
.collect::<Vec<_>>() | ||
.join("\n ") | ||
}) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod comments_builder; | ||
pub mod path_builder; | ||
pub mod path_field; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::path_field::PathField; | ||
|
||
pub struct PathBuilder { | ||
base_path: Vec<i32>, | ||
} | ||
|
||
impl PathBuilder { | ||
pub fn new(base_path: &[i32]) -> Self { | ||
Self { base_path: base_path.to_vec() } | ||
} | ||
|
||
pub fn extend(&self, field: PathField, index: i32) -> Vec<i32> { | ||
let mut extended_path = self.base_path.clone(); | ||
extended_path.push(field.value()); | ||
extended_path.push(index); | ||
extended_path | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pub enum PathField { | ||
EnumType, | ||
MessageType, | ||
Service, | ||
Field, | ||
Method, | ||
EnumValue, | ||
NestedType, | ||
NestedEnum, | ||
} | ||
|
||
impl PathField { | ||
pub fn value(&self) -> i32 { | ||
match self { | ||
PathField::EnumType => 5, | ||
PathField::MessageType => 4, | ||
PathField::Service => 6, | ||
PathField::Field => 2, | ||
PathField::Method => 2, | ||
PathField::EnumValue => 2, | ||
PathField::NestedType => 3, | ||
PathField::NestedEnum => 4, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.