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<CrateId> {
- 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
/// Returns crates this file belongs too.
pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
- 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.
-use ra_db::FilePosition;
+use ra_db::{FilePosition, FileId, CrateId};
use crate::{NavigationTarget, db::RootDatabase};
vec![nav]
}
+/// Returns `Vec` for the same reason as `parent_module`
+pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
+ 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;