diff options
author | Seivan Heidari <[email protected]> | 2019-11-11 13:31:09 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-11 13:31:09 +0000 |
commit | 68a5ff050faf514e9d122212a66703ca8ce66ab7 (patch) | |
tree | 0c389d2680aae82c1805a52f8315312724134341 /crates/ra_ide_api/src/references | |
parent | 7cd075ff0beb97039cd1d1c6c021abf89339731b (diff) | |
parent | a599147b4232c0d4f6b071a3a96e86f903f4cf52 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_ide_api/src/references')
-rw-r--r-- | crates/ra_ide_api/src/references/classify.rs | 22 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/name_definition.rs | 38 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/search_scope.rs | 6 |
3 files changed, 20 insertions, 46 deletions
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index 153082d5b..217f9951e 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -1,13 +1,13 @@ | |||
1 | //! Functions that are used to classify an element from its definition or reference. | 1 | //! Functions that are used to classify an element from its definition or reference. |
2 | 2 | ||
3 | use hir::{Either, FromSource, Module, ModuleSource, Path, PathResolution, Source, SourceAnalyzer}; | 3 | use hir::{FromSource, Module, ModuleSource, Path, PathResolution, Source, SourceAnalyzer}; |
4 | use ra_db::FileId; | 4 | use ra_db::FileId; |
5 | use ra_prof::profile; | 5 | use ra_prof::profile; |
6 | use ra_syntax::{ast, match_ast, AstNode, AstPtr}; | 6 | use ra_syntax::{ast, match_ast, AstNode}; |
7 | use test_utils::tested_by; | 7 | use test_utils::tested_by; |
8 | 8 | ||
9 | use super::{ | 9 | use super::{ |
10 | name_definition::{from_assoc_item, from_module_def, from_pat, from_struct_field}, | 10 | name_definition::{from_assoc_item, from_module_def, from_struct_field}, |
11 | NameDefinition, NameKind, | 11 | NameDefinition, NameKind, |
12 | }; | 12 | }; |
13 | use crate::db::RootDatabase; | 13 | use crate::db::RootDatabase; |
@@ -25,7 +25,13 @@ pub(crate) fn classify_name( | |||
25 | match_ast! { | 25 | match_ast! { |
26 | match parent { | 26 | match parent { |
27 | ast::BindPat(it) => { | 27 | ast::BindPat(it) => { |
28 | from_pat(db, file_id, AstPtr::new(&it)) | 28 | let src = hir::Source { file_id, ast: it }; |
29 | let local = hir::Local::from_source(db, src)?; | ||
30 | Some(NameDefinition { | ||
31 | visibility: None, | ||
32 | container: local.module(db), | ||
33 | kind: NameKind::Local(local), | ||
34 | }) | ||
29 | }, | 35 | }, |
30 | ast::RecordFieldDef(it) => { | 36 | ast::RecordFieldDef(it) => { |
31 | let ast = hir::FieldSource::Named(it); | 37 | let ast = hir::FieldSource::Named(it); |
@@ -159,10 +165,10 @@ pub(crate) fn classify_name_ref( | |||
159 | match resolved { | 165 | match resolved { |
160 | Def(def) => Some(from_module_def(db, def, Some(container))), | 166 | Def(def) => Some(from_module_def(db, def, Some(container))), |
161 | AssocItem(item) => Some(from_assoc_item(db, item)), | 167 | AssocItem(item) => Some(from_assoc_item(db, item)), |
162 | LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat), | 168 | Local(local) => { |
163 | LocalBinding(Either::B(par)) => { | 169 | let container = local.module(db); |
164 | let kind = NameKind::SelfParam(par); | 170 | let kind = NameKind::Local(local); |
165 | Some(NameDefinition { kind, container, visibility }) | 171 | Some(NameDefinition { kind, container, visibility: None }) |
166 | } | 172 | } |
167 | GenericParam(par) => { | 173 | GenericParam(par) => { |
168 | // FIXME: get generic param def | 174 | // FIXME: get generic param def |
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index 4580bc789..450f7ea9b 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs | |||
@@ -4,10 +4,9 @@ | |||
4 | //! Note that the reference search is possible for not all of the classified items. | 4 | //! Note that the reference search is possible for not all of the classified items. |
5 | 5 | ||
6 | use hir::{ | 6 | use hir::{ |
7 | db::AstDatabase, Adt, AssocItem, DefWithBody, FromSource, HasSource, HirFileId, MacroDef, | 7 | Adt, AssocItem, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, VariantDef, |
8 | Module, ModuleDef, StructField, Ty, VariantDef, | ||
9 | }; | 8 | }; |
10 | use ra_syntax::{ast, ast::VisibilityOwner, match_ast, AstNode, AstPtr}; | 9 | use ra_syntax::{ast, ast::VisibilityOwner}; |
11 | 10 | ||
12 | use crate::db::RootDatabase; | 11 | use crate::db::RootDatabase; |
13 | 12 | ||
@@ -18,8 +17,7 @@ pub enum NameKind { | |||
18 | AssocItem(AssocItem), | 17 | AssocItem(AssocItem), |
19 | Def(ModuleDef), | 18 | Def(ModuleDef), |
20 | SelfType(Ty), | 19 | SelfType(Ty), |
21 | Pat((DefWithBody, AstPtr<ast::BindPat>)), | 20 | Local(Local), |
22 | SelfParam(AstPtr<ast::SelfParam>), | ||
23 | GenericParam(u32), | 21 | GenericParam(u32), |
24 | } | 22 | } |
25 | 23 | ||
@@ -30,36 +28,6 @@ pub(crate) struct NameDefinition { | |||
30 | pub kind: NameKind, | 28 | pub kind: NameKind, |
31 | } | 29 | } |
32 | 30 | ||
33 | pub(super) fn from_pat( | ||
34 | db: &RootDatabase, | ||
35 | file_id: HirFileId, | ||
36 | pat: AstPtr<ast::BindPat>, | ||
37 | ) -> Option<NameDefinition> { | ||
38 | let root = db.parse_or_expand(file_id)?; | ||
39 | let def = pat.to_node(&root).syntax().ancestors().find_map(|node| { | ||
40 | match_ast! { | ||
41 | match node { | ||
42 | ast::FnDef(it) => { | ||
43 | let src = hir::Source { file_id, ast: it }; | ||
44 | Some(hir::Function::from_source(db, src)?.into()) | ||
45 | }, | ||
46 | ast::ConstDef(it) => { | ||
47 | let src = hir::Source { file_id, ast: it }; | ||
48 | Some(hir::Const::from_source(db, src)?.into()) | ||
49 | }, | ||
50 | ast::StaticDef(it) => { | ||
51 | let src = hir::Source { file_id, ast: it }; | ||
52 | Some(hir::Static::from_source(db, src)?.into()) | ||
53 | }, | ||
54 | _ => None, | ||
55 | } | ||
56 | } | ||
57 | })?; | ||
58 | let kind = NameKind::Pat((def, pat)); | ||
59 | let container = def.module(db); | ||
60 | Some(NameDefinition { kind, container, visibility: None }) | ||
61 | } | ||
62 | |||
63 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { | 31 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { |
64 | let container = item.module(db); | 32 | let container = item.module(db); |
65 | let visibility = match item { | 33 | let visibility = match item { |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index f2789e0b2..2907787c2 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -71,13 +71,13 @@ impl NameDefinition { | |||
71 | let module_src = self.container.definition_source(db); | 71 | let module_src = self.container.definition_source(db); |
72 | let file_id = module_src.file_id.original_file(db); | 72 | let file_id = module_src.file_id.original_file(db); |
73 | 73 | ||
74 | if let NameKind::Pat((def, _)) = self.kind { | 74 | if let NameKind::Local(var) = self.kind { |
75 | let mut res = FxHashMap::default(); | 75 | let range = match var.parent(db) { |
76 | let range = match def { | ||
77 | DefWithBody::Function(f) => f.source(db).ast.syntax().text_range(), | 76 | DefWithBody::Function(f) => f.source(db).ast.syntax().text_range(), |
78 | DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(), | 77 | DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(), |
79 | DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(), | 78 | DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(), |
80 | }; | 79 | }; |
80 | let mut res = FxHashMap::default(); | ||
81 | res.insert(file_id, Some(range)); | 81 | res.insert(file_id, Some(range)); |
82 | return SearchScope::new(res); | 82 | return SearchScope::new(res); |
83 | } | 83 | } |