diff options
author | Aleksey Kladov <[email protected]> | 2020-01-16 15:08:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-01-16 15:08:46 +0000 |
commit | 81a45ca1b3606d2c328740aa7e2dc989b9e128a5 (patch) | |
tree | beb2951ab9f7a7ab1420cb072c8839957c6de02f /crates/ra_ide/src | |
parent | f4eeff2c82e7d8b95706c2bcb0388eeeb3ddd24e (diff) |
Make FromSource private
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/impls.rs | 31 | ||||
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 4 |
2 files changed, 18 insertions, 17 deletions
diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs index 31195036e..bd14a6d13 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::{FromSource, ImplBlock}; | 3 | use hir::{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 | ||
@@ -12,6 +12,7 @@ pub(crate) fn goto_implementation( | |||
12 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 12 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
13 | let parse = db.parse(position.file_id); | 13 | let parse = db.parse(position.file_id); |
14 | let syntax = parse.tree().syntax().clone(); | 14 | let syntax = parse.tree().syntax().clone(); |
15 | let mut sb = SourceBinder::new(db); | ||
15 | 16 | ||
16 | let src = hir::ModuleSource::from_position(db, position); | 17 | let src = hir::ModuleSource::from_position(db, position); |
17 | let module = hir::Module::from_definition( | 18 | let module = hir::Module::from_definition( |
@@ -22,12 +23,12 @@ pub(crate) fn goto_implementation( | |||
22 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { | 23 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { |
23 | return Some(RangeInfo::new( | 24 | return Some(RangeInfo::new( |
24 | nominal_def.syntax().text_range(), | 25 | nominal_def.syntax().text_range(), |
25 | impls_for_def(db, position, &nominal_def, module)?, | 26 | impls_for_def(&mut sb, position, &nominal_def, module)?, |
26 | )); | 27 | )); |
27 | } else if let Some(trait_def) = find_node_at_offset::<ast::TraitDef>(&syntax, position.offset) { | 28 | } else if let Some(trait_def) = find_node_at_offset::<ast::TraitDef>(&syntax, position.offset) { |
28 | return Some(RangeInfo::new( | 29 | return Some(RangeInfo::new( |
29 | trait_def.syntax().text_range(), | 30 | trait_def.syntax().text_range(), |
30 | impls_for_trait(db, position, &trait_def, module)?, | 31 | impls_for_trait(&mut sb, position, &trait_def, module)?, |
31 | )); | 32 | )); |
32 | } | 33 | } |
33 | 34 | ||
@@ -35,7 +36,7 @@ pub(crate) fn goto_implementation( | |||
35 | } | 36 | } |
36 | 37 | ||
37 | fn impls_for_def( | 38 | fn impls_for_def( |
38 | db: &RootDatabase, | 39 | sb: &mut SourceBinder<RootDatabase>, |
39 | position: FilePosition, | 40 | position: FilePosition, |
40 | node: &ast::NominalDef, | 41 | node: &ast::NominalDef, |
41 | module: hir::Module, | 42 | module: hir::Module, |
@@ -43,43 +44,43 @@ fn impls_for_def( | |||
43 | let ty = match node { | 44 | let ty = match node { |
44 | ast::NominalDef::StructDef(def) => { | 45 | ast::NominalDef::StructDef(def) => { |
45 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; | 46 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; |
46 | hir::Struct::from_source(db, src)?.ty(db) | 47 | sb.to_def::<hir::Struct, _>(src)?.ty(sb.db) |
47 | } | 48 | } |
48 | ast::NominalDef::EnumDef(def) => { | 49 | ast::NominalDef::EnumDef(def) => { |
49 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; | 50 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; |
50 | hir::Enum::from_source(db, src)?.ty(db) | 51 | sb.to_def::<hir::Enum, _>(src)?.ty(sb.db) |
51 | } | 52 | } |
52 | ast::NominalDef::UnionDef(def) => { | 53 | ast::NominalDef::UnionDef(def) => { |
53 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; | 54 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; |
54 | hir::Union::from_source(db, src)?.ty(db) | 55 | sb.to_def::<hir::Union, _>(src)?.ty(sb.db) |
55 | } | 56 | } |
56 | }; | 57 | }; |
57 | 58 | ||
58 | let krate = module.krate(); | 59 | let krate = module.krate(); |
59 | let impls = ImplBlock::all_in_crate(db, krate); | 60 | let impls = ImplBlock::all_in_crate(sb.db, krate); |
60 | 61 | ||
61 | Some( | 62 | Some( |
62 | impls | 63 | impls |
63 | .into_iter() | 64 | .into_iter() |
64 | .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(db))) | 65 | .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(sb.db))) |
65 | .map(|imp| imp.to_nav(db)) | 66 | .map(|imp| imp.to_nav(sb.db)) |
66 | .collect(), | 67 | .collect(), |
67 | ) | 68 | ) |
68 | } | 69 | } |
69 | 70 | ||
70 | fn impls_for_trait( | 71 | fn impls_for_trait( |
71 | db: &RootDatabase, | 72 | sb: &mut SourceBinder<RootDatabase>, |
72 | position: FilePosition, | 73 | position: FilePosition, |
73 | node: &ast::TraitDef, | 74 | node: &ast::TraitDef, |
74 | module: hir::Module, | 75 | module: hir::Module, |
75 | ) -> Option<Vec<NavigationTarget>> { | 76 | ) -> Option<Vec<NavigationTarget>> { |
76 | let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() }; | 77 | let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() }; |
77 | let tr = hir::Trait::from_source(db, src)?; | 78 | let tr = sb.to_def(src)?; |
78 | 79 | ||
79 | let krate = module.krate(); | 80 | let krate = module.krate(); |
80 | let impls = ImplBlock::for_trait(db, krate, tr); | 81 | let impls = ImplBlock::for_trait(sb.db, krate, tr); |
81 | 82 | ||
82 | Some(impls.into_iter().map(|imp| imp.to_nav(db)).collect()) | 83 | Some(impls.into_iter().map(|imp| imp.to_nav(sb.db)).collect()) |
83 | } | 84 | } |
84 | 85 | ||
85 | #[cfg(test)] | 86 | #[cfg(test)] |
@@ -210,7 +211,7 @@ mod tests { | |||
210 | " | 211 | " |
211 | //- /lib.rs | 212 | //- /lib.rs |
212 | #[derive(Copy)] | 213 | #[derive(Copy)] |
213 | struct Foo<|>; | 214 | struct Foo<|>; |
214 | ", | 215 | ", |
215 | &["impl IMPL_BLOCK FileId(1) [0; 15)"], | 216 | &["impl IMPL_BLOCK FileId(1) [0; 15)"], |
216 | ); | 217 | ); |
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 4a6e11e27..dcffc3df2 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Functions that are used to classify an element from its definition or reference. | 1 | //! Functions that are used to classify an element from its definition or reference. |
2 | 2 | ||
3 | use hir::{FromSource, InFile, Module, ModuleSource, PathResolution, SourceBinder}; | 3 | use hir::{InFile, Module, ModuleSource, PathResolution, SourceBinder}; |
4 | use ra_prof::profile; | 4 | use ra_prof::profile; |
5 | use ra_syntax::{ast, match_ast, AstNode}; | 5 | use ra_syntax::{ast, match_ast, AstNode}; |
6 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
@@ -101,7 +101,7 @@ pub(crate) fn classify_name( | |||
101 | }, | 101 | }, |
102 | ast::MacroCall(it) => { | 102 | ast::MacroCall(it) => { |
103 | let src = name.with_value(it); | 103 | let src = name.with_value(it); |
104 | let def = hir::MacroDef::from_source(sb.db, src.clone())?; | 104 | let def = sb.to_def(src.clone())?; |
105 | 105 | ||
106 | let module_src = ModuleSource::from_child_node(sb.db, src.as_ref().map(|it| it.syntax())); | 106 | let module_src = ModuleSource::from_child_node(sb.db, src.as_ref().map(|it| it.syntax())); |
107 | let module = Module::from_definition(sb.db, src.with_value(module_src))?; | 107 | let module = Module::from_definition(sb.db, src.with_value(module_src))?; |