aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2019-03-02 19:57:40 +0000
committerJeremy Kolb <[email protected]>2019-03-04 13:27:08 +0000
commite1b59bfe0b00157a97f167b4857418b914ec1fd3 (patch)
tree47a39f4b42cf9ba2ad5f290ee90189fc4b3da52d /crates/ra_ide_api
parentad2da5b1dac87896772b4ae4087b4f9c83dc8ac9 (diff)
Add NavigationTarget::from_impl_item
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs15
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs21
2 files changed, 22 insertions, 14 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 3b66483cb..f16c3bda4 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -5,7 +5,7 @@ use ra_syntax::{
5 SyntaxNode, 5 SyntaxNode,
6}; 6};
7use test_utils::tested_by; 7use test_utils::tested_by;
8use hir::{ImplItem, Resolution}; 8use hir::Resolution;
9 9
10use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; 10use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
11 11
@@ -138,18 +138,7 @@ pub(crate) fn reference_definition(
138 .node_expr(expr) 138 .node_expr(expr)
139 .and_then(|it| infer_result.assoc_resolutions(it.into())) 139 .and_then(|it| infer_result.assoc_resolutions(it.into()))
140 { 140 {
141 match res { 141 return Exact(NavigationTarget::from_impl_item(db, res));
142 ImplItem::Method(f) => {
143 return Exact(NavigationTarget::from_function(db, f));
144 }
145 ImplItem::Const(c) => {
146 let (file, node) = c.source(db);
147 let file = file.original_file(db);
148 let node = &*node;
149 return Exact(NavigationTarget::from_named(file, node));
150 }
151 _ => {}
152 }
153 } 142 }
154 } 143 }
155 } 144 }
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 6538081ac..ff8d2f15b 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -3,7 +3,7 @@ use ra_syntax::{
3 SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast, 3 SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast,
4 SyntaxKind::{self, NAME}, 4 SyntaxKind::{self, NAME},
5}; 5};
6use hir::{ModuleSource, FieldSource, Name}; 6use hir::{ModuleSource, FieldSource, Name, ImplItem};
7 7
8use crate::{FileSymbol, db::RootDatabase}; 8use crate::{FileSymbol, db::RootDatabase};
9 9
@@ -174,6 +174,25 @@ impl NavigationTarget {
174 ) 174 )
175 } 175 }
176 176
177 pub(crate) fn from_impl_item(
178 db: &RootDatabase,
179 impl_item: hir::ImplItem,
180 ) -> NavigationTarget {
181 match impl_item {
182 ImplItem::Method(f) => {
183 NavigationTarget::from_function(db, f)
184 }
185 ImplItem::Const(c) => {
186 let (file_id, node) = c.source(db);
187 NavigationTarget::from_named(file_id.original_file(db), &*node)
188 }
189 ImplItem::TypeAlias(a) => {
190 let (file_id, node) = a.source(db);
191 NavigationTarget::from_named(file_id.original_file(db), &*node)
192 }
193 }
194 }
195
177 #[cfg(test)] 196 #[cfg(test)]
178 pub(crate) fn assert_match(&self, expected: &str) { 197 pub(crate) fn assert_match(&self, expected: &str) {
179 let actual = self.debug_render(); 198 let actual = self.debug_render();