mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
fix tests
This commit is contained in:
parent
8c4d277036
commit
61687b9db6
4 changed files with 43 additions and 21 deletions
|
@ -105,39 +105,36 @@ impl db::RootDatabase {
|
||||||
&self,
|
&self,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Vec<NavigationTarget>> {
|
) -> Cancelable<Vec<NavigationTarget>> {
|
||||||
let descr = match source_binder::module_from_position(self, position)? {
|
let module = match source_binder::module_from_position(self, position)? {
|
||||||
None => return Ok(Vec::new()),
|
None => return Ok(Vec::new()),
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
let (file_id, decl) = match descr.parent_link_source(self) {
|
let (file_id, ast_module) = module.source(self);
|
||||||
|
let ast_module = match ast_module {
|
||||||
None => return Ok(Vec::new()),
|
None => return Ok(Vec::new()),
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
let decl = decl.borrowed();
|
let ast_module = ast_module.borrowed();
|
||||||
let decl_name = decl.name().unwrap();
|
let name = ast_module.name().unwrap();
|
||||||
Ok(vec![NavigationTarget {
|
Ok(vec![NavigationTarget {
|
||||||
file_id,
|
file_id,
|
||||||
name: decl_name.text(),
|
name: name.text(),
|
||||||
range: decl_name.syntax().range(),
|
range: name.syntax().range(),
|
||||||
kind: MODULE,
|
kind: MODULE,
|
||||||
ptr: None,
|
ptr: None,
|
||||||
}])
|
}])
|
||||||
}
|
}
|
||||||
/// Returns `Vec` for the same reason as `parent_module`
|
/// Returns `Vec` for the same reason as `parent_module`
|
||||||
pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
||||||
let descr = match source_binder::module_from_file_id(self, file_id)? {
|
let module = match source_binder::module_from_file_id(self, file_id)? {
|
||||||
None => return Ok(Vec::new()),
|
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
|
None => return Ok(Vec::new()),
|
||||||
};
|
};
|
||||||
let root = descr.crate_root();
|
let krate = match module.krate(self)? {
|
||||||
let file_id = root.file_id();
|
Some(it) => it,
|
||||||
|
None => return Ok(Vec::new()),
|
||||||
let crate_graph = self.crate_graph();
|
};
|
||||||
let crate_id = crate_graph.crate_id_for_crate_root(file_id);
|
Ok(vec![krate.crate_id()])
|
||||||
Ok(crate_id.into_iter().collect())
|
|
||||||
}
|
|
||||||
pub(crate) fn crate_root(&self, crate_id: CrateId) -> FileId {
|
|
||||||
self.crate_graph().crate_root(crate_id)
|
|
||||||
}
|
}
|
||||||
pub(crate) fn find_all_refs(
|
pub(crate) fn find_all_refs(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use ra_db::{CrateId, Cancelable};
|
use ra_db::{CrateId, Cancelable, FileId};
|
||||||
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{Name, db::HirDatabase, DefId};
|
use crate::{Name, db::HirDatabase, DefId};
|
||||||
|
|
||||||
|
@ -17,6 +18,9 @@ pub struct CrateDependency {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Crate {
|
impl Crate {
|
||||||
|
pub fn crate_id(&self) -> CrateId {
|
||||||
|
self.crate_id
|
||||||
|
}
|
||||||
pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
|
pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
|
||||||
self.dependencies_impl(db)
|
self.dependencies_impl(db)
|
||||||
}
|
}
|
||||||
|
@ -31,6 +35,10 @@ pub struct Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
|
pub fn source(&self, db: &impl HirDatabase) -> (FileId, Option<ast::ModuleNode>) {
|
||||||
|
self.source_impl(db)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the crate this module is part of.
|
/// Returns the crate this module is part of.
|
||||||
pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
|
pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
|
||||||
self.krate_impl(db)
|
self.krate_impl(db)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use ra_db::{CrateId, Cancelable};
|
use ra_db::{CrateId, Cancelable, FileId};
|
||||||
|
use ra_syntax::{AstNode, ast};
|
||||||
|
|
||||||
use crate::{HirFileId, db::HirDatabase, Crate, CrateDependency, AsName, DefId, DefLoc, DefKind, Name};
|
use crate::{HirFileId, db::HirDatabase, Crate, CrateDependency, AsName, DefId, DefLoc, DefKind, Name};
|
||||||
|
|
||||||
|
@ -48,6 +49,22 @@ impl Module {
|
||||||
crate::code_model_api::Module { def_id }
|
crate::code_model_api::Module { def_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (FileId, Option<ast::ModuleNode>) {
|
||||||
|
let loc = self.def_id.loc(db);
|
||||||
|
let source_item_id = loc.source_item_id;
|
||||||
|
let module = match source_item_id.item_id {
|
||||||
|
None => None,
|
||||||
|
Some(_) => {
|
||||||
|
let syntax_node = db.file_item(source_item_id);
|
||||||
|
let module = ast::Module::cast(syntax_node.borrowed()).unwrap().owned();
|
||||||
|
Some(module)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// FIXME: remove `as_original_file` here
|
||||||
|
let file_id = source_item_id.file_id.as_original_file();
|
||||||
|
(file_id, module)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
|
pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
|
||||||
let root = self.crate_root(db)?;
|
let root = self.crate_root(db)?;
|
||||||
let loc = root.def_id.loc(db);
|
let loc = root.def_id.loc(db);
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn item_map(fixture: &str) -> (Arc<hir::ItemMap>, hir::ModuleId) {
|
||||||
let module = hir::source_binder::module_from_position(&db, pos)
|
let module = hir::source_binder::module_from_position(&db, pos)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let module_id = module.module_id;
|
let module_id = module.def_id.loc(&db).module_id;
|
||||||
(db.item_map(source_root).unwrap(), module_id)
|
(db.item_map(source_root).unwrap(), module_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ fn item_map_across_crates() {
|
||||||
let module = hir::source_binder::module_from_file_id(&db, main_id)
|
let module = hir::source_binder::module_from_file_id(&db, main_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let module_id = module.module_id;
|
let module_id = module.def_id.loc(&db).module_id;
|
||||||
let item_map = db.item_map(source_root).unwrap();
|
let item_map = db.item_map(source_root).unwrap();
|
||||||
|
|
||||||
check_module_item_map(
|
check_module_item_map(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue