diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-19 19:18:41 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-19 19:18:41 +0100 |
commit | cd9b222ba0555424d73d549eac43d9aaf1765d7d (patch) | |
tree | 88eea12084b65ba7b0f808cc2c626c7b57c7ac53 /crates/ra_ide_api/src/parent_module.rs | |
parent | 44bab3621d74f1aec922300a3b3f4476907ba2ac (diff) | |
parent | 2867c40925e8f7b440ff50a421a2d3726b9ff334 (diff) |
Merge #1853
1853: Introduce FromSource trait r=matklad a=viorina
The idea is to provide an ability to get HIR from AST in a more general way than it's possible using `source_binder`.
It also could help with #1622 fixing.
Co-authored-by: Ekaterina Babshukova <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/parent_module.rs')
-rw-r--r-- | crates/ra_ide_api/src/parent_module.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 7d5f9ea2c..3668da8d7 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs | |||
@@ -5,7 +5,11 @@ use crate::{db::RootDatabase, NavigationTarget}; | |||
5 | /// This returns `Vec` because a module may be included from several places. We | 5 | /// This returns `Vec` because a module may be included from several places. We |
6 | /// don't handle this case yet though, so the Vec has length at most one. | 6 | /// don't handle this case yet though, so the Vec has length at most one. |
7 | pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> { | 7 | pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> { |
8 | let module = match hir::source_binder::module_from_position(db, position) { | 8 | let src = hir::ModuleSource::from_position(db, position); |
9 | let module = match hir::Module::from_definition( | ||
10 | db, | ||
11 | hir::Source { file_id: position.file_id.into(), ast: src }, | ||
12 | ) { | ||
9 | None => return Vec::new(), | 13 | None => return Vec::new(), |
10 | Some(it) => it, | 14 | Some(it) => it, |
11 | }; | 15 | }; |
@@ -15,10 +19,12 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
15 | 19 | ||
16 | /// Returns `Vec` for the same reason as `parent_module` | 20 | /// Returns `Vec` for the same reason as `parent_module` |
17 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { | 21 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { |
18 | let module = match hir::source_binder::module_from_file_id(db, file_id) { | 22 | let src = hir::ModuleSource::from_file_id(db, file_id); |
19 | Some(it) => it, | 23 | let module = |
20 | None => return Vec::new(), | 24 | match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), ast: src }) { |
21 | }; | 25 | Some(it) => it, |
26 | None => return Vec::new(), | ||
27 | }; | ||
22 | let krate = match module.krate(db) { | 28 | let krate = match module.krate(db) { |
23 | Some(it) => it, | 29 | Some(it) => it, |
24 | None => return Vec::new(), | 30 | None => return Vec::new(), |