aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/references/name_definition.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/references/name_definition.rs')
-rw-r--r--crates/ra_ide_api/src/references/name_definition.rs38
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
6use hir::{ 6use 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};
10use ra_syntax::{ast, ast::VisibilityOwner, match_ast, AstNode, AstPtr}; 9use ra_syntax::{ast, ast::VisibilityOwner};
11 10
12use crate::db::RootDatabase; 11use 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
33pub(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
63pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { 31pub(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 {