diff options
Diffstat (limited to 'crates/ide_db/src/search.rs')
-rw-r--r-- | crates/ide_db/src/search.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index ddcfbd3f3..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; |
@@ -86,6 +86,10 @@ impl SearchScope { | |||
86 | SearchScope::new(std::iter::once((file, None)).collect()) | 86 | SearchScope::new(std::iter::once((file, None)).collect()) |
87 | } | 87 | } |
88 | 88 | ||
89 | pub fn file_range(range: FileRange) -> SearchScope { | ||
90 | SearchScope::new(std::iter::once((range.file_id, Some(range.range))).collect()) | ||
91 | } | ||
92 | |||
89 | pub fn files(files: &[FileId]) -> SearchScope { | 93 | pub fn files(files: &[FileId]) -> SearchScope { |
90 | SearchScope::new(files.iter().map(|f| (*f, None)).collect()) | 94 | SearchScope::new(files.iter().map(|f| (*f, None)).collect()) |
91 | } | 95 | } |
@@ -134,6 +138,20 @@ impl IntoIterator for SearchScope { | |||
134 | impl Definition { | 138 | impl Definition { |
135 | fn search_scope(&self, db: &RootDatabase) -> SearchScope { | 139 | fn search_scope(&self, db: &RootDatabase) -> SearchScope { |
136 | 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 | |||
137 | let module = match self.module(db) { | 155 | let module = match self.module(db) { |
138 | Some(it) => it, | 156 | Some(it) => it, |
139 | None => return SearchScope::empty(), | 157 | None => return SearchScope::empty(), |