diff options
author | Aleksey Kladov <[email protected]> | 2019-11-09 21:32:00 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-11 11:42:08 +0000 |
commit | 8b7f853cc19d0940ec542e10bc23aa78455bbb3b (patch) | |
tree | eb418bb0df37516dcf24ffc754a862ffea1ab789 /crates/ra_ide_api/src/references/name_definition.rs | |
parent | 5ac4ffbc121c8231fe3ea5c2bb918f7aae60f197 (diff) |
Add hir::Local
Diffstat (limited to 'crates/ra_ide_api/src/references/name_definition.rs')
-rw-r--r-- | crates/ra_ide_api/src/references/name_definition.rs | 38 |
1 files changed, 3 insertions, 35 deletions
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 { |