aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs6
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs40
2 files changed, 27 insertions, 19 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 9baebf643..3801fce23 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -25,7 +25,7 @@ use hir_ty::{
25 autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, 25 autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy,
26 Canonical, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, 26 Canonical, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor,
27}; 27};
28use ra_db::{CrateId, Edition, FileId}; 28use ra_db::{CrateId, CrateName, Edition, FileId};
29use ra_prof::profile; 29use ra_prof::profile;
30use ra_syntax::{ 30use ra_syntax::{
31 ast::{self, AttrsOwner, NameOwner}, 31 ast::{self, AttrsOwner, NameOwner},
@@ -91,6 +91,10 @@ impl Crate {
91 db.crate_graph()[self.id].edition 91 db.crate_graph()[self.id].edition
92 } 92 }
93 93
94 pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
95 db.crate_graph()[self.id].display_name.as_ref().cloned()
96 }
97
94 pub fn all(db: &dyn HirDatabase) -> Vec<Crate> { 98 pub fn all(db: &dyn HirDatabase) -> Vec<Crate> {
95 db.crate_graph().iter().map(|id| Crate { id }).collect() 99 db.crate_graph().iter().map(|id| Crate { id }).collect()
96 } 100 }
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 2d92c1f78..92664b415 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -2,7 +2,7 @@
2//! code if any errors are found. 2//! code if any errors are found.
3 3
4use anyhow::anyhow; 4use anyhow::anyhow;
5use ra_db::{SourceDatabase, SourceDatabaseExt}; 5use ra_db::SourceDatabaseExt;
6use ra_ide::Severity; 6use ra_ide::Severity;
7use std::{collections::HashSet, path::Path}; 7use std::{collections::HashSet, path::Path};
8 8
@@ -28,28 +28,32 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, all: bool) -> Result<()>
28 28
29 let mut found_error = false; 29 let mut found_error = false;
30 let mut visited_files = HashSet::new(); 30 let mut visited_files = HashSet::new();
31 let crate_graph = db.crate_graph(); 31 for source_root_id in members {
32 for crate_id in crate_graph.iter() { 32 for file_id in db.source_root(source_root_id).walk() {
33 let krate = &crate_graph[crate_id];
34 if let Some(crate_name) = &krate.display_name {
35 println!("processing crate: {}", crate_name);
36 } else {
37 println!("processing crate: unknown");
38 }
39 for file_id in db.source_root(db.file_source_root(krate.root_file_id)).walk() {
40 // Filter out files which are not actually modules (unless `--all` flag is 33 // Filter out files which are not actually modules (unless `--all` flag is
41 // passed). In the rust-analyzer repository this filters out the parser test files. 34 // passed). In the rust-analyzer repository this filters out the parser test files.
42 if semantics.to_module_def(file_id).is_some() || all { 35 if semantics.to_module_def(file_id).is_some() || all {
43 if !visited_files.contains(&file_id) { 36 if !visited_files.contains(&file_id) {
44 if members.contains(&db.file_source_root(file_id)) { 37 let crate_name = if let Some(module) = semantics.to_module_def(file_id) {
45 println!("processing module: {}", db.file_relative_path(file_id)); 38 if let Some(name) = module.krate().display_name(db) {
46 for diagnostic in analysis.diagnostics(file_id).unwrap() { 39 format!("{}", name)
47 if matches!(diagnostic.severity, Severity::Error) { 40 } else {
48 found_error = true; 41 String::from("unknown")
49 }
50
51 println!("{:?}", diagnostic);
52 } 42 }
43 } else {
44 String::from("unknown")
45 };
46 println!(
47 "processing crate: {}, module: {}",
48 crate_name,
49 db.file_relative_path(file_id)
50 );
51 for diagnostic in analysis.diagnostics(file_id).unwrap() {
52 if matches!(diagnostic.severity, Severity::Error) {
53 found_error = true;
54 }
55
56 println!("{:?}", diagnostic);
53 } 57 }
54 58
55 visited_files.insert(file_id); 59 visited_files.insert(file_id);