move crate to code_model_api

This commit is contained in:
Aleksey Kladov 2019-01-05 00:02:05 +03:00
parent eaf553dade
commit 9a820dc0ee
3 changed files with 34 additions and 21 deletions

View File

@ -0,0 +1,26 @@
use ra_db::{CrateId, Cancelable};
use crate::{Module, Name, db::HirDatabase};
/// hir::Crate describes a single crate. It's the main inteface with which
/// crate's dependencies interact. Mostly, it should be just a proxy for the
/// root module.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Crate {
pub(crate) crate_id: CrateId,
}
#[derive(Debug)]
pub struct CrateDependency {
pub krate: Crate,
pub name: Name,
}
impl Crate {
pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
self.dependencies_impl(db)
}
pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
self.root_module_impl(db)
}
}

View File

@ -1,26 +1,12 @@
pub use ra_db::{CrateId, Cancelable};
use ra_db::{CrateId, Cancelable};
use crate::{HirDatabase, Module, Name, AsName, HirFileId};
/// hir::Crate describes a single crate. It's the main inteface with which
/// crate's dependencies interact. Mostly, it should be just a proxy for the
/// root module.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Crate {
crate_id: CrateId,
}
#[derive(Debug)]
pub struct CrateDependency {
pub krate: Crate,
pub name: Name,
}
use crate::{Module, HirFileId, db::HirDatabase, Crate, CrateDependency, AsName};
impl Crate {
pub(crate) fn new(crate_id: CrateId) -> Crate {
Crate { crate_id }
}
pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
let crate_graph = db.crate_graph();
crate_graph
.dependencies(self.crate_id)
@ -31,7 +17,7 @@ impl Crate {
})
.collect()
}
pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
let crate_graph = db.crate_graph();
let file_id = crate_graph.crate_root(self.crate_id);
let source_root_id = db.file_source_root(file_id);

View File

@ -24,8 +24,6 @@ pub mod source_binder;
mod ids;
mod macros;
mod name;
// can't use `crate` or `r#crate` here :(
mod krate;
mod module;
mod function;
mod adt;
@ -34,16 +32,19 @@ mod ty;
mod impl_block;
mod expr;
pub mod code_model_api;
mod code_model_impl;
use crate::{
db::HirDatabase,
name::{AsName, KnownName},
ids::{DefKind, SourceItemId, SourceFileItemId, SourceFileItems},
code_model_api::{Crate, CrateDependency}
};
pub use self::{
path::{Path, PathKind},
name::Name,
krate::Crate,
ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc},
macros::{MacroDef, MacroInput, MacroExpansion},
module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution},