Rust: reduce log spam and skip debug diagnostics in the DB

This commit is contained in:
Paolo Tranquilli
2024-10-25 13:46:46 +02:00
parent 45e9c2ff4d
commit 5230b7b041
3 changed files with 28 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
use itertools::Itertools;
use log::info;
use log::{debug, info};
use ra_ap_base_db::SourceDatabase;
use ra_ap_base_db::SourceDatabaseFileInputExt;
use ra_ap_hir::Semantics;
@@ -119,10 +119,21 @@ pub fn find_project_manifests(
.map(|path| AbsPathBuf::assert_utf8(current.join(path)))
.collect();
let ret = ra_ap_project_model::ProjectManifest::discover_all(&abs_files);
info!(
"found manifests: {}",
ret.iter().map(|m| format!("{m}")).join(", ")
);
let iter = || ret.iter().map(|m| format!(" {m}"));
const log_limit: usize = 10;
if ret.len() <= log_limit {
info!("found manifests:\n{}", iter().join("\n"));
} else {
info!(
"found manifests:\n{}\nand {} more",
iter().take(log_limit).join("\n"),
ret.len() - log_limit
);
debug!(
"rest of the manifests found:\n{}",
iter().dropping(log_limit).join("\n")
);
}
Ok(ret)
}
fn from_utf8_lossy(v: &[u8]) -> (Cow<'_, str>, Option<SyntaxError>) {

View File

@@ -142,7 +142,7 @@ impl<'a> Translator<'a> {
self.trap.emit_location(self.label, label, start, end)
} else {
self.emit_diagnostic(
DiagnosticSeverity::Info,
DiagnosticSeverity::Debug,
"locations".to_owned(),
"missing location for AstNode".to_owned(),
"missing location for AstNode".to_owned(),
@@ -189,14 +189,16 @@ impl<'a> Translator<'a> {
start.col + 1,
&error_message
);
let location = self.trap.emit_location_label(self.label, start, end);
self.trap.emit_diagnostic(
severity,
error_tag,
error_message,
full_error_message,
location,
);
if severity != DiagnosticSeverity::Debug {
let location = self.trap.emit_location_label(self.label, start, end);
self.trap.emit_diagnostic(
severity,
error_tag,
error_message,
full_error_message,
location,
);
}
}
pub fn emit_parse_error(&mut self, owner: &impl ast::AstNode, err: &SyntaxError) {
let owner_range: TextRange = owner.syntax().text_range();

View File

@@ -128,7 +128,7 @@ pub struct TrapFile {
compression: Compression,
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum DiagnosticSeverity {
Debug = 10,
Info = 20,