mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
move crate for
This commit is contained in:
parent
842e8001b2
commit
bddd124298
3 changed files with 16 additions and 16 deletions
|
@ -10,25 +10,12 @@ use ra_syntax::{
|
||||||
use ra_db::SourceDatabase;
|
use ra_db::SourceDatabase;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CrateId, db, Diagnostic, FileId, FilePosition, FileSystemEdit,
|
db, Diagnostic, FileId, FilePosition, FileSystemEdit,
|
||||||
Query, SourceChange, SourceFileEdit,
|
Query, SourceChange, SourceFileEdit,
|
||||||
symbol_index::FileSymbol,
|
symbol_index::FileSymbol,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl db::RootDatabase {
|
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)> {
|
pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> {
|
||||||
let file = self.parse(position.file_id);
|
let file = self.parse(position.file_id);
|
||||||
// Find the binding associated with the offset
|
// Find the binding associated with the offset
|
||||||
|
|
|
@ -342,7 +342,7 @@ impl Analysis {
|
||||||
|
|
||||||
/// Returns crates this file belongs too.
|
/// Returns crates this file belongs too.
|
||||||
pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
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.
|
/// Returns the root file of the given crate.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_db::FilePosition;
|
use ra_db::{FilePosition, FileId, CrateId};
|
||||||
|
|
||||||
use crate::{NavigationTarget, db::RootDatabase};
|
use crate::{NavigationTarget, db::RootDatabase};
|
||||||
|
|
||||||
|
@ -13,6 +13,19 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
|
||||||
vec![nav]
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::mock_analysis::analysis_and_position;
|
use crate::mock_analysis::analysis_and_position;
|
||||||
|
|
Loading…
Reference in a new issue