diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-16 16:58:13 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-16 16:58:13 +0000 |
commit | d3c4fbbbc45afc7d480185493b5ce77b5daa1747 (patch) | |
tree | aa12838a1b0c45710bb7657f6f3c34947519484c /crates/ra_ide/src | |
parent | e614356de10256c64e02f5d0f82cfa39e27b0f07 (diff) | |
parent | 846f11c2177f3e3a6348acb67503028180b3c1f8 (diff) |
Merge #2862
2862: Move from `from_source` to `SourceBinder` r=matklad a=matklad
bors r+
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 38 | ||||
-rw-r--r-- | crates/ra_ide/src/impls.rs | 43 | ||||
-rw-r--r-- | crates/ra_ide/src/parent_module.rs | 29 | ||||
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide/src/references/name_definition.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/runnables.rs | 4 |
9 files changed, 73 insertions, 89 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 48d69f7e5..deaacda6c 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -52,15 +52,11 @@ impl<'a> CompletionContext<'a> { | |||
52 | original_parse: &'a Parse<ast::SourceFile>, | 52 | original_parse: &'a Parse<ast::SourceFile>, |
53 | position: FilePosition, | 53 | position: FilePosition, |
54 | ) -> Option<CompletionContext<'a>> { | 54 | ) -> Option<CompletionContext<'a>> { |
55 | let src = hir::ModuleSource::from_position(db, position); | 55 | let mut sb = hir::SourceBinder::new(db); |
56 | let module = hir::Module::from_definition( | 56 | let module = sb.to_module_def(position.file_id); |
57 | db, | ||
58 | hir::InFile { file_id: position.file_id.into(), value: src }, | ||
59 | ); | ||
60 | let token = | 57 | let token = |
61 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; | 58 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; |
62 | let analyzer = hir::SourceAnalyzer::new( | 59 | let analyzer = sb.analyze( |
63 | db, | ||
64 | hir::InFile::new(position.file_id.into(), &token.parent()), | 60 | hir::InFile::new(position.file_id.into(), &token.parent()), |
65 | Some(position.offset), | 61 | Some(position.offset), |
66 | ); | 62 | ); |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 478368529..f403b3bcf 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -23,6 +23,7 @@ pub enum Severity { | |||
23 | 23 | ||
24 | pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> { | 24 | pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> { |
25 | let _p = profile("diagnostics"); | 25 | let _p = profile("diagnostics"); |
26 | let mut sb = hir::SourceBinder::new(db); | ||
26 | let parse = db.parse(file_id); | 27 | let parse = db.parse(file_id); |
27 | let mut res = Vec::new(); | 28 | let mut res = Vec::new(); |
28 | 29 | ||
@@ -108,10 +109,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
108 | fix: Some(fix), | 109 | fix: Some(fix), |
109 | }) | 110 | }) |
110 | }); | 111 | }); |
111 | let source_file = db.parse(file_id).tree(); | 112 | if let Some(m) = sb.to_module_def(file_id) { |
112 | let src = | ||
113 | hir::InFile { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) }; | ||
114 | if let Some(m) = hir::Module::from_definition(db, src) { | ||
115 | m.diagnostics(db, &mut sink); | 113 | m.diagnostics(db, &mut sink); |
116 | }; | 114 | }; |
117 | drop(sink); | 115 | drop(sink); |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index f2b5af321..5a12a619c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -24,13 +24,14 @@ pub(crate) fn goto_definition( | |||
24 | let original_token = pick_best(file.token_at_offset(position.offset))?; | 24 | let original_token = pick_best(file.token_at_offset(position.offset))?; |
25 | let token = descend_into_macros(db, position.file_id, original_token.clone()); | 25 | let token = descend_into_macros(db, position.file_id, original_token.clone()); |
26 | 26 | ||
27 | let mut sb = SourceBinder::new(db); | ||
27 | let nav_targets = match_ast! { | 28 | let nav_targets = match_ast! { |
28 | match (token.value.parent()) { | 29 | match (token.value.parent()) { |
29 | ast::NameRef(name_ref) => { | 30 | ast::NameRef(name_ref) => { |
30 | reference_definition(db, token.with_value(&name_ref)).to_vec() | 31 | reference_definition(&mut sb, token.with_value(&name_ref)).to_vec() |
31 | }, | 32 | }, |
32 | ast::Name(name) => { | 33 | ast::Name(name) => { |
33 | name_definition(db, token.with_value(&name))? | 34 | name_definition(&mut sb, token.with_value(&name))? |
34 | }, | 35 | }, |
35 | _ => return None, | 36 | _ => return None, |
36 | } | 37 | } |
@@ -67,20 +68,19 @@ impl ReferenceResult { | |||
67 | } | 68 | } |
68 | 69 | ||
69 | pub(crate) fn reference_definition( | 70 | pub(crate) fn reference_definition( |
70 | db: &RootDatabase, | 71 | sb: &mut SourceBinder<RootDatabase>, |
71 | name_ref: InFile<&ast::NameRef>, | 72 | name_ref: InFile<&ast::NameRef>, |
72 | ) -> ReferenceResult { | 73 | ) -> ReferenceResult { |
73 | use self::ReferenceResult::*; | 74 | use self::ReferenceResult::*; |
74 | 75 | ||
75 | let mut sb = SourceBinder::new(db); | 76 | let name_kind = classify_name_ref(sb, name_ref).map(|d| d.kind); |
76 | let name_kind = classify_name_ref(&mut sb, name_ref).map(|d| d.kind); | ||
77 | match name_kind { | 77 | match name_kind { |
78 | Some(Macro(it)) => return Exact(it.to_nav(db)), | 78 | Some(Macro(it)) => return Exact(it.to_nav(sb.db)), |
79 | Some(Field(it)) => return Exact(it.to_nav(db)), | 79 | Some(Field(it)) => return Exact(it.to_nav(sb.db)), |
80 | Some(TypeParam(it)) => return Exact(it.to_nav(db)), | 80 | Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)), |
81 | Some(AssocItem(it)) => return Exact(it.to_nav(db)), | 81 | Some(AssocItem(it)) => return Exact(it.to_nav(sb.db)), |
82 | Some(Local(it)) => return Exact(it.to_nav(db)), | 82 | Some(Local(it)) => return Exact(it.to_nav(sb.db)), |
83 | Some(Def(def)) => match NavigationTarget::from_def(db, def) { | 83 | Some(Def(def)) => match NavigationTarget::from_def(sb.db, def) { |
84 | Some(nav) => return Exact(nav), | 84 | Some(nav) => return Exact(nav), |
85 | None => return Approximate(vec![]), | 85 | None => return Approximate(vec![]), |
86 | }, | 86 | }, |
@@ -88,21 +88,21 @@ pub(crate) fn reference_definition( | |||
88 | // FIXME: ideally, this should point to the type in the impl, and | 88 | // FIXME: ideally, this should point to the type in the impl, and |
89 | // not at the whole impl. And goto **type** definition should bring | 89 | // not at the whole impl. And goto **type** definition should bring |
90 | // us to the actual type | 90 | // us to the actual type |
91 | return Exact(imp.to_nav(db)); | 91 | return Exact(imp.to_nav(sb.db)); |
92 | } | 92 | } |
93 | None => {} | 93 | None => {} |
94 | }; | 94 | }; |
95 | 95 | ||
96 | // Fallback index based approach: | 96 | // Fallback index based approach: |
97 | let navs = crate::symbol_index::index_resolve(db, name_ref.value) | 97 | let navs = crate::symbol_index::index_resolve(sb.db, name_ref.value) |
98 | .into_iter() | 98 | .into_iter() |
99 | .map(|s| s.to_nav(db)) | 99 | .map(|s| s.to_nav(sb.db)) |
100 | .collect(); | 100 | .collect(); |
101 | Approximate(navs) | 101 | Approximate(navs) |
102 | } | 102 | } |
103 | 103 | ||
104 | pub(crate) fn name_definition( | 104 | fn name_definition( |
105 | db: &RootDatabase, | 105 | sb: &mut SourceBinder<RootDatabase>, |
106 | name: InFile<&ast::Name>, | 106 | name: InFile<&ast::Name>, |
107 | ) -> Option<Vec<NavigationTarget>> { | 107 | ) -> Option<Vec<NavigationTarget>> { |
108 | let parent = name.value.syntax().parent()?; | 108 | let parent = name.value.syntax().parent()?; |
@@ -110,14 +110,14 @@ pub(crate) fn name_definition( | |||
110 | if let Some(module) = ast::Module::cast(parent.clone()) { | 110 | if let Some(module) = ast::Module::cast(parent.clone()) { |
111 | if module.has_semi() { | 111 | if module.has_semi() { |
112 | let src = name.with_value(module); | 112 | let src = name.with_value(module); |
113 | if let Some(child_module) = hir::Module::from_declaration(db, src) { | 113 | if let Some(child_module) = sb.to_def(src) { |
114 | let nav = child_module.to_nav(db); | 114 | let nav = child_module.to_nav(sb.db); |
115 | return Some(vec![nav]); | 115 | return Some(vec![nav]); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | if let Some(nav) = named_target(db, name.with_value(&parent)) { | 120 | if let Some(nav) = named_target(sb.db, name.with_value(&parent)) { |
121 | return Some(vec![nav]); | 121 | return Some(vec![nav]); |
122 | } | 122 | } |
123 | 123 | ||
diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs index 31195036e..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::{FromSource, ImplBlock}; | 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 | ||
@@ -12,22 +12,19 @@ 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 krate = sb.to_module_def(position.file_id)?.krate(); |
17 | let module = hir::Module::from_definition( | ||
18 | db, | ||
19 | hir::InFile { file_id: position.file_id.into(), value: src }, | ||
20 | )?; | ||
21 | 18 | ||
22 | 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) { |
23 | return Some(RangeInfo::new( | 20 | return Some(RangeInfo::new( |
24 | nominal_def.syntax().text_range(), | 21 | nominal_def.syntax().text_range(), |
25 | impls_for_def(db, position, &nominal_def, module)?, | 22 | impls_for_def(&mut sb, position, &nominal_def, krate)?, |
26 | )); | 23 | )); |
27 | } 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) { |
28 | return Some(RangeInfo::new( | 25 | return Some(RangeInfo::new( |
29 | trait_def.syntax().text_range(), | 26 | trait_def.syntax().text_range(), |
30 | impls_for_trait(db, position, &trait_def, module)?, | 27 | impls_for_trait(&mut sb, position, &trait_def, krate)?, |
31 | )); | 28 | )); |
32 | } | 29 | } |
33 | 30 | ||
@@ -35,51 +32,49 @@ pub(crate) fn goto_implementation( | |||
35 | } | 32 | } |
36 | 33 | ||
37 | fn impls_for_def( | 34 | fn impls_for_def( |
38 | db: &RootDatabase, | 35 | sb: &mut SourceBinder<RootDatabase>, |
39 | position: FilePosition, | 36 | position: FilePosition, |
40 | node: &ast::NominalDef, | 37 | node: &ast::NominalDef, |
41 | module: hir::Module, | 38 | krate: Crate, |
42 | ) -> Option<Vec<NavigationTarget>> { | 39 | ) -> Option<Vec<NavigationTarget>> { |
43 | let ty = match node { | 40 | let ty = match node { |
44 | ast::NominalDef::StructDef(def) => { | 41 | ast::NominalDef::StructDef(def) => { |
45 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; | 42 | let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; |
46 | hir::Struct::from_source(db, src)?.ty(db) | 43 | sb.to_def(src)?.ty(sb.db) |
47 | } | 44 | } |
48 | ast::NominalDef::EnumDef(def) => { | 45 | ast::NominalDef::EnumDef(def) => { |
49 | 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() }; |
50 | hir::Enum::from_source(db, src)?.ty(db) | 47 | sb.to_def(src)?.ty(sb.db) |
51 | } | 48 | } |
52 | ast::NominalDef::UnionDef(def) => { | 49 | ast::NominalDef::UnionDef(def) => { |
53 | 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() }; |
54 | hir::Union::from_source(db, src)?.ty(db) | 51 | sb.to_def(src)?.ty(sb.db) |
55 | } | 52 | } |
56 | }; | 53 | }; |
57 | 54 | ||
58 | let krate = module.krate(); | 55 | let impls = ImplBlock::all_in_crate(sb.db, krate); |
59 | let impls = ImplBlock::all_in_crate(db, krate); | ||
60 | 56 | ||
61 | Some( | 57 | Some( |
62 | impls | 58 | impls |
63 | .into_iter() | 59 | .into_iter() |
64 | .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(db))) | 60 | .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(sb.db))) |
65 | .map(|imp| imp.to_nav(db)) | 61 | .map(|imp| imp.to_nav(sb.db)) |
66 | .collect(), | 62 | .collect(), |
67 | ) | 63 | ) |
68 | } | 64 | } |
69 | 65 | ||
70 | fn impls_for_trait( | 66 | fn impls_for_trait( |
71 | db: &RootDatabase, | 67 | sb: &mut SourceBinder<RootDatabase>, |
72 | position: FilePosition, | 68 | position: FilePosition, |
73 | node: &ast::TraitDef, | 69 | node: &ast::TraitDef, |
74 | module: hir::Module, | 70 | krate: Crate, |
75 | ) -> Option<Vec<NavigationTarget>> { | 71 | ) -> Option<Vec<NavigationTarget>> { |
76 | 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() }; |
77 | let tr = hir::Trait::from_source(db, src)?; | 73 | let tr = sb.to_def(src)?; |
78 | 74 | ||
79 | let krate = module.krate(); | 75 | let impls = ImplBlock::for_trait(sb.db, krate, tr); |
80 | let impls = ImplBlock::for_trait(db, krate, tr); | ||
81 | 76 | ||
82 | Some(impls.into_iter().map(|imp| imp.to_nav(db)).collect()) | 77 | Some(impls.into_iter().map(|imp| imp.to_nav(sb.db)).collect()) |
83 | } | 78 | } |
84 | 79 | ||
85 | #[cfg(test)] | 80 | #[cfg(test)] |
@@ -210,7 +205,7 @@ mod tests { | |||
210 | " | 205 | " |
211 | //- /lib.rs | 206 | //- /lib.rs |
212 | #[derive(Copy)] | 207 | #[derive(Copy)] |
213 | struct Foo<|>; | 208 | struct Foo<|>; |
214 | ", | 209 | ", |
215 | &["impl IMPL_BLOCK FileId(1) [0; 15)"], | 210 | &["impl IMPL_BLOCK FileId(1) [0; 15)"], |
216 | ); | 211 | ); |
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index f5a788c07..2dbccfc3b 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs | |||
@@ -1,17 +1,23 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_db::{CrateId, FileId, FilePosition, SourceDatabase}; | 3 | use ra_db::{CrateId, FileId, FilePosition, SourceDatabase}; |
4 | use ra_syntax::{ | ||
5 | algo::find_node_at_offset, | ||
6 | ast::{self, AstNode}, | ||
7 | }; | ||
4 | 8 | ||
5 | use crate::{db::RootDatabase, NavigationTarget}; | 9 | use crate::{db::RootDatabase, NavigationTarget}; |
6 | 10 | ||
7 | /// This returns `Vec` because a module may be included from several places. We | 11 | /// This returns `Vec` because a module may be included from several places. We |
8 | /// don't handle this case yet though, so the Vec has length at most one. | 12 | /// don't handle this case yet though, so the Vec has length at most one. |
9 | pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> { | 13 | pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> { |
10 | let src = hir::ModuleSource::from_position(db, position); | 14 | let mut sb = hir::SourceBinder::new(db); |
11 | let module = match hir::Module::from_definition( | 15 | let parse = db.parse(position.file_id); |
12 | db, | 16 | let module = match find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) { |
13 | hir::InFile { file_id: position.file_id.into(), value: src }, | 17 | Some(module) => sb.to_def(hir::InFile::new(position.file_id.into(), module)), |
14 | ) { | 18 | None => sb.to_module_def(position.file_id), |
19 | }; | ||
20 | let module = match module { | ||
15 | None => return Vec::new(), | 21 | None => return Vec::new(), |
16 | Some(it) => it, | 22 | Some(it) => it, |
17 | }; | 23 | }; |
@@ -21,14 +27,11 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
21 | 27 | ||
22 | /// Returns `Vec` for the same reason as `parent_module` | 28 | /// Returns `Vec` for the same reason as `parent_module` |
23 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { | 29 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { |
24 | let source_file = db.parse(file_id).tree(); | 30 | let mut sb = hir::SourceBinder::new(db); |
25 | let src = hir::ModuleSource::SourceFile(source_file); | 31 | let module = match sb.to_module_def(file_id) { |
26 | let module = | 32 | Some(it) => it, |
27 | match hir::Module::from_definition(db, hir::InFile { file_id: file_id.into(), value: src }) | 33 | None => return Vec::new(), |
28 | { | 34 | }; |
29 | Some(it) => it, | ||
30 | None => return Vec::new(), | ||
31 | }; | ||
32 | let krate = module.krate(); | 35 | let krate = module.krate(); |
33 | vec![krate.into()] | 36 | vec![krate.into()] |
34 | } | 37 | } |
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 4a6e11e27..46cba30a3 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, 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; |
@@ -22,7 +22,7 @@ pub(crate) fn classify_name( | |||
22 | match parent { | 22 | match parent { |
23 | ast::BindPat(it) => { | 23 | ast::BindPat(it) => { |
24 | let src = name.with_value(it); | 24 | let src = name.with_value(it); |
25 | let local = hir::Local::from_source(sb.db, src)?; | 25 | let local = sb.to_def(src)?; |
26 | Some(NameDefinition { | 26 | Some(NameDefinition { |
27 | visibility: None, | 27 | visibility: None, |
28 | container: local.module(sb.db), | 28 | container: local.module(sb.db), |
@@ -35,16 +35,7 @@ pub(crate) fn classify_name( | |||
35 | Some(from_struct_field(sb.db, field)) | 35 | Some(from_struct_field(sb.db, field)) |
36 | }, | 36 | }, |
37 | ast::Module(it) => { | 37 | ast::Module(it) => { |
38 | let def = { | 38 | let def = sb.to_def(name.with_value(it))?; |
39 | if !it.has_semi() { | ||
40 | let ast = hir::ModuleSource::Module(it); | ||
41 | let src = name.with_value(ast); | ||
42 | hir::Module::from_definition(sb.db, src) | ||
43 | } else { | ||
44 | let src = name.with_value(it); | ||
45 | hir::Module::from_declaration(sb.db, src) | ||
46 | } | ||
47 | }?; | ||
48 | Some(from_module_def(sb.db, def.into(), None)) | 39 | Some(from_module_def(sb.db, def.into(), None)) |
49 | }, | 40 | }, |
50 | ast::StructDef(it) => { | 41 | ast::StructDef(it) => { |
@@ -101,10 +92,9 @@ pub(crate) fn classify_name( | |||
101 | }, | 92 | }, |
102 | ast::MacroCall(it) => { | 93 | ast::MacroCall(it) => { |
103 | let src = name.with_value(it); | 94 | let src = name.with_value(it); |
104 | let def = hir::MacroDef::from_source(sb.db, src.clone())?; | 95 | let def = sb.to_def(src.clone())?; |
105 | 96 | ||
106 | let module_src = ModuleSource::from_child_node(sb.db, src.as_ref().map(|it| it.syntax())); | 97 | let module = sb.to_module_def(src.file_id.original_file(sb.db))?; |
107 | let module = Module::from_definition(sb.db, src.with_value(module_src))?; | ||
108 | 98 | ||
109 | Some(NameDefinition { | 99 | Some(NameDefinition { |
110 | visibility: None, | 100 | visibility: None, |
@@ -114,7 +104,7 @@ pub(crate) fn classify_name( | |||
114 | }, | 104 | }, |
115 | ast::TypeParam(it) => { | 105 | ast::TypeParam(it) => { |
116 | let src = name.with_value(it); | 106 | let src = name.with_value(it); |
117 | let def = hir::TypeParam::from_source(sb.db, src)?; | 107 | let def = sb.to_def(src)?; |
118 | Some(NameDefinition { | 108 | Some(NameDefinition { |
119 | visibility: None, | 109 | visibility: None, |
120 | container: def.module(sb.db), | 110 | container: def.module(sb.db), |
@@ -157,10 +147,9 @@ pub(crate) fn classify_name_ref( | |||
157 | } | 147 | } |
158 | } | 148 | } |
159 | 149 | ||
160 | let ast = ModuleSource::from_child_node(sb.db, name_ref.with_value(&parent)); | ||
161 | // FIXME: find correct container and visibility for each case | 150 | // FIXME: find correct container and visibility for each case |
162 | let container = Module::from_definition(sb.db, name_ref.with_value(ast))?; | ||
163 | let visibility = None; | 151 | let visibility = None; |
152 | let container = sb.to_module_def(name_ref.file_id.original_file(sb.db))?; | ||
164 | 153 | ||
165 | if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { | 154 | if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { |
166 | tested_by!(goto_def_for_macros); | 155 | tested_by!(goto_def_for_macros); |
@@ -178,12 +167,13 @@ pub(crate) fn classify_name_ref( | |||
178 | PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))), | 167 | PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))), |
179 | PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)), | 168 | PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)), |
180 | PathResolution::Local(local) => { | 169 | PathResolution::Local(local) => { |
181 | let container = local.module(sb.db); | ||
182 | let kind = NameKind::Local(local); | 170 | let kind = NameKind::Local(local); |
171 | let container = local.module(sb.db); | ||
183 | Some(NameDefinition { kind, container, visibility: None }) | 172 | Some(NameDefinition { kind, container, visibility: None }) |
184 | } | 173 | } |
185 | PathResolution::TypeParam(par) => { | 174 | PathResolution::TypeParam(par) => { |
186 | let kind = NameKind::TypeParam(par); | 175 | let kind = NameKind::TypeParam(par); |
176 | let container = par.module(sb.db); | ||
187 | Some(NameDefinition { kind, container, visibility }) | 177 | Some(NameDefinition { kind, container, visibility }) |
188 | } | 178 | } |
189 | PathResolution::Macro(def) => { | 179 | PathResolution::Macro(def) => { |
diff --git a/crates/ra_ide/src/references/name_definition.rs b/crates/ra_ide/src/references/name_definition.rs index 8c67c8863..1e4226ab9 100644 --- a/crates/ra_ide/src/references/name_definition.rs +++ b/crates/ra_ide/src/references/name_definition.rs | |||
@@ -25,6 +25,8 @@ pub enum NameKind { | |||
25 | #[derive(PartialEq, Eq)] | 25 | #[derive(PartialEq, Eq)] |
26 | pub(crate) struct NameDefinition { | 26 | pub(crate) struct NameDefinition { |
27 | pub visibility: Option<ast::Visibility>, | 27 | pub visibility: Option<ast::Visibility>, |
28 | /// FIXME: this doesn't really make sense. For example, builtin types don't | ||
29 | /// really have a module. | ||
28 | pub container: Module, | 30 | pub container: Module, |
29 | pub kind: NameKind, | 31 | pub kind: NameKind, |
30 | } | 32 | } |
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index e02985dcd..626efb603 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -63,7 +63,7 @@ fn rename_mod( | |||
63 | let mut source_file_edits = Vec::new(); | 63 | let mut source_file_edits = Vec::new(); |
64 | let mut file_system_edits = Vec::new(); | 64 | let mut file_system_edits = Vec::new(); |
65 | let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() }; | 65 | let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() }; |
66 | if let Some(module) = hir::Module::from_declaration(db, module_src) { | 66 | if let Some(module) = hir::SourceBinder::new(db).to_def(module_src) { |
67 | let src = module.definition_source(db); | 67 | let src = module.definition_source(db); |
68 | let file_id = src.file_id.original_file(db); | 68 | let file_id = src.file_id.original_file(db); |
69 | match src.value { | 69 | match src.value { |
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index e213e1a06..7533692f6 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs | |||
@@ -66,8 +66,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti | |||
66 | return None; | 66 | return None; |
67 | } | 67 | } |
68 | let range = module.syntax().text_range(); | 68 | let range = module.syntax().text_range(); |
69 | let src = hir::ModuleSource::from_child_node(db, InFile::new(file_id.into(), &module.syntax())); | 69 | let mut sb = hir::SourceBinder::new(db); |
70 | let module = hir::Module::from_definition(db, InFile::new(file_id.into(), src))?; | 70 | let module = sb.to_def(InFile::new(file_id.into(), module))?; |
71 | 71 | ||
72 | let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); | 72 | let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); |
73 | Some(Runnable { range, kind: RunnableKind::TestMod { path } }) | 73 | Some(Runnable { range, kind: RunnableKind::TestMod { path } }) |