diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 10:50:18 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:34:30 +0000 |
commit | bddd1242986f3155bdb1ca65495bc0623e3d211d (patch) | |
tree | 699b44c6bb2f4978430b3d84994f4f73897241ac /crates | |
parent | 842e8001b287b0e3d77215235ae96a3bd8944207 (diff) |
move crate for
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/imp.rs | 15 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/parent_module.rs | 15 |
3 files changed, 16 insertions, 16 deletions
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index 7d672656f..dea71740c 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs | |||
@@ -10,25 +10,12 @@ use ra_syntax::{ | |||
10 | use ra_db::SourceDatabase; | 10 | use ra_db::SourceDatabase; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | CrateId, db, Diagnostic, FileId, FilePosition, FileSystemEdit, | 13 | db, Diagnostic, FileId, FilePosition, FileSystemEdit, |
14 | Query, SourceChange, SourceFileEdit, | 14 | Query, SourceChange, SourceFileEdit, |
15 | symbol_index::FileSymbol, | 15 | symbol_index::FileSymbol, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | impl db::RootDatabase { | 18 | impl db::RootDatabase { |
19 | /// Returns `Vec` for the same reason as `parent_module` | ||
20 | pub(crate) fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { | ||
21 | let module = match source_binder::module_from_file_id(self, file_id) { | ||
22 | Some(it) => it, | ||
23 | None => return Vec::new(), | ||
24 | }; | ||
25 | let krate = match module.krate(self) { | ||
26 | Some(it) => it, | ||
27 | None => return Vec::new(), | ||
28 | }; | ||
29 | vec![krate.crate_id()] | ||
30 | } | ||
31 | |||
32 | pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { | 19 | pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { |
33 | let file = self.parse(position.file_id); | 20 | let file = self.parse(position.file_id); |
34 | // Find the binding associated with the offset | 21 | // Find the binding associated with the offset |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 22a601ec8..bb60e8d40 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -342,7 +342,7 @@ impl Analysis { | |||
342 | 342 | ||
343 | /// Returns crates this file belongs too. | 343 | /// Returns crates this file belongs too. |
344 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 344 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
345 | self.with_db(|db| db.crate_for(file_id)) | 345 | self.with_db(|db| parent_module::crate_for(db, file_id)) |
346 | } | 346 | } |
347 | 347 | ||
348 | /// Returns the root file of the given crate. | 348 | /// Returns the root file of the given crate. |
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index e94297fe3..603c3db6a 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_db::FilePosition; | 1 | use ra_db::{FilePosition, FileId, CrateId}; |
2 | 2 | ||
3 | use crate::{NavigationTarget, db::RootDatabase}; | 3 | use crate::{NavigationTarget, db::RootDatabase}; |
4 | 4 | ||
@@ -13,6 +13,19 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
13 | vec![nav] | 13 | vec![nav] |
14 | } | 14 | } |
15 | 15 | ||
16 | /// Returns `Vec` for the same reason as `parent_module` | ||
17 | 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) { | ||
19 | Some(it) => it, | ||
20 | None => return Vec::new(), | ||
21 | }; | ||
22 | let krate = match module.krate(db) { | ||
23 | Some(it) => it, | ||
24 | None => return Vec::new(), | ||
25 | }; | ||
26 | vec![krate.crate_id()] | ||
27 | } | ||
28 | |||
16 | #[cfg(test)] | 29 | #[cfg(test)] |
17 | mod tests { | 30 | mod tests { |
18 | use crate::mock_analysis::analysis_and_position; | 31 | use crate::mock_analysis::analysis_and_position; |