use std::path::Path;
use anyhow::Result;
use ra_ap_hir::{self as hir};
use ra_ap_ide::{self as ide};
pub use crate::{
analyzer::LoadOptions,
item::Item,
options::{GeneralOptions, ProjectOptions},
tree::{ModuleTree, Tree, TreeBuilder},
};
pub mod analyzer;
pub mod item;
pub mod options;
pub mod tree;
pub mod utils;
mod colors;
mod graph;
#[derive(Debug, Clone)]
pub struct AnalysisConfig {
pub cfg_test: bool,
pub sysroot: bool,
pub no_default_features: bool,
pub all_features: bool,
pub features: Vec<String>,
}
impl Default for AnalysisConfig {
fn default() -> Self {
Self::fast()
}
}
impl AnalysisConfig {
pub fn fast() -> Self {
Self {
cfg_test: false,
sysroot: false,
no_default_features: true, all_features: false,
features: vec![],
}
}
pub fn standard() -> Self {
Self {
cfg_test: false,
sysroot: false,
no_default_features: false,
all_features: false,
features: vec![],
}
}
pub fn ultra_fast() -> Self {
Self {
cfg_test: false,
sysroot: false,
no_default_features: true, all_features: false, features: vec![], }
}
}
pub fn analyze_crate(
path: &Path,
package: Option<&str>,
config: AnalysisConfig,
) -> Result<(hir::Crate, ide::AnalysisHost, ide::Edition)> {
let general_options = GeneralOptions { verbose: false };
let project_options = ProjectOptions {
lib: false,
bin: None,
package: package.map(|p| p.to_string()),
no_default_features: config.no_default_features,
all_features: config.all_features,
features: config.features,
target: None,
manifest_path: path.to_path_buf(),
};
let load_options = LoadOptions {
cfg_test: config.cfg_test,
sysroot: config.sysroot,
};
let (crate_id, analysis_host, _vfs, edition) =
analyzer::load_workspace(&general_options, &project_options, &load_options)?;
Ok((crate_id, analysis_host, edition))
}
pub fn build_module_tree(
crate_id: hir::Crate,
db: &ide::RootDatabase,
edition: ide::Edition,
) -> Result<ModuleTree> {
ModuleTree::build(db, &crate_id, edition)
}
pub fn detect_orphans(path: &Path) -> Result<Vec<std::path::PathBuf>> {
let _ = path;
Ok(vec![])
}