-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: ide-assists, gen from impl for enum indent #19789
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
base: master
Are you sure you want to change the base?
fix: ide-assists, gen from impl for enum indent #19789
Conversation
let level = indent_level.0 as usize; | ||
|
||
let indent = indent_level.to_string(); | ||
let mut buf = String::with_capacity(s.len() + level * 3 * 4); |
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.
what are the values (3 and 4) here?
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.
- 4 is the number of spaces for indent
- 3 is an approximate expected number of lines used for optimization
crates/ide-assists/src/utils.rs
Outdated
buf.push_str(line); | ||
buf.push('\n'); | ||
|
||
if !rest.split_once('\n').map_or(rest, |s| s.0).is_empty() { |
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.
can you pull out the split_once
/map_or
into a separate statement? it makes it a bit tricky to understand what the condition here actually is.
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.
Ok
@@ -250,6 +252,36 @@ pub fn add_trait_assoc_items_to_impl( | |||
first_item.unwrap() | |||
} | |||
|
|||
pub(crate) fn indent_string(mut s: &str, indent_level: IndentLevel) -> Cow<'_, str> { |
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 is the wrong kind of API here, we already have indentation things that work on the AST. If those don't suffice this will have to wait until we have our own formatter to pretty print nodes with. Our assist output is currently best effort due to the lack of that
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.
Currently, many ide-assists directly generate strings. With this API, I can quickly fix nearly ten ide-assists implements
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.
Can we keep this API and continue?
Old output:
Fixed output: