From e45ab7e0ecb681a2d19bd94fb0b2c09b88309319 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 4 Dec 2020 19:37:37 +0100 Subject: Fix `diagnostics` subcommand, look at all modules --- crates/rust-analyzer/src/cli/diagnostics.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 368f627ac..0090fd2c2 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs @@ -6,12 +6,25 @@ use std::path::Path; use anyhow::anyhow; use rustc_hash::FxHashSet; -use hir::Crate; +use hir::{db::HirDatabase, Crate, Module}; use ide::{DiagnosticsConfig, Severity}; use ide_db::base_db::SourceDatabaseExt; use crate::cli::{load_cargo::load_cargo, Result}; +fn all_modules(db: &dyn HirDatabase) -> Vec { + let mut worklist: Vec<_> = + Crate::all(db).into_iter().map(|krate| krate.root_module(db)).collect(); + let mut modules = Vec::new(); + + while let Some(module) = worklist.pop() { + modules.push(module); + worklist.extend(module.children(db)); + } + + modules +} + pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; let db = host.raw_database(); @@ -20,18 +33,12 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) - let mut found_error = false; let mut visited_files = FxHashSet::default(); - let mut work = Vec::new(); - let krates = Crate::all(db); - for krate in krates { - let module = krate.root_module(db); - let file_id = module.definition_source(db).file_id; - let file_id = file_id.original_file(db); + let work = all_modules(db).into_iter().filter(|module| { + let file_id = module.definition_source(db).file_id.original_file(db); let source_root = db.file_source_root(file_id); let source_root = db.source_root(source_root); - if !source_root.is_library { - work.push(module); - } - } + !source_root.is_library + }); for module in work { let file_id = module.definition_source(db).file_id.original_file(db); -- cgit v1.2.3