diff options
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 28 |
2 files changed, 30 insertions, 5 deletions
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 6bcccc848..fc1b19def 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -55,6 +55,13 @@ impl FileLoader for RootDatabase { | |||
55 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 55 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
56 | FileLoaderDelegate(self).relevant_crates(file_id) | 56 | FileLoaderDelegate(self).relevant_crates(file_id) |
57 | } | 57 | } |
58 | fn resolve_extern_path( | ||
59 | &self, | ||
60 | extern_id: ra_db::ExternSourceId, | ||
61 | relative_path: &RelativePath, | ||
62 | ) -> Option<FileId> { | ||
63 | FileLoaderDelegate(self).resolve_extern_path(extern_id, relative_path) | ||
64 | } | ||
58 | } | 65 | } |
59 | 66 | ||
60 | impl salsa::Database for RootDatabase { | 67 | impl salsa::Database for RootDatabase { |
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 6f198df04..cf78d3e41 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -17,7 +17,7 @@ use rustc_hash::FxHashMap; | |||
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | defs::{classify_name_ref, Definition}, | 20 | defs::{classify_name_ref, Definition, NameRefClass}, |
21 | RootDatabase, | 21 | RootDatabase, |
22 | }; | 22 | }; |
23 | 23 | ||
@@ -30,6 +30,8 @@ pub struct Reference { | |||
30 | 30 | ||
31 | #[derive(Debug, Clone, PartialEq)] | 31 | #[derive(Debug, Clone, PartialEq)] |
32 | pub enum ReferenceKind { | 32 | pub enum ReferenceKind { |
33 | StructFieldShorthandForField, | ||
34 | StructFieldShorthandForLocal, | ||
33 | StructLiteral, | 35 | StructLiteral, |
34 | Other, | 36 | Other, |
35 | } | 37 | } |
@@ -237,9 +239,8 @@ impl Definition { | |||
237 | // FIXME: reuse sb | 239 | // FIXME: reuse sb |
238 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 | 240 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 |
239 | 241 | ||
240 | if let Some(d) = classify_name_ref(&sema, &name_ref) { | 242 | match classify_name_ref(&sema, &name_ref) { |
241 | let d = d.definition(); | 243 | Some(NameRefClass::Definition(def)) if &def == self => { |
242 | if &d == self { | ||
243 | let kind = if is_record_lit_name_ref(&name_ref) | 244 | let kind = if is_record_lit_name_ref(&name_ref) |
244 | || is_call_expr_name_ref(&name_ref) | 245 | || is_call_expr_name_ref(&name_ref) |
245 | { | 246 | { |
@@ -252,9 +253,26 @@ impl Definition { | |||
252 | refs.push(Reference { | 253 | refs.push(Reference { |
253 | file_range, | 254 | file_range, |
254 | kind, | 255 | kind, |
255 | access: reference_access(&d, &name_ref), | 256 | access: reference_access(&def, &name_ref), |
256 | }); | 257 | }); |
257 | } | 258 | } |
259 | Some(NameRefClass::FieldShorthand { local, field }) => { | ||
260 | match self { | ||
261 | Definition::StructField(_) if &field == self => refs.push(Reference { | ||
262 | file_range: sema.original_range(name_ref.syntax()), | ||
263 | kind: ReferenceKind::StructFieldShorthandForField, | ||
264 | access: reference_access(&field, &name_ref), | ||
265 | }), | ||
266 | Definition::Local(l) if &local == l => refs.push(Reference { | ||
267 | file_range: sema.original_range(name_ref.syntax()), | ||
268 | kind: ReferenceKind::StructFieldShorthandForLocal, | ||
269 | access: reference_access(&Definition::Local(local), &name_ref), | ||
270 | }), | ||
271 | |||
272 | _ => {} // not a usage | ||
273 | }; | ||
274 | } | ||
275 | _ => {} // not a usage | ||
258 | } | 276 | } |
259 | } | 277 | } |
260 | } | 278 | } |