aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/search.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 891b8cf0a..d8abef491 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -318,7 +318,7 @@ pub struct FindUsages<'a> {
318impl<'a> FindUsages<'a> { 318impl<'a> FindUsages<'a> {
319 /// Enable searching for `Self` when the definition is a type. 319 /// Enable searching for `Self` when the definition is a type.
320 pub fn include_self_refs(mut self) -> FindUsages<'a> { 320 pub fn include_self_refs(mut self) -> FindUsages<'a> {
321 self.include_self_kw_refs = def_to_ty(self.sema.db, self.def); 321 self.include_self_kw_refs = def_to_ty(self.sema, self.def);
322 self 322 self
323 } 323 }
324 324
@@ -474,7 +474,7 @@ impl<'a> FindUsages<'a> {
474 sink(file_id, reference) 474 sink(file_id, reference)
475 } 475 }
476 Some(NameRefClass::Definition(def)) if self.include_self_kw_refs.is_some() => { 476 Some(NameRefClass::Definition(def)) if self.include_self_kw_refs.is_some() => {
477 if self.include_self_kw_refs == def_to_ty(self.sema.db, &def) { 477 if self.include_self_kw_refs == def_to_ty(self.sema, &def) {
478 let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax()); 478 let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
479 let reference = FileReference { 479 let reference = FileReference {
480 range, 480 range,
@@ -536,16 +536,22 @@ impl<'a> FindUsages<'a> {
536 } 536 }
537} 537}
538 538
539fn def_to_ty(db: &RootDatabase, def: &Definition) -> Option<hir::Type> { 539fn def_to_ty(sema: &Semantics<RootDatabase>, def: &Definition) -> Option<hir::Type> {
540 match def { 540 match def {
541 Definition::ModuleDef(def) => match def { 541 Definition::ModuleDef(def) => match def {
542 ModuleDef::Adt(adt) => Some(adt.ty(db)), 542 ModuleDef::Adt(adt) => Some(adt.ty(sema.db)),
543 ModuleDef::TypeAlias(it) => Some(it.ty(db)), 543 ModuleDef::TypeAlias(it) => Some(it.ty(sema.db)),
544 ModuleDef::BuiltinType(_it) => None, // FIXME somehow acquire some module to construct the builtin type 544 ModuleDef::BuiltinType(it) => {
545 ModuleDef::Trait(_it) => None, // FIXME turn trait into its self-type 545 let graph = sema.db.crate_graph();
546 let krate = graph.iter().next()?;
547 let root_file = graph[krate].root_file_id;
548 let module = sema.to_module_def(root_file)?;
549 Some(it.ty(sema.db, module))
550 }
551 ModuleDef::Trait(_it) => None, // FIXME turn trait into its self-type
546 _ => None, 552 _ => None,
547 }, 553 },
548 Definition::SelfType(it) => Some(it.self_ty(db)), 554 Definition::SelfType(it) => Some(it.self_ty(sema.db)),
549 _ => None, 555 _ => None,
550 } 556 }
551} 557}