Skip to content

Commit

Permalink
fix off by one
Browse files Browse the repository at this point in the history
more visible marker
spacing, marker, make it prettier
  • Loading branch information
sokra committed Feb 8, 2023
1 parent 8568fd6 commit 74b823c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
6 changes: 3 additions & 3 deletions crates/turbo-tasks-fs/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ impl UnparseableJson {
Self {
message: inner.to_string().into(),
path: Some(e.path().to_string()),
start_location: Some((inner.line() - 1, inner.column())),
start_location: Some((inner.line() - 1, inner.column() - 1)),
end_location: None,
}
}

pub fn write_with_content(&self, writer: &mut impl Write, text: &str) -> std::fmt::Result {
writeln!(writer, "{}", self.message)?;
if let Some(path) = &self.path {
writeln!(writer, " at {}", path)?;
writeln!(writer, " at {}", path)?;
}
match (self.start_location, self.end_location) {
(Some((line, column)), Some((end_line, end_column))) => {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Display for UnparseableJson {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)?;
if let Some(path) = &self.path {
write!(f, " at {}", path)?;
write!(f, " at {}", path)?;
}
Ok(())
}
Expand Down
14 changes: 12 additions & 2 deletions crates/turbo-tasks-fs/src/source_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ impl<'a> Display for SourceContextLine<'a> {
inside,
after,
} => {
writeln!(f, "{line:>6} | {before}{inside}{after}")?;
if inside.len() >= 2 {
writeln!(
f,
" | {}v{}v",
" ".repeat(before.len()),
"-".repeat(inside.len() - 2)
)?;
} else {
writeln!(f, " | {}v", " ".repeat(before.len()))?;
}
writeln!(f, "{line:>6} + {before}{inside}{after}")?;
if inside.len() >= 2 {
writeln!(
f,
Expand All @@ -69,7 +79,7 @@ impl<'a> Display for SourceContextLine<'a> {
"-".repeat(inside.len() - 2),
)
} else {
writeln!(f, " | {}^", " ".repeat(before.len()),)
writeln!(f, " | {}^", " ".repeat(before.len()))
}
}
SourceContextLine::Inside { line, inside } => {
Expand Down
15 changes: 14 additions & 1 deletion crates/turbopack-cli-utils/src/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,22 @@ fn format_source_content(source: &PlainIssueSource, formatted_issue: &mut String
inside,
after,
} => {
if inside.len() >= 2 {
writeln!(
f,
" + {}{}{}{}",
" ".repeat(before.len()),
"v".bold(),
"-".repeat(inside.len() - 2).bold(),
"v".bold(),
)
.unwrap();
} else {
writeln!(f, " | {}{}", " ".repeat(before.len()), "v".bold()).unwrap();
}
writeln!(
f,
"{line:>6} | {}{}{}",
"{line:>6} + {}{}{}",
before.dimmed(),
inside.bold(),
after.dimmed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PlainIssue {
context: "[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json",
category: "code generation",
title: "Code generation for chunk item errored",
description: "An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)\n at Execution of module_factory failed\n at Execution of JsonChunkItem::content failed\n at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26\n at nested.?\n 1 | {\n 2 | \"nested\": {\n 3 | \"this-is\": \"invalid\" // lint-staged will remove trailing commas, so here's a comment\n | ^\n 4 | }\n 5 | }\n",
description: "An error occurred while generating the chunk item [project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)\n at Execution of module_factory failed\n at Execution of JsonChunkItem::content failed\n at Unable to make a module from invalid JSON: expected `,` or `}` at line 3 column 26\n at nested.?\n 1 | {\n 2 | \"nested\": {\n | v\n 3 + \"this-is\": \"invalid\" // lint-staged will remove trailing commas, so here's a comment\n | ^\n 4 | }\n 5 | }\n",
detail: "",
documentation_link: "",
source: None,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74b823c

Please sign in to comment.