mirror of
https://github.com/nushell/nushell
synced 2024-12-30 15:03:25 +00:00
add magical debugging code to SourceCode impl for future debugging
This commit is contained in:
parent
32f39c2fb8
commit
a7ecf7af90
1 changed files with 32 additions and 2 deletions
|
@ -556,8 +556,20 @@ impl<'a> miette::SourceCode for &StateWorkingSet<'a> {
|
||||||
context_lines_before: usize,
|
context_lines_before: usize,
|
||||||
context_lines_after: usize,
|
context_lines_after: usize,
|
||||||
) -> Result<Box<dyn miette::SpanContents + 'b>, miette::MietteError> {
|
) -> Result<Box<dyn miette::SpanContents + 'b>, 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() {
|
for (filename, start, end) in self.files() {
|
||||||
|
if debugging {
|
||||||
|
dbg!(&filename, start, end);
|
||||||
|
}
|
||||||
if span.offset() >= *start && span.offset() + span.len() <= *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 {
|
let our_span = Span {
|
||||||
start: *start,
|
start: *start,
|
||||||
end: *end,
|
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
|
// We need to move to a local span because we're only reading
|
||||||
// the specific file contents via self.get_span_contents.
|
// the specific file contents via self.get_span_contents.
|
||||||
let local_span = (span.offset() - *start, span.len()).into();
|
let local_span = (span.offset() - *start, span.len()).into();
|
||||||
|
if debugging {
|
||||||
|
dbg!(&local_span);
|
||||||
|
}
|
||||||
let span_contents = self.get_span_contents(our_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(
|
let span_contents = span_contents.read_span(
|
||||||
&local_span,
|
&local_span,
|
||||||
context_lines_before,
|
context_lines_before,
|
||||||
|
@ -574,19 +592,31 @@ impl<'a> miette::SourceCode for &StateWorkingSet<'a> {
|
||||||
let content_span = span_contents.span();
|
let content_span = span_contents.span();
|
||||||
// Back to "global" indexing
|
// Back to "global" indexing
|
||||||
let retranslated = (content_span.offset() + start, content_span.len()).into();
|
let retranslated = (content_span.offset() + start, content_span.len()).into();
|
||||||
|
if debugging {
|
||||||
|
dbg!(&retranslated);
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = span_contents.data();
|
||||||
if filename == "<cli>" {
|
if filename == "<cli>" {
|
||||||
|
if debugging {
|
||||||
|
let success_cli = "Successfully read CLI span";
|
||||||
|
dbg!(success_cli, String::from_utf8_lossy(data));
|
||||||
|
}
|
||||||
return Ok(Box::new(miette::MietteSpanContents::new(
|
return Ok(Box::new(miette::MietteSpanContents::new(
|
||||||
span_contents.data(),
|
data,
|
||||||
retranslated,
|
retranslated,
|
||||||
span_contents.line(),
|
span_contents.line(),
|
||||||
span_contents.column(),
|
span_contents.column(),
|
||||||
span_contents.line_count(),
|
span_contents.line_count(),
|
||||||
)));
|
)));
|
||||||
} else {
|
} else {
|
||||||
|
if debugging {
|
||||||
|
let success_file = "Successfully read file span";
|
||||||
|
dbg!(success_file);
|
||||||
|
}
|
||||||
return Ok(Box::new(miette::MietteSpanContents::new_named(
|
return Ok(Box::new(miette::MietteSpanContents::new_named(
|
||||||
filename.clone(),
|
filename.clone(),
|
||||||
span_contents.data(),
|
data,
|
||||||
retranslated,
|
retranslated,
|
||||||
span_contents.line(),
|
span_contents.line(),
|
||||||
span_contents.column(),
|
span_contents.column(),
|
||||||
|
|
Loading…
Reference in a new issue