diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_ide_db/src/search.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_ide_db/src/search.rs')
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 44d5c35e6..0b862b449 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -60,6 +60,10 @@ impl SearchScope { | |||
60 | SearchScope::new(std::iter::once((file, None)).collect()) | 60 | SearchScope::new(std::iter::once((file, None)).collect()) |
61 | } | 61 | } |
62 | 62 | ||
63 | pub fn files(files: &[FileId]) -> SearchScope { | ||
64 | SearchScope::new(files.iter().map(|f| (*f, None)).collect()) | ||
65 | } | ||
66 | |||
63 | pub fn intersection(&self, other: &SearchScope) -> SearchScope { | 67 | pub fn intersection(&self, other: &SearchScope) -> SearchScope { |
64 | let (mut small, mut large) = (&self.entries, &other.entries); | 68 | let (mut small, mut large) = (&self.entries, &other.entries); |
65 | if small.len() > large.len() { | 69 | if small.len() > large.len() { |
@@ -180,20 +184,20 @@ impl Definition { | |||
180 | 184 | ||
181 | pub fn find_usages( | 185 | pub fn find_usages( |
182 | &self, | 186 | &self, |
183 | db: &RootDatabase, | 187 | sema: &Semantics<RootDatabase>, |
184 | search_scope: Option<SearchScope>, | 188 | search_scope: Option<SearchScope>, |
185 | ) -> Vec<Reference> { | 189 | ) -> Vec<Reference> { |
186 | let _p = profile("Definition::find_usages"); | 190 | let _p = profile("Definition::find_usages"); |
187 | 191 | ||
188 | let search_scope = { | 192 | let search_scope = { |
189 | let base = self.search_scope(db); | 193 | let base = self.search_scope(sema.db); |
190 | match search_scope { | 194 | match search_scope { |
191 | None => base, | 195 | None => base, |
192 | Some(scope) => base.intersection(&scope), | 196 | Some(scope) => base.intersection(&scope), |
193 | } | 197 | } |
194 | }; | 198 | }; |
195 | 199 | ||
196 | let name = match self.name(db) { | 200 | let name = match self.name(sema.db) { |
197 | None => return Vec::new(), | 201 | None => return Vec::new(), |
198 | Some(it) => it.to_string(), | 202 | Some(it) => it.to_string(), |
199 | }; | 203 | }; |
@@ -202,11 +206,10 @@ impl Definition { | |||
202 | let mut refs = vec![]; | 206 | let mut refs = vec![]; |
203 | 207 | ||
204 | for (file_id, search_range) in search_scope { | 208 | for (file_id, search_range) in search_scope { |
205 | let text = db.file_text(file_id); | 209 | let text = sema.db.file_text(file_id); |
206 | let search_range = | 210 | let search_range = |
207 | search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str()))); | 211 | search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str()))); |
208 | 212 | ||
209 | let sema = Semantics::new(db); | ||
210 | let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); | 213 | let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); |
211 | 214 | ||
212 | for (idx, _) in text.match_indices(pat) { | 215 | for (idx, _) in text.match_indices(pat) { |
@@ -222,9 +225,6 @@ impl Definition { | |||
222 | continue; | 225 | continue; |
223 | }; | 226 | }; |
224 | 227 | ||
225 | // FIXME: reuse sb | ||
226 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 | ||
227 | |||
228 | match classify_name_ref(&sema, &name_ref) { | 228 | match classify_name_ref(&sema, &name_ref) { |
229 | Some(NameRefClass::Definition(def)) if &def == self => { | 229 | Some(NameRefClass::Definition(def)) if &def == self => { |
230 | let kind = if is_record_lit_name_ref(&name_ref) | 230 | let kind = if is_record_lit_name_ref(&name_ref) |
@@ -315,7 +315,7 @@ fn is_record_lit_name_ref(name_ref: &ast::NameRef) -> bool { | |||
315 | name_ref | 315 | name_ref |
316 | .syntax() | 316 | .syntax() |
317 | .ancestors() | 317 | .ancestors() |
318 | .find_map(ast::RecordLit::cast) | 318 | .find_map(ast::RecordExpr::cast) |
319 | .and_then(|l| l.path()) | 319 | .and_then(|l| l.path()) |
320 | .and_then(|p| p.segment()) | 320 | .and_then(|p| p.segment()) |
321 | .map(|p| p.name_ref().as_ref() == Some(name_ref)) | 321 | .map(|p| p.name_ref().as_ref() == Some(name_ref)) |