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

Shows e-exprs inside container literals, delimited END #186

Merged
merged 5 commits into from
Jan 10, 2025
Merged

Conversation

zslayton
Copy link
Contributor

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.

Copy link
Contributor Author

@zslayton zslayton left a 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> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪧 Clippy suggestion.

Comment on lines -112 to +120
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
},
);
Copy link
Contributor Author

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,
}
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

Comment on lines 396 to 406
style: ColorSpec,
mut style: ColorSpec,
write_fn: impl FnOnce(&mut CommandOutput) -> Result<()>,
) -> Result<()> {
if self.is_inside_ephemeral() {
style = comment_style();
}
Copy link
Contributor Author

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,
Copy link
Contributor Author

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,
Copy link
Contributor Author

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)?;
Copy link
Contributor Author

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<()>,
Copy link
Contributor Author

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>(
Copy link
Contributor Author

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.

@zslayton zslayton marked this pull request as ready for review January 9, 2025 21:34
@zslayton zslayton merged commit 4c8b913 into main Jan 10, 2025
4 checks passed
@zslayton zslayton deleted the update-inspect branch January 10, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants