Skip to content

Commit 5230b7b

Browse files
author
Paolo Tranquilli
committed
Rust: reduce log spam and skip debug diagnostics in the DB
1 parent 45e9c2f commit 5230b7b

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
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: 11 additions & 9 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(),
@@ -189,14 +189,16 @@ impl<'a> Translator<'a> {
189189
start.col + 1,
190190
&error_message
191191
);
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,
199-
);
192+
if severity != DiagnosticSeverity::Debug {
193+
let location = self.trap.emit_location_label(self.label, start, end);
194+
self.trap.emit_diagnostic(
195+
severity,
196+
error_tag,
197+
error_message,
198+
full_error_message,
199+
location,
200+
);
201+
}
200202
}
201203
pub fn emit_parse_error(&mut self, owner: &impl ast::AstNode, err: &SyntaxError) {
202204
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)]
132132
pub enum DiagnosticSeverity {
133133
Debug = 10,
134134
Info = 20,

0 commit comments

Comments
 (0)