-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: rename and add import #19799
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: rename and add import #19799
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1170,6 +1170,22 @@ impl<'a> FindUsages<'a> { | |||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
fn is_related_import(&self, name_ref: &ast::NameRef) -> bool { | ||||||||||||||||||||||||||||||||||
ast::UseTree::find_tail_use_tree_for_name_ref(name_ref) | ||||||||||||||||||||||||||||||||||
.and_then(|u| u.path()) | ||||||||||||||||||||||||||||||||||
.and_then(|path| self.sema.resolve_path_per_ns(&path)) | ||||||||||||||||||||||||||||||||||
.map(|res| { | ||||||||||||||||||||||||||||||||||
res.to_small_vec() | ||||||||||||||||||||||||||||||||||
.into_iter() | ||||||||||||||||||||||||||||||||||
.filter_map(|res| match res { | ||||||||||||||||||||||||||||||||||
Some(PathResolution::Def(def)) => Some(Definition::from(def)), | ||||||||||||||||||||||||||||||||||
_ => None, | ||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||
.any(|def| def == self.def) | ||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||
== Some(true) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
fn found_name_ref( | ||||||||||||||||||||||||||||||||||
&self, | ||||||||||||||||||||||||||||||||||
name_ref: &ast::NameRef, | ||||||||||||||||||||||||||||||||||
|
@@ -1180,7 +1196,8 @@ impl<'a> FindUsages<'a> { | |||||||||||||||||||||||||||||||||
if self.def == def | ||||||||||||||||||||||||||||||||||
// is our def a trait assoc item? then we want to find all assoc items from trait impls of our trait | ||||||||||||||||||||||||||||||||||
|| matches!(self.assoc_item_container, Some(hir::AssocItemContainer::Trait(_))) | ||||||||||||||||||||||||||||||||||
&& convert_to_def_in_trait(self.sema.db, def) == self.def => | ||||||||||||||||||||||||||||||||||
&& convert_to_def_in_trait(self.sema.db, def) == self.def | ||||||||||||||||||||||||||||||||||
|| self.is_related_import(name_ref) => | ||||||||||||||||||||||||||||||||||
Comment on lines
1196
to
+1200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I find some definition item, we use NameRefClass::classify but it only return single definition. So, I check use block have some definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change give affect to this test rust-analyzer/crates/ide/src/references.rs Lines 1765 to 1780 in d2a05af
|
||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax()); | ||||||||||||||||||||||||||||||||||
let reference = FileReference { | ||||||||||||||||||||||||||||||||||
|
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.
When we rename import item, We check that the path is ambiguous or not. if It is ambiguous, we add old import name and new name.