Rust: drop tracing:: qualifiers

This commit is contained in:
Arthur Baars
2025-02-11 18:05:15 +01:00
parent c602e82ac4
commit 0442d24204
3 changed files with 25 additions and 35 deletions

View File

@@ -15,7 +15,7 @@ use std::{
collections::HashMap,
path::{Path, PathBuf},
};
use tracing::{info, warn};
use tracing::{error, info, warn};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
@@ -87,7 +87,7 @@ impl<'a> Extractor<'a> {
}
translator.emit_source_file(ast);
translator.trap.commit().unwrap_or_else(|err| {
tracing::error!(
error!(
"Failed to write trap file for: {}: {}",
display_path,
err.to_string()

View File

@@ -21,7 +21,7 @@ use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use tracing::{debug, error, info, warn};
use tracing::{debug, error, info, trace, warn};
use triomphe::Arc;
pub enum RustAnalyzer<'a> {
@@ -51,7 +51,7 @@ impl<'a> RustAnalyzer<'a> {
project: &ProjectManifest,
config: &CargoConfig,
) -> Option<(RootDatabase, Vfs)> {
let progress = |t| (tracing::trace!("progress: {}", t));
let progress = |t| (trace!("progress: {}", t));
let load_config = LoadCargoConfig {
load_out_dirs_from_check: true,
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
@@ -62,7 +62,7 @@ impl<'a> RustAnalyzer<'a> {
match load_workspace_at(manifest.as_ref(), config, &load_config, &progress) {
Ok((db, vfs, _macro_server)) => Some((db, vfs)),
Err(err) => {
tracing::error!("failed to load workspace for {}: {}", manifest, err);
error!("failed to load workspace for {}: {}", manifest, err);
None
}
}

View File

@@ -71,6 +71,18 @@ macro_rules! emit_detached {
($($_:tt)*) => {};
}
// see https://github.com/tokio-rs/tracing/issues/2730
macro_rules! dispatch_to_tracing {
($lvl:ident, $($arg:tt)+) => {
match $lvl {
DiagnosticSeverity::Debug => ::tracing::debug!($($arg)+),
DiagnosticSeverity::Info => ::tracing::info!($($arg)+),
DiagnosticSeverity::Warning => ::tracing::warn!($($arg)+),
DiagnosticSeverity::Error => ::tracing::error!($($arg)+),
}
};
}
pub struct Translator<'a> {
pub trap: TrapFile,
path: &'a str,
@@ -169,36 +181,14 @@ impl<'a> Translator<'a> {
location: (LineCol, LineCol),
) {
let (start, end) = location;
match severity {
DiagnosticSeverity::Debug => tracing::debug!(
"{}:{}:{}: {}",
self.path,
start.line + 1,
start.col + 1,
&full_message
),
DiagnosticSeverity::Info => tracing::info!(
"{}:{}:{}: {}",
self.path,
start.line + 1,
start.col + 1,
&full_message
),
DiagnosticSeverity::Warning => tracing::warn!(
"{}:{}:{}: {}",
self.path,
start.line + 1,
start.col + 1,
&full_message
),
DiagnosticSeverity::Error => tracing::error!(
"{}:{}:{}: {}",
self.path,
start.line + 1,
start.col + 1,
&full_message
),
};
dispatch_to_tracing!(
severity,
"{}:{}:{}: {}",
self.path,
start.line + 1,
start.col + 1,
&full_message,
);
if severity > DiagnosticSeverity::Debug {
let location = self.trap.emit_location_label(self.label, start, end);