From bddd1242986f3155bdb1ca65495bc0623e3d211d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 13:50:18 +0300 Subject: [PATCH] move crate for --- crates/ra_ide_api/src/imp.rs | 15 +-------------- crates/ra_ide_api/src/lib.rs | 2 +- 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 7d672656f7..dea71740cc 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs @@ -10,25 +10,12 @@ use ra_syntax::{ use ra_db::SourceDatabase; use crate::{ - CrateId, db, Diagnostic, FileId, FilePosition, FileSystemEdit, + db, Diagnostic, FileId, FilePosition, FileSystemEdit, Query, SourceChange, SourceFileEdit, symbol_index::FileSymbol, }; impl db::RootDatabase { - /// Returns `Vec` for the same reason as `parent_module` - pub(crate) fn crate_for(&self, file_id: FileId) -> Vec { - let module = match source_binder::module_from_file_id(self, file_id) { - Some(it) => it, - None => return Vec::new(), - }; - let krate = match module.krate(self) { - Some(it) => it, - None => return Vec::new(), - }; - vec![krate.crate_id()] - } - pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { let file = self.parse(position.file_id); // 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 22a601ec81..bb60e8d404 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -342,7 +342,7 @@ impl Analysis { /// Returns crates this file belongs too. pub fn crate_for(&self, file_id: FileId) -> Cancelable> { - self.with_db(|db| db.crate_for(file_id)) + self.with_db(|db| parent_module::crate_for(db, file_id)) } /// 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 e94297fe38..603c3db6ae 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs @@ -1,4 +1,4 @@ -use ra_db::FilePosition; +use ra_db::{FilePosition, FileId, CrateId}; use crate::{NavigationTarget, db::RootDatabase}; @@ -13,6 +13,19 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec Vec { + let module = match hir::source_binder::module_from_file_id(db, file_id) { + Some(it) => it, + None => return Vec::new(), + }; + let krate = match module.krate(db) { + Some(it) => it, + None => return Vec::new(), + }; + vec![krate.crate_id()] +} + #[cfg(test)] mod tests { use crate::mock_analysis::analysis_and_position;