mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
move crate to code_model_api
This commit is contained in:
parent
eaf553dade
commit
9a820dc0ee
26
crates/ra_hir/src/code_model_api.rs
Normal file
26
crates/ra_hir/src/code_model_api.rs
Normal 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)
|
||||
}
|
||||
}
|
@ -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);
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user