diff options
Diffstat (limited to 'crates/ra_ide/src/impls.rs')
-rw-r--r-- | crates/ra_ide/src/impls.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs index fb9396195..9834025d3 100644 --- a/crates/ra_ide/src/impls.rs +++ b/crates/ra_ide/src/impls.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{ImplBlock, SourceBinder}; | 3 | use hir::{Crate, ImplBlock, SourceBinder}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; | 5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; |
6 | 6 | ||
@@ -14,21 +14,17 @@ pub(crate) fn goto_implementation( | |||
14 | let syntax = parse.tree().syntax().clone(); | 14 | let syntax = parse.tree().syntax().clone(); |
15 | let mut sb = SourceBinder::new(db); | 15 | let mut sb = SourceBinder::new(db); |
16 | 16 | ||
17 | let src = hir::ModuleSource::from_position(db, position); | 17 | let krate = sb.to_module_def(position.file_id)?.krate(); |
18 | let module = hir::Module::from_definition( | ||
19 | db, | ||
20 | hir::InFile { file_id: position.file_id.into(), value: src }, | ||
21 | )?; | ||
22 | 18 | ||
23 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { | 19 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { |
24 | return Some(RangeInfo::new( | 20 | return Some(RangeInfo::new( |
25 | nominal_def.syntax().text_range(), | 21 | nominal_def.syntax().text_range(), |
26 | impls_for_def(&mut sb, position, &nominal_def, module)?, | 22 | impls_for_def(&mut sb, position, &nominal_def, krate)?, |
27 | )); | 23 | )); |
28 | } else if let Some(trait_def) = find_node_at_offset::<ast::TraitDef>(&syntax, position.offset) { | 24 | } else if let Some(trait_def) = find_node_at_offset::<ast::TraitDef>(&syntax, position.offset) { |
29 | return Some(RangeInfo::new( | 25 | return Some(RangeInfo::new( |
30 | trait_def.syntax().text_range(), | 26 | trait_def.syntax().text_range(), |
31 | impls_for_trait(&mut sb, position, &trait_def, module)?, | 27 | impls_for_trait(&mut sb, position, &trait_def, krate)?, |
32 | )); | 28 | )); |
33 | } | 29 | } |
34 | 30 | ||
@@ -39,7 +35,7 @@ fn impls_for_def( | |||
39 | sb: &mut SourceBinder<RootDatabase>, | 35 | sb: &mut SourceBinder<RootDatabase>, |
40 | position: FilePosition, | 36 | position: FilePosition, |
41 | node: &ast::NominalDef, | 37 | node: &ast::NominalDef, |
42 | module: hir::Module, | 38 | krate: Crate, |
43 | ) -> Option<Vec<NavigationTarget>> { | 39 | ) -> Option<Vec<NavigationTarget>> { |
44 | let ty = match node { | 40 | let ty = match node { |
45 | ast::NominalDef::StructDef(def) => { | 41 | ast::NominalDef::StructDef(def) => { |
@@ -56,7 +52,6 @@ fn impls_for_def( | |||
56 | } | 52 | } |
57 | }; | 53 | }; |
58 | 54 | ||
59 | let krate = module.krate(); | ||
60 | let impls = ImplBlock::all_in_crate(sb.db, krate); | 55 | let impls = ImplBlock::all_in_crate(sb.db, krate); |
61 | 56 | ||
62 | Some( | 57 | Some( |
@@ -72,12 +67,11 @@ fn impls_for_trait( | |||
72 | sb: &mut SourceBinder<RootDatabase>, | 67 | sb: &mut SourceBinder<RootDatabase>, |
73 | position: FilePosition, | 68 | position: FilePosition, |
74 | node: &ast::TraitDef, | 69 | node: &ast::TraitDef, |
75 | module: hir::Module, | 70 | krate: Crate, |
76 | ) -> Option<Vec<NavigationTarget>> { | 71 | ) -> Option<Vec<NavigationTarget>> { |
77 | let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() }; | 72 | let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() }; |
78 | let tr = sb.to_def(src)?; | 73 | let tr = sb.to_def(src)?; |
79 | 74 | ||
80 | let krate = module.krate(); | ||
81 | let impls = ImplBlock::for_trait(sb.db, krate, tr); | 75 | let impls = ImplBlock::for_trait(sb.db, krate, tr); |
82 | 76 | ||
83 | Some(impls.into_iter().map(|imp| imp.to_nav(sb.db)).collect()) | 77 | Some(impls.into_iter().map(|imp| imp.to_nav(sb.db)).collect()) |