about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-04-09 13:40:48 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-04-09 13:41:06 +0200
commit295f0c57a5202f9db8924044f155ac4911e5cbfc (patch)
tree5729bf8d47b1aa0fbd302270e0eb681d48941a6f
parent9050db2e80ee0190cc4a6eddc972a5e19bc9f926 (diff)
downloadrust-295f0c57a5202f9db8924044f155ac4911e5cbfc.tar.gz
rust-295f0c57a5202f9db8924044f155ac4911e5cbfc.zip
Revert #11912 as it parses all visited files
-rw-r--r--crates/base_db/src/input.rs4
-rw-r--r--crates/hir/src/lib.rs7
-rw-r--r--crates/ide_db/src/search.rs18
3 files changed, 13 insertions, 16 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index 43d7ccad492..e6d94f1d0dd 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -334,7 +334,7 @@ impl CrateGraph {
 
     /// Returns an iterator over all transitive dependencies of the given crate,
     /// including the crate itself.
-    pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ {
+    pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> {
         let mut worklist = vec![of];
         let mut deps = FxHashSet::default();
 
@@ -351,7 +351,7 @@ impl CrateGraph {
 
     /// Returns all transitive reverse dependencies of the given crate,
     /// including the crate itself.
-    pub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ {
+    pub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> {
         let mut worklist = vec![of];
         let mut rev_deps = FxHashSet::default();
         rev_deps.insert(of);
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 37bb2e1997d..df17b75c05c 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -175,8 +175,11 @@ impl Crate {
             .collect()
     }
 
-    pub fn transitive_reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> {
-        db.crate_graph().transitive_rev_deps(self.id).into_iter().map(|id| Crate { id }).collect()
+    pub fn transitive_reverse_dependencies(
+        self,
+        db: &dyn HirDatabase,
+    ) -> impl Iterator<Item = Crate> {
+        db.crate_graph().transitive_rev_deps(self.id).map(|id| Crate { id })
     }
 
     pub fn root_module(self, db: &dyn HirDatabase) -> Module {
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 63a45aa3efc..4a11fb73cd6 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -102,18 +102,12 @@ impl SearchScope {
     /// Build a search scope spanning all the reverse dependencies of the given crate.
     fn reverse_dependencies(db: &RootDatabase, of: hir::Crate) -> SearchScope {
         let mut entries = FxHashMap::default();
-        let mut insert_modules = |of: hir::Crate| {
-            entries.extend(of.modules(db).into_iter().filter_map(|module| {
-                match module.definition_source(db) {
-                    InFile { file_id, value: ModuleSource::SourceFile(..) } => {
-                        Some((file_id.original_file(db), None))
-                    }
-                    _ => None,
-                }
-            }));
-        };
-        insert_modules(of);
-        of.transitive_reverse_dependencies(db).into_iter().for_each(insert_modules);
+        for rev_dep in of.transitive_reverse_dependencies(db) {
+            let root_file = rev_dep.root_file(db);
+            let source_root_id = db.file_source_root(root_file);
+            let source_root = db.source_root(source_root_id);
+            entries.extend(source_root.iter().map(|id| (id, None)));
+        }
         SearchScope { entries }
     }