From a7ecf7af90395b9013f7d60ba749344f61947e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 21 Sep 2021 17:54:20 -0700 Subject: [PATCH 1/2] add magical debugging code to SourceCode impl for future debugging --- crates/nu-protocol/src/engine/engine_state.rs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index 03c816df8..6a7588428 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -556,8 +556,20 @@ impl<'a> miette::SourceCode for &StateWorkingSet<'a> { context_lines_before: usize, context_lines_after: usize, ) -> Result, miette::MietteError> { + let debugging = std::env::var("MIETTE_DEBUG").is_ok(); + if debugging { + let finding_span = "Finding span in StateWorkingSet"; + dbg!(finding_span, span); + } for (filename, start, end) in self.files() { + if debugging { + dbg!(&filename, start, end); + } if span.offset() >= *start && span.offset() + span.len() <= *end { + if debugging { + let found_file = "Found matching file"; + dbg!(found_file); + } let our_span = Span { start: *start, end: *end, @@ -565,7 +577,13 @@ impl<'a> miette::SourceCode for &StateWorkingSet<'a> { // We need to move to a local span because we're only reading // the specific file contents via self.get_span_contents. let local_span = (span.offset() - *start, span.len()).into(); + if debugging { + dbg!(&local_span); + } let span_contents = self.get_span_contents(our_span); + if debugging { + dbg!(String::from_utf8_lossy(span_contents)); + } let span_contents = span_contents.read_span( &local_span, context_lines_before, @@ -574,19 +592,31 @@ impl<'a> miette::SourceCode for &StateWorkingSet<'a> { let content_span = span_contents.span(); // Back to "global" indexing let retranslated = (content_span.offset() + start, content_span.len()).into(); + if debugging { + dbg!(&retranslated); + } + let data = span_contents.data(); if filename == "" { + if debugging { + let success_cli = "Successfully read CLI span"; + dbg!(success_cli, String::from_utf8_lossy(data)); + } return Ok(Box::new(miette::MietteSpanContents::new( - span_contents.data(), + data, retranslated, span_contents.line(), span_contents.column(), span_contents.line_count(), ))); } else { + if debugging { + let success_file = "Successfully read file span"; + dbg!(success_file); + } return Ok(Box::new(miette::MietteSpanContents::new_named( filename.clone(), - span_contents.data(), + data, retranslated, span_contents.line(), span_contents.column(), From 2553da3dc42ff52344ca285f429294c1ef5ed456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 21 Sep 2021 17:57:16 -0700 Subject: [PATCH 2/2] bump miette to fix multi-file rendering bug --- Cargo.lock | 5 ++--- Cargo.toml | 2 +- crates/nu-cli/Cargo.toml | 2 +- crates/nu-parser/Cargo.toml | 2 +- crates/nu-protocol/Cargo.toml | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50bfd3619..15c5d13b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -339,7 +339,7 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "miette" version = "3.0.1-alpha.0" -source = "git+https://github.com/zkat/miette?rev=183ecb9#183ecb9b78a1c22d832e979db5054dcac36d8b7a" +source = "git+https://github.com/zkat/miette?branch=release/3.0.0#491ce7c0ce1f04c9b6fc09c250f188c1ec77df53" dependencies = [ "atty", "backtrace", @@ -354,13 +354,12 @@ dependencies = [ "term_size", "textwrap", "thiserror", - "unicode-width", ] [[package]] name = "miette-derive" version = "3.0.0-alpha.0" -source = "git+https://github.com/zkat/miette?rev=183ecb9#183ecb9b78a1c22d832e979db5054dcac36d8b7a" +source = "git+https://github.com/zkat/miette?branch=release/3.0.0#491ce7c0ce1f04c9b6fc09c250f188c1ec77df53" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 36592d6a2..767c73764 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ nu-engine = { path="./crates/nu-engine" } nu-parser = { path="./crates/nu-parser" } nu-protocol = { path = "./crates/nu-protocol" } nu-table = { path = "./crates/nu-table" } -miette = { git = "https://github.com/zkat/miette", rev = "183ecb9" } +miette = { git = "https://github.com/zkat/miette", branch = "release/3.0.0" } # miette = { path = "../miette" } # mimalloc = { version = "*", default-features = false } diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index 9db871f11..005bc686b 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" nu-engine = { path = "../nu-engine" } nu-parser = { path = "../nu-parser" } nu-protocol = { path = "../nu-protocol" } -miette = { git = "https://github.com/zkat/miette", rev = "183ecb9", features = ["fancy"] } +miette = { git = "https://github.com/zkat/miette", branch = "release/3.0.0", features = ["fancy"] } # miette = { path = "../../../miette", features = ["fancy"] } thiserror = "1.0.29" nu-ansi-term = "0.36.0" diff --git a/crates/nu-parser/Cargo.toml b/crates/nu-parser/Cargo.toml index 3372a8b63..b3775feed 100644 --- a/crates/nu-parser/Cargo.toml +++ b/crates/nu-parser/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [dependencies] -miette = { git = "https://github.com/zkat/miette", rev = "183ecb9" } +miette = { git = "https://github.com/zkat/miette", branch = "release/3.0.0" } # miette = { path = "../../../miette" } thiserror = "1.0.29" nu-protocol = { path = "../nu-protocol"} diff --git a/crates/nu-protocol/Cargo.toml b/crates/nu-protocol/Cargo.toml index e15c50e54..1f92f6765 100644 --- a/crates/nu-protocol/Cargo.toml +++ b/crates/nu-protocol/Cargo.toml @@ -7,5 +7,5 @@ edition = "2018" [dependencies] thiserror = "1.0.29" -miette = { git = "https://github.com/zkat/miette", rev = "183ecb9" } +miette = { git = "https://github.com/zkat/miette", branch = "release/3.0.0" } # miette = { path = "../../../miette" }