Skip to content

Commit b6def65

Browse files
Merge #6724
6724: Fix `diagnostics` subcommand, look at all modules r=jonas-schievink a=jonas-schievink The `diagnostics` subcommand used to only compute diagnostics for `lib.rs` / the root module of all workspace crates. This fixed it and makes it look at every module. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 7efab3e + e45ab7e commit b6def65

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

crates/rust-analyzer/src/cli/diagnostics.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@ use std::path::Path;
66
use anyhow::anyhow;
77
use rustc_hash::FxHashSet;
88

9-
use hir::Crate;
9+
use hir::{db::HirDatabase, Crate, Module};
1010
use ide::{DiagnosticsConfig, Severity};
1111
use ide_db::base_db::SourceDatabaseExt;
1212

1313
use crate::cli::{load_cargo::load_cargo, Result};
1414

15+
fn all_modules(db: &dyn HirDatabase) -> Vec<Module> {
16+
let mut worklist: Vec<_> =
17+
Crate::all(db).into_iter().map(|krate| krate.root_module(db)).collect();
18+
let mut modules = Vec::new();
19+
20+
while let Some(module) = worklist.pop() {
21+
modules.push(module);
22+
worklist.extend(module.children(db));
23+
}
24+
25+
modules
26+
}
27+
1528
pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> {
1629
let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
1730
let db = host.raw_database();
@@ -20,18 +33,12 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -
2033
let mut found_error = false;
2134
let mut visited_files = FxHashSet::default();
2235

23-
let mut work = Vec::new();
24-
let krates = Crate::all(db);
25-
for krate in krates {
26-
let module = krate.root_module(db);
27-
let file_id = module.definition_source(db).file_id;
28-
let file_id = file_id.original_file(db);
36+
let work = all_modules(db).into_iter().filter(|module| {
37+
let file_id = module.definition_source(db).file_id.original_file(db);
2938
let source_root = db.file_source_root(file_id);
3039
let source_root = db.source_root(source_root);
31-
if !source_root.is_library {
32-
work.push(module);
33-
}
34-
}
40+
!source_root.is_library
41+
});
3542

3643
for module in work {
3744
let file_id = module.definition_source(db).file_id.original_file(db);

0 commit comments

Comments
 (0)