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

fix: remove parenthesis should ensure space #15857

Merged
merged 2 commits into from Nov 27, 2023
Merged

Conversation

Young-Flash
Copy link
Member

close #15844

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 9, 2023
@Young-Flash
Copy link
Member Author

Young-Flash commented Nov 15, 2023

Can anyone help review this?

cc @lnicola @Veykril

Comment on lines 37 to 50
// we should use `find_node_at_offset` at `SourceFile` level to get expectant `Between`
let token_at_offset = ctx
.find_node_at_offset::<ast::SourceFile>()?
.syntax()
.token_at_offset(parens.syntax().text_range().start());
let need_to_add_ws = match token_at_offset {
syntax::TokenAtOffset::Between(before, _after) => {
// anyother `SyntaxKind` we missing here?
let tokens = vec![T![&], T![!], T!['('], T!['['], T!['{']];
before.kind() != SyntaxKind::WHITESPACE && !tokens.contains(&before.kind())
}
_ => false,
};
let expr = if need_to_add_ws { format!(" {}", expr) } else { expr.to_string() };
Copy link
Member

@Veykril Veykril Nov 21, 2023

Choose a reason for hiding this comment

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

Two things, first this "analysis" should go into the |builder| closure so its only executed if the user makes use of the assist (for perf reasons).

Second, we can do this simpler, we can just take the preceding token of the expression via expr.syntax().first_token().and_then(|it| it.prev_token()) and check that for whitespace, if its not a whitespace token we should insert one.

As usual, ideally we'd have a formatter that just generally formats our outputs but thats a far future thing

Copy link
Member

@Veykril Veykril Nov 21, 2023

Choose a reason for hiding this comment

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

Ah seeing the commented out tests I just realized I was tunnel visioning on the match(1+1) thing, my approach doesnt generally work for other stuff I suppose hmm ... Oh or did you forget to uncomment the tests again? Since you d ospecial case things in way that should work there ithink

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I forgot to uncomment them after debug. Your approach works well over all the tests 👍

@Young-Flash
Copy link
Member Author

@Veykril could you please review it again when you have time?

@Veykril
Copy link
Member

Veykril commented Nov 27, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 27, 2023

📌 Commit bd5a63b has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Nov 27, 2023

⌛ Testing commit bd5a63b with merge 4ab6729...

@bors
Copy link
Collaborator

bors commented Nov 27, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 4ab6729 to master...

@bors bors merged commit 4ab6729 into rust-lang:master Nov 27, 2023
10 checks passed
@Young-Flash Young-Flash deleted the fix branch November 28, 2023 01:18
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.

Remove parenthesis should ensure space
4 participants