aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/references/classify.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/references/classify.rs')
-rw-r--r--crates/ra_ide/src/references/classify.rs112
1 files changed, 3 insertions, 109 deletions
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index 758ea4e8b..0326fd379 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -2,119 +2,13 @@
2 2
3use hir::{InFile, PathResolution, SourceBinder}; 3use hir::{InFile, PathResolution, SourceBinder};
4use ra_prof::profile; 4use ra_prof::profile;
5use ra_syntax::{ast, match_ast, AstNode}; 5use ra_syntax::{ast, AstNode};
6use test_utils::tested_by; 6use test_utils::tested_by;
7 7
8use super::{ 8use super::{NameDefinition, NameKind};
9 name_definition::{from_assoc_item, from_module_def, from_struct_field},
10 NameDefinition, NameKind,
11};
12use ra_ide_db::RootDatabase; 9use ra_ide_db::RootDatabase;
13 10
14pub(crate) fn classify_name( 11pub use ra_ide_db::defs::{classify_name, from_assoc_item, from_module_def, from_struct_field};
15 sb: &mut SourceBinder<RootDatabase>,
16 name: InFile<&ast::Name>,
17) -> Option<NameDefinition> {
18 let _p = profile("classify_name");
19 let parent = name.value.syntax().parent()?;
20
21 match_ast! {
22 match parent {
23 ast::BindPat(it) => {
24 let src = name.with_value(it);
25 let local = sb.to_def(src)?;
26 Some(NameDefinition {
27 visibility: None,
28 container: local.module(sb.db),
29 kind: NameKind::Local(local),
30 })
31 },
32 ast::RecordFieldDef(it) => {
33 let src = name.with_value(it);
34 let field: hir::StructField = sb.to_def(src)?;
35 Some(from_struct_field(sb.db, field))
36 },
37 ast::Module(it) => {
38 let def = sb.to_def(name.with_value(it))?;
39 Some(from_module_def(sb.db, def.into(), None))
40 },
41 ast::StructDef(it) => {
42 let src = name.with_value(it);
43 let def: hir::Struct = sb.to_def(src)?;
44 Some(from_module_def(sb.db, def.into(), None))
45 },
46 ast::EnumDef(it) => {
47 let src = name.with_value(it);
48 let def: hir::Enum = sb.to_def(src)?;
49 Some(from_module_def(sb.db, def.into(), None))
50 },
51 ast::TraitDef(it) => {
52 let src = name.with_value(it);
53 let def: hir::Trait = sb.to_def(src)?;
54 Some(from_module_def(sb.db, def.into(), None))
55 },
56 ast::StaticDef(it) => {
57 let src = name.with_value(it);
58 let def: hir::Static = sb.to_def(src)?;
59 Some(from_module_def(sb.db, def.into(), None))
60 },
61 ast::EnumVariant(it) => {
62 let src = name.with_value(it);
63 let def: hir::EnumVariant = sb.to_def(src)?;
64 Some(from_module_def(sb.db, def.into(), None))
65 },
66 ast::FnDef(it) => {
67 let src = name.with_value(it);
68 let def: hir::Function = sb.to_def(src)?;
69 if parent.parent().and_then(ast::ItemList::cast).is_some() {
70 Some(from_assoc_item(sb.db, def.into()))
71 } else {
72 Some(from_module_def(sb.db, def.into(), None))
73 }
74 },
75 ast::ConstDef(it) => {
76 let src = name.with_value(it);
77 let def: hir::Const = sb.to_def(src)?;
78 if parent.parent().and_then(ast::ItemList::cast).is_some() {
79 Some(from_assoc_item(sb.db, def.into()))
80 } else {
81 Some(from_module_def(sb.db, def.into(), None))
82 }
83 },
84 ast::TypeAliasDef(it) => {
85 let src = name.with_value(it);
86 let def: hir::TypeAlias = sb.to_def(src)?;
87 if parent.parent().and_then(ast::ItemList::cast).is_some() {
88 Some(from_assoc_item(sb.db, def.into()))
89 } else {
90 Some(from_module_def(sb.db, def.into(), None))
91 }
92 },
93 ast::MacroCall(it) => {
94 let src = name.with_value(it);
95 let def = sb.to_def(src.clone())?;
96
97 let module = sb.to_module_def(src.file_id.original_file(sb.db))?;
98
99 Some(NameDefinition {
100 visibility: None,
101 container: module,
102 kind: NameKind::Macro(def),
103 })
104 },
105 ast::TypeParam(it) => {
106 let src = name.with_value(it);
107 let def = sb.to_def(src)?;
108 Some(NameDefinition {
109 visibility: None,
110 container: def.module(sb.db),
111 kind: NameKind::TypeParam(def),
112 })
113 },
114 _ => None,
115 }
116 }
117}
118 12
119pub(crate) fn classify_name_ref( 13pub(crate) fn classify_name_ref(
120 sb: &mut SourceBinder<RootDatabase>, 14 sb: &mut SourceBinder<RootDatabase>,