Skip to content

Commit 01820c5

Browse files
committed
emmylua_check: print summary of diagnostics
Resolves #508
1 parent 5e37f50 commit 01820c5

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

crates/emmylua_check/src/cmd_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct CmdArgs {
4141
pub verbose: bool,
4242
}
4343

44-
#[derive(Debug, Clone)]
44+
#[derive(Debug, Clone, PartialEq)]
4545
pub enum OutputFormat {
4646
Json,
4747
Text,

crates/emmylua_check/src/output/mod.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,33 @@ pub async fn output_result(
2525

2626
let mut has_error = false;
2727
let mut count = 0;
28+
let mut error_count = 0;
29+
let mut warning_count = 0;
30+
let mut info_count = 0;
31+
let mut hint_count = 0;
32+
2833
while let Some((file_id, diagnostics)) = receiver.recv().await {
2934
count += 1;
3035
if let Some(diagnostics) = diagnostics {
3136
for diagnostic in &diagnostics {
32-
if diagnostic.severity == Some(lsp_types::DiagnosticSeverity::ERROR) {
33-
has_error = true;
34-
break;
35-
} else if warnings_as_errors
36-
&& diagnostic.severity == Some(lsp_types::DiagnosticSeverity::WARNING)
37-
{
38-
has_error = true;
39-
break;
37+
match diagnostic.severity {
38+
Some(lsp_types::DiagnosticSeverity::ERROR) => {
39+
has_error = true;
40+
error_count += 1;
41+
}
42+
Some(lsp_types::DiagnosticSeverity::WARNING) => {
43+
if warnings_as_errors {
44+
has_error = true;
45+
}
46+
warning_count += 1;
47+
}
48+
Some(lsp_types::DiagnosticSeverity::INFORMATION) => {
49+
info_count += 1;
50+
}
51+
Some(lsp_types::DiagnosticSeverity::HINT) => {
52+
hint_count += 1;
53+
}
54+
_ => {}
4055
}
4156
}
4257
writer.write(db, file_id, diagnostics);
@@ -49,6 +64,21 @@ pub async fn output_result(
4964

5065
writer.finish();
5166

67+
if output_format == OutputFormat::Text {
68+
if error_count > 0 {
69+
println!("Errors: {}", error_count);
70+
}
71+
if warning_count > 0 {
72+
println!("Warnings: {}", warning_count);
73+
}
74+
if info_count > 0 {
75+
println!("Information: {}", info_count);
76+
}
77+
if hint_count > 0 {
78+
println!("Hints: {}", hint_count);
79+
}
80+
}
81+
5282
if has_error {
5383
1
5484
} else {

0 commit comments

Comments
 (0)