aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/references
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/references')
-rw-r--r--crates/ra_ide_api/src/references/classify.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index 217f9951e..f12b58cb9 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -21,7 +21,6 @@ pub(crate) fn classify_name(
21 let parent = name.syntax().parent()?; 21 let parent = name.syntax().parent()?;
22 let file_id = file_id.into(); 22 let file_id = file_id.into();
23 23
24 // FIXME: add ast::MacroCall(it)
25 match_ast! { 24 match_ast! {
26 match parent { 25 match parent {
27 ast::BindPat(it) => { 26 ast::BindPat(it) => {
@@ -104,6 +103,19 @@ pub(crate) fn classify_name(
104 Some(from_module_def(db, def.into(), None)) 103 Some(from_module_def(db, def.into(), None))
105 } 104 }
106 }, 105 },
106 ast::MacroCall(it) => {
107 let src = hir::Source { file_id, ast: it};
108 let def = hir::MacroDef::from_source(db, src.clone())?;
109
110 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
111 let module = Module::from_definition(db, Source::new(file_id, module_src))?;
112
113 Some(NameDefinition {
114 visibility: None,
115 container: module,
116 kind: NameKind::Macro(def),
117 })
118 },
107 _ => None, 119 _ => None,
108 } 120 }
109 } 121 }
@@ -114,12 +126,11 @@ pub(crate) fn classify_name_ref(
114 file_id: FileId, 126 file_id: FileId,
115 name_ref: &ast::NameRef, 127 name_ref: &ast::NameRef,
116) -> Option<NameDefinition> { 128) -> Option<NameDefinition> {
117 use PathResolution::*;
118
119 let _p = profile("classify_name_ref"); 129 let _p = profile("classify_name_ref");
120 130
121 let parent = name_ref.syntax().parent()?; 131 let parent = name_ref.syntax().parent()?;
122 let analyzer = SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); 132 let analyzer =
133 SourceAnalyzer::new(db, hir::Source::new(file_id.into(), name_ref.syntax()), None);
123 134
124 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 135 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
125 tested_by!(goto_definition_works_for_methods); 136 tested_by!(goto_definition_works_for_methods);
@@ -146,8 +157,8 @@ pub(crate) fn classify_name_ref(
146 } 157 }
147 } 158 }
148 159
149 let ast = ModuleSource::from_child_node(db, file_id, &parent);
150 let file_id = file_id.into(); 160 let file_id = file_id.into();
161 let ast = ModuleSource::from_child_node(db, Source::new(file_id, &parent));
151 // FIXME: find correct container and visibility for each case 162 // FIXME: find correct container and visibility for each case
152 let container = Module::from_definition(db, Source { file_id, ast })?; 163 let container = Module::from_definition(db, Source { file_id, ast })?;
153 let visibility = None; 164 let visibility = None;
@@ -163,26 +174,26 @@ pub(crate) fn classify_name_ref(
163 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; 174 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
164 let resolved = analyzer.resolve_path(db, &path)?; 175 let resolved = analyzer.resolve_path(db, &path)?;
165 match resolved { 176 match resolved {
166 Def(def) => Some(from_module_def(db, def, Some(container))), 177 PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))),
167 AssocItem(item) => Some(from_assoc_item(db, item)), 178 PathResolution::AssocItem(item) => Some(from_assoc_item(db, item)),
168 Local(local) => { 179 PathResolution::Local(local) => {
169 let container = local.module(db); 180 let container = local.module(db);
170 let kind = NameKind::Local(local); 181 let kind = NameKind::Local(local);
171 Some(NameDefinition { kind, container, visibility: None }) 182 Some(NameDefinition { kind, container, visibility: None })
172 } 183 }
173 GenericParam(par) => { 184 PathResolution::GenericParam(par) => {
174 // FIXME: get generic param def 185 // FIXME: get generic param def
175 let kind = NameKind::GenericParam(par); 186 let kind = NameKind::GenericParam(par);
176 Some(NameDefinition { kind, container, visibility }) 187 Some(NameDefinition { kind, container, visibility })
177 } 188 }
178 Macro(def) => { 189 PathResolution::Macro(def) => {
179 let kind = NameKind::Macro(def); 190 let kind = NameKind::Macro(def);
180 Some(NameDefinition { kind, container, visibility }) 191 Some(NameDefinition { kind, container, visibility })
181 } 192 }
182 SelfType(impl_block) => { 193 PathResolution::SelfType(impl_block) => {
183 let ty = impl_block.target_ty(db); 194 let ty = impl_block.target_ty(db);
184 let kind = NameKind::SelfType(ty); 195 let kind = NameKind::SelfType(ty);
185 let container = impl_block.module(); 196 let container = impl_block.module(db);
186 Some(NameDefinition { kind, container, visibility }) 197 Some(NameDefinition { kind, container, visibility })
187 } 198 }
188 } 199 }