diff options
author | Aleksey Kladov <[email protected]> | 2019-11-16 10:33:25 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-16 10:33:25 +0000 |
commit | 272af56a5c5a0e89fc3c2db41e125f0f16df0d0c (patch) | |
tree | 958f763ff024903635a4450cf5aec0000e837446 /crates/ra_ide_api/src/references/classify.rs | |
parent | d9d99369b2765eaef7f49cd519990769191c3381 (diff) |
Sourcify classify_name_ref
Diffstat (limited to 'crates/ra_ide_api/src/references/classify.rs')
-rw-r--r-- | crates/ra_ide_api/src/references/classify.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index f12b58cb9..5ca9da15e 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -123,14 +123,12 @@ pub(crate) fn classify_name( | |||
123 | 123 | ||
124 | pub(crate) fn classify_name_ref( | 124 | pub(crate) fn classify_name_ref( |
125 | db: &RootDatabase, | 125 | db: &RootDatabase, |
126 | file_id: FileId, | 126 | name_ref: Source<&ast::NameRef>, |
127 | name_ref: &ast::NameRef, | ||
128 | ) -> Option<NameDefinition> { | 127 | ) -> Option<NameDefinition> { |
129 | let _p = profile("classify_name_ref"); | 128 | let _p = profile("classify_name_ref"); |
130 | 129 | ||
131 | let parent = name_ref.syntax().parent()?; | 130 | let parent = name_ref.ast.syntax().parent()?; |
132 | let analyzer = | 131 | let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None); |
133 | SourceAnalyzer::new(db, hir::Source::new(file_id.into(), name_ref.syntax()), None); | ||
134 | 132 | ||
135 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { | 133 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { |
136 | tested_by!(goto_definition_works_for_methods); | 134 | tested_by!(goto_definition_works_for_methods); |
@@ -150,17 +148,16 @@ pub(crate) fn classify_name_ref( | |||
150 | tested_by!(goto_definition_works_for_record_fields); | 148 | tested_by!(goto_definition_works_for_record_fields); |
151 | if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { | 149 | if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { |
152 | let variant_def = analyzer.resolve_record_literal(&record_lit)?; | 150 | let variant_def = analyzer.resolve_record_literal(&record_lit)?; |
153 | let hir_path = Path::from_name_ref(name_ref); | 151 | let hir_path = Path::from_name_ref(name_ref.ast); |
154 | let hir_name = hir_path.as_ident()?; | 152 | let hir_name = hir_path.as_ident()?; |
155 | let field = variant_def.field(db, hir_name)?; | 153 | let field = variant_def.field(db, hir_name)?; |
156 | return Some(from_struct_field(db, field)); | 154 | return Some(from_struct_field(db, field)); |
157 | } | 155 | } |
158 | } | 156 | } |
159 | 157 | ||
160 | let file_id = file_id.into(); | 158 | let ast = ModuleSource::from_child_node(db, name_ref.with_ast(&parent)); |
161 | let ast = ModuleSource::from_child_node(db, Source::new(file_id, &parent)); | ||
162 | // FIXME: find correct container and visibility for each case | 159 | // FIXME: find correct container and visibility for each case |
163 | let container = Module::from_definition(db, Source { file_id, ast })?; | 160 | let container = Module::from_definition(db, name_ref.with_ast(ast))?; |
164 | let visibility = None; | 161 | let visibility = None; |
165 | 162 | ||
166 | if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { | 163 | if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { |
@@ -171,7 +168,7 @@ pub(crate) fn classify_name_ref( | |||
171 | } | 168 | } |
172 | } | 169 | } |
173 | 170 | ||
174 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; | 171 | let path = name_ref.ast.syntax().ancestors().find_map(ast::Path::cast)?; |
175 | let resolved = analyzer.resolve_path(db, &path)?; | 172 | let resolved = analyzer.resolve_path(db, &path)?; |
176 | match resolved { | 173 | match resolved { |
177 | PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), | 174 | PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), |