-
Notifications
You must be signed in to change notification settings - Fork 16
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
Shows e-exprs inside container literals, delimited END #186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ PR Tour 🧭
impl<'a, L: Language + 'static> CodeGenerator<'a, L> { | ||
impl<L: Language + 'static> CodeGenerator<'_, L> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 Clippy suggestion.
let digest_string: String = | ||
digest.iter().map(|b| format!("{:02x?}", b)).collect(); | ||
let digest_string = digest.iter().fold( | ||
String::with_capacity(digest.len() * 2), | ||
|mut string, byte| { | ||
use fmt::Write; | ||
write!(&mut string, "{:02x}", byte).expect("infallible"); | ||
string | ||
}, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 Clippy suggestion.
enum StructKind { | ||
Standard, | ||
SymbolTable, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 This enum allowed me to consolidate the inspect methods for structs with the one for symbol tables. Now the method printing the struct just checks to see if it's a symbol table when it's inspecting a field called 'symbols'.
@@ -336,11 +345,7 @@ impl<'a, 'b> IonInspector<'a, 'b> { | |||
self.inspect_value(0, "", lazy_sexp.as_value(), no_comment())?; | |||
} | |||
Value(lazy_value) => { | |||
if lazy_value.expanded().is_ephemeral() && self.hide_expansion { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 This check is now handled inside inspect_value
so that it applies globally, not just at the top level.
src/bin/ion/commands/inspect.rs
Outdated
style: ColorSpec, | ||
mut style: ColorSpec, | ||
write_fn: impl FnOnce(&mut CommandOutput) -> Result<()>, | ||
) -> Result<()> { | ||
if self.is_inside_ephemeral() { | ||
style = comment_style(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 This overrides the requested color/style whenever we're inspecting an ephemeral value. The net result is that all ephemeral values appear in very muted colors so it's obvious that they're not encoded in the byte stream.
@@ -223,6 +223,8 @@ struct IonInspector<'a, 'b> { | |||
skip_complete: bool, | |||
limit_bytes: usize, | |||
hide_expansion: bool, | |||
ephemeral_depth: usize, | |||
line_has_comment: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 As you'll see later, the inspector now tracks whether a comment has already been opened on the current line of output. This allows multiple bits of "commentor" code to add comments without coordination.
@@ -223,6 +223,8 @@ struct IonInspector<'a, 'b> { | |||
skip_complete: bool, | |||
limit_bytes: usize, | |||
hide_expansion: bool, | |||
ephemeral_depth: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ephemeral values are now grayed out in the output. This tracks the level of traversal depth where the ephemeral value began so we know when to restore color.
// If this item is neither the first nor last in the stream, print a row separator. | ||
write!(self.output, "{ROW_SEPARATOR}")?; | ||
} | ||
|
||
match expr { | ||
EExp(eexp) => { | ||
self.inspect_eexp(0, eexp)?; | ||
self.inspect_eexp(0, "", eexp)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 E-expressions and arg groups now correctly print their trailing delimiter when they appear inside a container.
style: ColorSpec, | ||
write_fn: impl FnOnce(&mut CommandOutput) -> Result<()>, | ||
mut style: ColorSpec, | ||
write_fn: impl FnOnce(&mut Self) -> Result<()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 Passing Self
means that the closure has access to IonInspector
's fields when formatting comments.
@@ -896,6 +1021,35 @@ impl<'a, 'b> IonInspector<'a, 'b> { | |||
self.write_offset_length_and_bytes(depth, range.start, range.len(), &mut formatter) | |||
} | |||
|
|||
fn inspect_literal_container_footer<'x, D: Decoder>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪧 Delimited container END
is now displayed properly.
Depends on the version of
ion-rust
in amazon-ion/ion-rust#885.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.