Skip to content

Commit

Permalink
Add some logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 7, 2024
1 parent 9587230 commit 268088c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 7 deletions.
11 changes: 6 additions & 5 deletions crates/red_knot/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ impl Verbosity {

#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub(crate) enum VerbosityLevel {
/// Default output level. Only shows ruff and red knot events up to the [`LogLevel::Warn`].
/// Default output level. Only shows Ruff and Red Knot events up to the [`WARN`](tracing::Level::WARN).
Default,

/// Enables verbose output. Emits ruff and red knot events up to the [`LogLevel::Info`]
/// Enables verbose output. Emits Ruff and Red Knot events up to the [`INFO`](tracing::Level::INFO)
Verbose,

/// Enables a more verbose tracing format and emits ruff and red_knot events up to [`LogLevel::Debug`] Corresponds to `-vv`
/// Enables a more verbose tracing format and emits Ruff and Red Knot events up to [`DEBUG`](tracing::Level::DEBUG) Corresponds to `-vv`
ExtraVerbose,

/// Enables all tracing events and uses a tree like output format. Corresponds to `-vvv`.
/// Enables all tracing events and uses a tree-like output format. Corresponds to `-vvv`.
Trace,
}

Expand Down Expand Up @@ -145,6 +145,7 @@ pub(crate) fn setup_tracing(level: VerbosityLevel) -> anyhow::Result<TracingGuar
})
}

#[allow(clippy::type_complexity)]
fn setup_profile<S>() -> (
Option<tracing_flame::FlameLayer<S, BufWriter<File>>>,
Option<tracing_flame::FlushGuard<BufWriter<File>>>,
Expand Down Expand Up @@ -208,7 +209,7 @@ where
let formatted_level = level.to_string();
match *level {
tracing::Level::TRACE => {
write!(writer, "{} ", formatted_level.purple().bold())?
write!(writer, "{} ", formatted_level.purple().bold())?;
}
tracing::Level::DEBUG => write!(writer, "{} ", formatted_level.blue().bold())?,
tracing::Level::INFO => write!(writer, "{} ", formatted_level.green().bold())?,
Expand Down
1 change: 1 addition & 0 deletions crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl MainLoop {
let is_trace = self.verbosity.is_trace();
self.run(db);

#[allow(clippy::print_stderr)]
if is_trace {
eprintln!("Exit");
eprintln!("{}", countme::get_all());
Expand Down
10 changes: 9 additions & 1 deletion crates/red_knot_module_resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ pub(crate) fn resolve_module_query<'db>(
let name = module_name.name(db);
let _span = tracing::trace_span!("resolve_module", %name).entered();

let (search_path, module_file, kind) = resolve_name(db, name)?;
let Some((search_path, module_file, kind)) = resolve_name(db, name) else {
tracing::debug!("Module '{name}' not found in the search paths.");
return None;
};

let module = Module::new(name.clone(), kind, search_path, module_file);

tracing::debug!(
"Resolved module '{name}' to '{path}'.",
path = module_file.path(db)
);

Some(module)
}

Expand Down
4 changes: 4 additions & 0 deletions crates/red_knot_workspace/src/site_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ fn site_packages_dir_from_sys_prefix(

let site_packages_candidate = path.join("site-packages");
if system.is_directory(&site_packages_candidate) {
tracing::debug!(
"Resoled site-packages directory: {}",
site_packages_candidate
);
return Ok(site_packages_candidate);
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/red_knot_workspace/src/watch/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,17 @@ struct WatcherInner {
impl Watcher {
/// Sets up file watching for `path`.
pub fn watch(&mut self, path: &SystemPath) -> notify::Result<()> {
tracing::debug!("Watching path: {path}.");

self.inner_mut()
.watcher
.watch(path.as_std_path(), RecursiveMode::Recursive)
}

/// Stops file watching for `path`.
pub fn unwatch(&mut self, path: &SystemPath) -> notify::Result<()> {
tracing::debug!("Unwatching path: {path}.");

self.inner_mut().watcher.unwatch(path.as_std_path())
}

Expand All @@ -125,6 +129,7 @@ impl Watcher {
///
/// The call blocks until the watcher has stopped.
pub fn stop(mut self) {
tracing::debug!("Stop file watcher");
self.set_stop();
}

Expand Down Expand Up @@ -173,8 +178,8 @@ struct Debouncer {
}

impl Debouncer {
#[tracing::instrument(level = "trace", skip(self))]
fn add_result(&mut self, result: notify::Result<notify::Event>) {
tracing::trace!("Handling file watcher event: {result:?}.");
match result {
Ok(event) => self.add_event(event),
Err(error) => self.add_error(error),
Expand Down
5 changes: 5 additions & 0 deletions crates/red_knot_workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl Workspace {
/// Checks all open files in the workspace and its dependencies.
#[tracing::instrument(level = "debug", skip_all)]
pub fn check(self, db: &dyn Db) -> Vec<String> {
tracing::debug!("Checking workspace");

let mut result = Vec::new();

if let Some(open_files) = self.open_files(db) {
Expand Down Expand Up @@ -274,6 +276,8 @@ impl Package {

#[tracing::instrument(level = "debug", skip(db))]
pub(crate) fn check(self, db: &dyn Db) -> Vec<String> {
tracing::debug!("Checking package {}", self.root(db));

let mut result = Vec::new();
for file in &self.files(db).read() {
let diagnostics = check_file(db, file);
Expand Down Expand Up @@ -327,6 +331,7 @@ impl Package {
}

pub(super) fn check_file(db: &dyn Db, file: File) -> Diagnostics {
tracing::debug!("Checking file {path}", path = file.path(db));
let mut diagnostics = Vec::new();
diagnostics.extend_from_slice(lint_syntax(db, file));
diagnostics.extend_from_slice(lint_semantic(db, file));
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_db/src/files/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::files::{system_path_to_file, vendored_path_to_file, File};
use crate::system::{SystemPath, SystemPathBuf, SystemVirtualPath, SystemVirtualPathBuf};
use crate::vendored::{VendoredPath, VendoredPathBuf};
use crate::Db;
use std::fmt::{Display, Formatter};

/// Path to a file.
///
Expand Down Expand Up @@ -209,3 +210,13 @@ impl PartialEq<FilePath> for VendoredPathBuf {
other == self
}
}

impl Display for FilePath {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
FilePath::System(path) => std::fmt::Display::fmt(path, f),
FilePath::SystemVirtual(path) => std::fmt::Display::fmt(path, f),
FilePath::Vendored(path) => std::fmt::Display::fmt(path, f),
}
}
}
13 changes: 13 additions & 0 deletions crates/ruff_db/src/vendored/path.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Borrow;
use std::fmt::Formatter;
use std::ops::Deref;
use std::path;

Expand Down Expand Up @@ -197,3 +198,15 @@ impl TryFrom<path::PathBuf> for VendoredPathBuf {
Ok(VendoredPathBuf(camino::Utf8PathBuf::try_from(value)?))
}
}

impl std::fmt::Display for VendoredPath {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}

impl std::fmt::Display for VendoredPathBuf {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.as_path(), f)
}
}

0 comments on commit 268088c

Please sign in to comment.