mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
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 <jonasschievink@gmail.com>
This commit is contained in:
commit
b6def6575c
@ -6,12 +6,25 @@ use std::path::Path;
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use hir::Crate;
|
use hir::{db::HirDatabase, Crate, Module};
|
||||||
use ide::{DiagnosticsConfig, Severity};
|
use ide::{DiagnosticsConfig, Severity};
|
||||||
use ide_db::base_db::SourceDatabaseExt;
|
use ide_db::base_db::SourceDatabaseExt;
|
||||||
|
|
||||||
use crate::cli::{load_cargo::load_cargo, Result};
|
use crate::cli::{load_cargo::load_cargo, Result};
|
||||||
|
|
||||||
|
fn all_modules(db: &dyn HirDatabase) -> Vec<Module> {
|
||||||
|
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<()> {
|
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 (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
|
||||||
let db = host.raw_database();
|
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 found_error = false;
|
||||||
let mut visited_files = FxHashSet::default();
|
let mut visited_files = FxHashSet::default();
|
||||||
|
|
||||||
let mut work = Vec::new();
|
let work = all_modules(db).into_iter().filter(|module| {
|
||||||
let krates = Crate::all(db);
|
let file_id = module.definition_source(db).file_id.original_file(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 source_root = db.file_source_root(file_id);
|
let source_root = db.file_source_root(file_id);
|
||||||
let source_root = db.source_root(source_root);
|
let source_root = db.source_root(source_root);
|
||||||
if !source_root.is_library {
|
!source_root.is_library
|
||||||
work.push(module);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for module in work {
|
for module in work {
|
||||||
let file_id = module.definition_source(db).file_id.original_file(db);
|
let file_id = module.definition_source(db).file_id.original_file(db);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user