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

Migrate sort_items Assist to Use SyntaxFactory #18538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tareknaser
Copy link
Contributor

part of #15710 and #18285
For this one, I had to pass AssistContext to other methods as well in order to get the file ID.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 20, 2024
Copy link
Contributor

@darichey darichey left a comment

Choose a reason for hiding this comment

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

Mostly looks good, a couple opportunities for simplification.

Not for this PR, but after doing a few of these, it looks like there may be potential for a slightly nicer api that takes care of some things for us. Something like:

fn add_with_editor(
    &mut self,
    id: AssistId,
    label: impl Into<String>,
    target: SyntaxNode,
    f: impl FnOnce(&mut SyntaxEditor, &SyntaxFactory),
) -> Option<()>

label: &str,
old: Vec<T>,
new: Vec<T>,
target: TextRange,
) -> Option<()> {
let node = old.first().unwrap().syntax().parent().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Try instead modifying add_rewrite to accept target: SyntaxNode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.
But, Assists::add actually accepts TextRange as a parameter, so I had to use target.text_range() for that. Let me know if this works better.

crates/ide-assists/src/handlers/sort_items.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants