-
Notifications
You must be signed in to change notification settings - Fork 653
Conversation
Deploying with
|
Latest commit: |
847b802
|
Status: | ✅ Deploy successful! |
Preview URL: | https://553abfca.tools-8rn.pages.dev |
Branch Preview URL: | https://feature-rename-batch-mutatio.tools-8rn.pages.dev |
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
Could our LSP rename handle the case that reference across the file? |
Not yet, but it will. |
if scope | ||
.ancestors() | ||
.filter_map(|scope| scope.get_binding(new_name)) | ||
.next() | ||
.is_some() | ||
{ |
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.
Unrelated to the PR itself but I was surprised to learn that scope.get_binding(new_name)
only checks the current scope but not the parent scopes as well to retrieve any binding with that name.
I think, ideally, scope.get_binding(new_name)
should check the whole ancestor chain to see if there's any binding with the given name but scope
can have a scope.get_own_binding(new_name)
method that only checks the current scope. That would most closely match my expectations of get_binding
.
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.
I have no problem with this approach, but as soon as we start adding more methods, we will need to keep consistency: "all_reads", "all_writes", "all_references" etc... will also navigate upwards. Which means we will end up with two sets of methods.
And in the end .ancestors().filter_map(...)
solves the problem.
.node() | ||
.clone() | ||
.cast::<JsIdentifierAssignment>() |
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 last clone should not be necessary if you use all_references.into_iter()
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.
I still need it because Reference::node(...)
returns a borrow.
But I indeed can consume the all_references
.
} | ||
} | ||
|
||
// Now it is safe to pish changes to the batch mutation |
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.
pish -> push?
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.
ops... and "pish" is not a nice word! 😄
crates/rome_js_analyze/src/utils.rs
Outdated
#[cfg(test)] | ||
pub mod tests; | ||
|
||
#[macro_export] |
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.
Is it possible to limit these test helpers to test builds only or is this something Rust doesn't support?
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 was annoying me also. I think I managed to improve it.
@@ -56,6 +56,18 @@ struct SemanticModelData { | |||
} | |||
|
|||
impl SemanticModelData { | |||
pub fn scope(&self, range: &TextRange) -> usize { |
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.
Nit: No pub
as this is an internal type?
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.
Done.
@@ -122,6 +122,24 @@ where | |||
}); | |||
} | |||
|
|||
pub fn replace_token(&mut self, prev_token: SyntaxToken<L>, next_token: SyntaxToken<L>) { |
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 add some documentation to these new public methods?
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.
Done.
match node.try_into() { | ||
Ok(node) => { | ||
let mut batch = root.begin(); | ||
batch.rename_with_any_can_be_renamed(&model, node, &new_name); |
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.
Should we return an error if the renaming fails in case new_name
is already used?
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.
I found that vscode will not emit an error when the new name is already used.
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.
Yes, we should. Done.
I think we should add an option like |
I had to disable the built-in to test ours. I will research later if there is another option. |
Given that this changed the LSP, I would include it in the change log of #2835 |
Summary
This PR is the first step to implementing #2903.
It introduces an
rename
extension method to theBatchMutation
.I still need to understand what to do when the cursor is not at a symbol.
Test Plan
or directly using the lsp.