diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-04 18:39:04 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-04 18:39:04 +0000 |
commit | b6def6575cc0d1534f1fd9dcd04aa3fc40620e88 (patch) | |
tree | 3c7225d32f405ea993583bbe9c8e7efe69babd04 | |
parent | 7efab3ed032e84ae8d8acf807aeb914365a9ac50 (diff) | |
parent | e45ab7e0ecb681a2d19bd94fb0b2c09b88309319 (diff) |
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]>
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 29 |
1 files changed, 18 insertions, 11 deletions
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; | |||
6 | use anyhow::anyhow; | 6 | use anyhow::anyhow; |
7 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::FxHashSet; |
8 | 8 | ||
9 | use hir::Crate; | 9 | use hir::{db::HirDatabase, Crate, Module}; |
10 | use ide::{DiagnosticsConfig, Severity}; | 10 | use ide::{DiagnosticsConfig, Severity}; |
11 | use ide_db::base_db::SourceDatabaseExt; | 11 | use ide_db::base_db::SourceDatabaseExt; |
12 | 12 | ||
13 | use crate::cli::{load_cargo::load_cargo, Result}; | 13 | use crate::cli::{load_cargo::load_cargo, Result}; |
14 | 14 | ||
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 | |||
15 | pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { | 28 | pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { |
16 | let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; | 29 | let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; |
17 | let db = host.raw_database(); | 30 | let db = host.raw_database(); |
@@ -20,18 +33,12 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) - | |||
20 | let mut found_error = false; | 33 | let mut found_error = false; |
21 | let mut visited_files = FxHashSet::default(); | 34 | let mut visited_files = FxHashSet::default(); |
22 | 35 | ||
23 | let mut work = Vec::new(); | 36 | let work = all_modules(db).into_iter().filter(|module| { |
24 | let krates = Crate::all(db); | 37 | let file_id = module.definition_source(db).file_id.original_file(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); | ||
29 | let source_root = db.file_source_root(file_id); | 38 | let source_root = db.file_source_root(file_id); |
30 | let source_root = db.source_root(source_root); | 39 | let source_root = db.source_root(source_root); |
31 | if !source_root.is_library { | 40 | !source_root.is_library |
32 | work.push(module); | 41 | }); |
33 | } | ||
34 | } | ||
35 | 42 | ||
36 | for module in work { | 43 | for module in work { |
37 | let file_id = module.definition_source(db).file_id.original_file(db); | 44 | let file_id = module.definition_source(db).file_id.original_file(db); |