Skip to content

Commit ab1b48d

Browse files
authored
Merge pull request github#17843 from github/redsun82/reduce-log-noise
Rust: reduce log spam and skip debug diagnostics in the DB
2 parents c5da712 + a760b89 commit ab1b48d

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

rust/extractor/src/rust_analyzer.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use itertools::Itertools;
2-
use log::info;
2+
use log::{debug, info};
33
use ra_ap_base_db::SourceDatabase;
44
use ra_ap_base_db::SourceDatabaseFileInputExt;
55
use ra_ap_hir::Semantics;
@@ -119,10 +119,21 @@ pub fn find_project_manifests(
119119
.map(|path| AbsPathBuf::assert_utf8(current.join(path)))
120120
.collect();
121121
let ret = ra_ap_project_model::ProjectManifest::discover_all(&abs_files);
122-
info!(
123-
"found manifests: {}",
124-
ret.iter().map(|m| format!("{m}")).join(", ")
125-
);
122+
let iter = || ret.iter().map(|m| format!(" {m}"));
123+
const LOG_LIMIT: usize = 10;
124+
if ret.len() <= LOG_LIMIT {
125+
info!("found manifests:\n{}", iter().join("\n"));
126+
} else {
127+
info!(
128+
"found manifests:\n{}\nand {} more",
129+
iter().take(LOG_LIMIT).join("\n"),
130+
ret.len() - LOG_LIMIT
131+
);
132+
debug!(
133+
"rest of the manifests found:\n{}",
134+
iter().dropping(LOG_LIMIT).join("\n")
135+
);
136+
}
126137
Ok(ret)
127138
}
128139
fn from_utf8_lossy(v: &[u8]) -> (Cow<'_, str>, Option<SyntaxError>) {

rust/extractor/src/translate/base.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a> Translator<'a> {
142142
self.trap.emit_location(self.label, label, start, end)
143143
} else {
144144
self.emit_diagnostic(
145-
DiagnosticSeverity::Info,
145+
DiagnosticSeverity::Debug,
146146
"locations".to_owned(),
147147
"missing location for AstNode".to_owned(),
148148
"missing location for AstNode".to_owned(),
@@ -169,9 +169,9 @@ impl<'a> Translator<'a> {
169169
pub fn emit_diagnostic(
170170
&mut self,
171171
severity: DiagnosticSeverity,
172-
error_tag: String,
173-
error_message: String,
174-
full_error_message: String,
172+
tag: String,
173+
message: String,
174+
full_message: String,
175175
location: (LineCol, LineCol),
176176
) {
177177
let (start, end) = location;
@@ -187,16 +187,13 @@ impl<'a> Translator<'a> {
187187
self.path,
188188
start.line + 1,
189189
start.col + 1,
190-
&error_message
191-
);
192-
let location = self.trap.emit_location_label(self.label, start, end);
193-
self.trap.emit_diagnostic(
194-
severity,
195-
error_tag,
196-
error_message,
197-
full_error_message,
198-
location,
190+
&message
199191
);
192+
if severity > DiagnosticSeverity::Debug {
193+
let location = self.trap.emit_location_label(self.label, start, end);
194+
self.trap
195+
.emit_diagnostic(severity, tag, message, full_message, location);
196+
}
200197
}
201198
pub fn emit_parse_error(&mut self, owner: &impl ast::AstNode, err: &SyntaxError) {
202199
let owner_range: TextRange = owner.syntax().text_range();

rust/extractor/src/trap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub struct TrapFile {
128128
compression: Compression,
129129
}
130130

131-
#[derive(Copy, Clone)]
131+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
132132
pub enum DiagnosticSeverity {
133133
Debug = 10,
134134
Info = 20,

0 commit comments

Comments
 (0)