diff options
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/defs.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/helpers.rs | 28 | ||||
-rw-r--r-- | crates/ide_db/src/search.rs | 16 |
3 files changed, 44 insertions, 2 deletions
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index ff612b7d0..f86e5ce93 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -70,7 +70,7 @@ impl Definition { | |||
70 | hir::ModuleDef::Static(it) => it.name(db)?, | 70 | hir::ModuleDef::Static(it) => it.name(db)?, |
71 | hir::ModuleDef::Trait(it) => it.name(db), | 71 | hir::ModuleDef::Trait(it) => it.name(db), |
72 | hir::ModuleDef::TypeAlias(it) => it.name(db), | 72 | hir::ModuleDef::TypeAlias(it) => it.name(db), |
73 | hir::ModuleDef::BuiltinType(_) => return None, | 73 | hir::ModuleDef::BuiltinType(it) => it.name(), |
74 | }, | 74 | }, |
75 | Definition::SelfType(_) => return None, | 75 | Definition::SelfType(_) => return None, |
76 | Definition::Local(it) => it.name(db)?, | 76 | Definition::Local(it) => it.name(db)?, |
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index 3c95d3cff..9992a92bd 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs | |||
@@ -2,6 +2,10 @@ | |||
2 | pub mod insert_use; | 2 | pub mod insert_use; |
3 | pub mod import_assets; | 3 | pub mod import_assets; |
4 | 4 | ||
5 | use std::collections::VecDeque; | ||
6 | |||
7 | use base_db::FileId; | ||
8 | use either::Either; | ||
5 | use hir::{Crate, Enum, ItemInNs, MacroDef, Module, ModuleDef, Name, ScopeDef, Semantics, Trait}; | 9 | use hir::{Crate, Enum, ItemInNs, MacroDef, Module, ModuleDef, Name, ScopeDef, Semantics, Trait}; |
6 | use syntax::ast::{self, make}; | 10 | use syntax::ast::{self, make}; |
7 | 11 | ||
@@ -39,6 +43,30 @@ pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path { | |||
39 | make::path_from_segments(segments, is_abs) | 43 | make::path_from_segments(segments, is_abs) |
40 | } | 44 | } |
41 | 45 | ||
46 | /// Iterates all `ModuleDef`s and `Impl` blocks of the given file. | ||
47 | pub fn visit_file_defs( | ||
48 | sema: &Semantics<RootDatabase>, | ||
49 | file_id: FileId, | ||
50 | cb: &mut dyn FnMut(Either<hir::ModuleDef, hir::Impl>), | ||
51 | ) { | ||
52 | let db = sema.db; | ||
53 | let module = match sema.to_module_def(file_id) { | ||
54 | Some(it) => it, | ||
55 | None => return, | ||
56 | }; | ||
57 | let mut defs: VecDeque<_> = module.declarations(db).into(); | ||
58 | while let Some(def) = defs.pop_front() { | ||
59 | if let ModuleDef::Module(submodule) = def { | ||
60 | if let hir::ModuleSource::Module(_) = submodule.definition_source(db).value { | ||
61 | defs.extend(submodule.declarations(db)); | ||
62 | submodule.impl_defs(db).into_iter().for_each(|impl_| cb(Either::Right(impl_))); | ||
63 | } | ||
64 | } | ||
65 | cb(Either::Left(def)); | ||
66 | } | ||
67 | module.impl_defs(db).into_iter().for_each(|impl_| cb(Either::Right(impl_))); | ||
68 | } | ||
69 | |||
42 | /// Helps with finding well-know things inside the standard library. This is | 70 | /// Helps with finding well-know things inside the standard library. This is |
43 | /// somewhat similar to the known paths infra inside hir, but it different; We | 71 | /// somewhat similar to the known paths infra inside hir, but it different; We |
44 | /// want to make sure that IDE specific paths don't become interesting inside | 72 | /// want to make sure that IDE specific paths don't become interesting inside |
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index fa18703e1..d00a8b6e7 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | use std::{convert::TryInto, mem}; | 7 | use std::{convert::TryInto, mem}; |
8 | 8 | ||
9 | use base_db::{FileId, FileRange, SourceDatabaseExt}; | 9 | use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt}; |
10 | use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; | 10 | use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; |
11 | use once_cell::unsync::Lazy; | 11 | use once_cell::unsync::Lazy; |
12 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
@@ -138,6 +138,20 @@ impl IntoIterator for SearchScope { | |||
138 | impl Definition { | 138 | impl Definition { |
139 | fn search_scope(&self, db: &RootDatabase) -> SearchScope { | 139 | fn search_scope(&self, db: &RootDatabase) -> SearchScope { |
140 | let _p = profile::span("search_scope"); | 140 | let _p = profile::span("search_scope"); |
141 | |||
142 | if let Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)) = self { | ||
143 | let mut res = FxHashMap::default(); | ||
144 | |||
145 | let graph = db.crate_graph(); | ||
146 | for krate in graph.iter() { | ||
147 | let root_file = graph[krate].root_file_id; | ||
148 | let source_root_id = db.file_source_root(root_file); | ||
149 | let source_root = db.source_root(source_root_id); | ||
150 | res.extend(source_root.iter().map(|id| (id, None))); | ||
151 | } | ||
152 | return SearchScope::new(res); | ||
153 | } | ||
154 | |||
141 | let module = match self.module(db) { | 155 | let module = match self.module(db) { |
142 | Some(it) => it, | 156 | Some(it) => it, |
143 | None => return SearchScope::empty(), | 157 | None => return SearchScope::empty(), |