-
Notifications
You must be signed in to change notification settings - Fork 529
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
updated max depth for multi + crate & super #6912
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.
Reviewed all commit messages.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @dean-starkware and @gilbens-starkware)
crates/cairo-lang-formatter/src/formatter_impl.rs
line 117 at r1 (raw file):
(nested_paths, false) }
Suggestion:
/// Merge and organize the `use` paths in a hierarchical structure.
pub fn create_merged_use_items(
self,
allow_duplicate_uses: bool,
top_level: bool,
) -> (Vec<String>, bool) {
let leaf_paths = self
.leaves
.into_iter()
.map(|leaf| {
if let Some(alias) = leaf.alias {
format!("{} as {alias}", leaf.name)
} else {
leaf.name
}
})
.collect_vec();
let mut nested_paths = vec![];
for (segment, subtree) in self.children {
let next_depth = current_depth + 1;
let subtree_merged_use_items =
subtree.create_merged_use_items(allow_duplicate_uses, next_depth, false);
nested_paths.extend(subtree_merged_use_items.into_iter().map(|child| format!("{segment}::{child}")));
if is_single_leaf && next_depth >= MAX_DEPTH_FOR_MULTI {
leaf_paths.extend(formatted_subtree_paths);
} else {
formatted_subtree_paths);
}
}
if !allow_duplicate_uses {
leaf_paths.sort();
leaf_paths.dedup();
}
match leaf_paths.len() {
0 => {}
1 if nested_paths.is_empty() => return (leaf_paths, true),
1 => nested_paths.extend(leaf_paths),
_ if top_level => nested_paths.extend(leaf_paths),
_ => nested_paths.push(format!("{{{}}}", leaf_paths.join(", "))),
}
(nested_paths, false)
}
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.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @dean-starkware and @gilbens-starkware)
crates/cairo-lang-formatter/src/formatter_impl.rs
line 117 at r1 (raw file):
(nested_paths, false) }
Suggestion:
/// Merge and organize the `use` paths in a hierarchical structure.
pub fn create_merged_use_items(
self,
allow_duplicate_uses: bool,
top_level: bool,
) -> Vec<String> {
let leaf_paths = self
.leaves
.into_iter()
.map(|leaf| {
if let Some(alias) = leaf.alias {
format!("{} as {alias}", leaf.name)
} else {
leaf.name
}
})
.collect_vec();
let mut nested_paths = vec![];
for (segment, subtree) in self.children {
let next_depth = current_depth + 1;
let subtree_merged_use_items =
subtree.create_merged_use_items(allow_duplicate_uses, next_depth, false);
nested_paths.extend(subtree_merged_use_items.into_iter().map(|child| format!("{segment}::{child}")));
if is_single_leaf && next_depth >= MAX_DEPTH_FOR_MULTI {
leaf_paths.extend(formatted_subtree_paths);
} else {
formatted_subtree_paths);
}
}
if !allow_duplicate_uses {
leaf_paths.sort();
leaf_paths.dedup();
}
match leaf_paths.len() {
0 => {}
1 if nested_paths.is_empty() => return leaf_paths,
1 => nested_paths.extend(leaf_paths),
_ if top_level => nested_paths.extend(leaf_paths),
_ => nested_paths.push(format!("{{{}}}", leaf_paths.join(", "))),
}
nested_paths
}
813d577
to
cfe1d57
Compare
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.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @gilbens-starkware and @orizi)
crates/cairo-lang-formatter/src/formatter_impl.rs
line 117 at r1 (raw file):
(nested_paths, false) }
leaf_paths must be mut.
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.
Reviewed 4 of 5 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @gilbens-starkware)
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.
Reviewed all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @gilbens-starkware)
This PR addresses the formatting of crate and super and limits the allowed depth of chaining in UsePathMulti.
Please note:
Unlike Rust, we do not insert a blank line between the "regular" use statements and crate & super.