diff options
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 | 41 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/search_scope.rs | 6 |
3 files changed, 22 insertions, 47 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..ccd75278a 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs | |||
@@ -4,10 +4,10 @@ | |||
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, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, |
8 | Module, ModuleDef, StructField, Ty, VariantDef, | 8 | VariantDef, |
9 | }; | 9 | }; |
10 | use ra_syntax::{ast, ast::VisibilityOwner, match_ast, AstNode, AstPtr}; | 10 | use ra_syntax::{ast, ast::VisibilityOwner}; |
11 | 11 | ||
12 | use crate::db::RootDatabase; | 12 | use crate::db::RootDatabase; |
13 | 13 | ||
@@ -18,9 +18,8 @@ pub enum NameKind { | |||
18 | AssocItem(AssocItem), | 18 | AssocItem(AssocItem), |
19 | Def(ModuleDef), | 19 | Def(ModuleDef), |
20 | SelfType(Ty), | 20 | SelfType(Ty), |
21 | Pat((DefWithBody, AstPtr<ast::BindPat>)), | 21 | Local(Local), |
22 | SelfParam(AstPtr<ast::SelfParam>), | 22 | GenericParam(GenericParam), |
23 | GenericParam(u32), | ||
24 | } | 23 | } |
25 | 24 | ||
26 | #[derive(PartialEq, Eq)] | 25 | #[derive(PartialEq, Eq)] |
@@ -30,36 +29,6 @@ pub(crate) struct NameDefinition { | |||
30 | pub kind: NameKind, | 29 | pub kind: NameKind, |
31 | } | 30 | } |
32 | 31 | ||
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 { | 32 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { |
64 | let container = item.module(db); | 33 | let container = item.module(db); |
65 | let visibility = match item { | 34 | 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 | } |