fix(assists/add_reference_here): _modify_ the reference type when dealing with &T->&mut T#22342
Conversation
This comment has been minimized.
This comment has been minimized.
910f6cb to
fdfffdb
Compare
This comment has been minimized.
This comment has been minimized.
| let expr = expr_ptr.to_node(ctx.db()); | ||
| // If the node comes from a macro expansion, then we shouldn't assist, | ||
| // as the suggestion would overwrite the macro _definition_ position | ||
| let expr = ctx.sema.original_ast_node(expr)?; | ||
| let expr_without_ref = RefExpr::cast(expr.syntax().clone())?.expr()?; | ||
|
|
||
| let pos = expr_without_ref.syntax().text_range().start(); | ||
| let edit = TextEdit::insert(pos, "mut ".to_string()); | ||
| let source_change = SourceChange::from_text_edit(range.file_id, edit); |
There was a problem hiding this comment.
I initially wanted to do this with SyntaxEditor, but it looks like a text edit works just fine... Let me know which one I should go with.
There was a problem hiding this comment.
SyntaxEditor would likely be better in the future, but this is fine for now
There was a problem hiding this comment.
I had actually implemented it with SyntaxEditor initially, see the second commit.. I'll open a PR which switches to that then (EDIT: done, see #22467)
a66b485 to
4e6676e
Compare
This comment has been minimized.
This comment has been minimized.
- use `ctx.db()` - move `add_mutable_reference_to_let_stmt` closer to `add_reference_to_let_stmt`
…ling with &T->&mut T ..instead of adding another layer of reference, i.e. &T -> &mut &T Co-authored-by: Ana Hobden <operator@hoverbear.org>
4e6676e to
05bc639
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| let expr = expr_ptr.to_node(ctx.db()); | ||
| // If the node comes from a macro expansion, then we shouldn't assist, | ||
| // as the suggestion would overwrite the macro _definition_ position | ||
| let expr = ctx.sema.original_ast_node(expr)?; | ||
| let expr_without_ref = RefExpr::cast(expr.syntax().clone())?.expr()?; | ||
|
|
||
| let pos = expr_without_ref.syntax().text_range().start(); | ||
| let edit = TextEdit::insert(pos, "mut ".to_string()); | ||
| let source_change = SourceChange::from_text_edit(range.file_id, edit); |
There was a problem hiding this comment.
SyntaxEditor would likely be better in the future, but this is fine for now
..instead of adding another layer of reference, i.e. &T -> &mut &T
Fixes #13047