Skip to content

Commit d4c1fbe

Browse files
committed
fix off by one
more visible marker spacing, marker, make it prettier
1 parent 136378f commit d4c1fbe

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

crates/turbo-tasks-fs/src/json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ impl UnparseableJson {
4747
Self {
4848
message: inner.to_string().into(),
4949
path: Some(e.path().to_string()),
50-
start_location: Some((inner.line() - 1, inner.column())),
50+
start_location: Some((inner.line() - 1, inner.column() - 1)),
5151
end_location: None,
5252
}
5353
}
5454

5555
pub fn write_with_content(&self, writer: &mut impl Write, text: &str) -> std::fmt::Result {
5656
writeln!(writer, "{}", self.message)?;
5757
if let Some(path) = &self.path {
58-
writeln!(writer, " at {}", path)?;
58+
writeln!(writer, " at {}", path)?;
5959
}
6060
match (self.start_location, self.end_location) {
6161
(Some((line, column)), Some((end_line, end_column))) => {
@@ -90,7 +90,7 @@ impl Display for UnparseableJson {
9090
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
9191
write!(f, "{}", self.message)?;
9292
if let Some(path) = &self.path {
93-
write!(f, " at {}", path)?;
93+
write!(f, " at {}", path)?;
9494
}
9595
Ok(())
9696
}

crates/turbo-tasks-fs/src/source_context.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ impl<'a> Display for SourceContextLine<'a> {
6060
inside,
6161
after,
6262
} => {
63-
writeln!(f, "{line:>6} | {before}{inside}{after}")?;
63+
if inside.len() >= 2 {
64+
writeln!(
65+
f,
66+
" | {}v{}v",
67+
" ".repeat(before.len()),
68+
"-".repeat(inside.len() - 2)
69+
)?;
70+
} else {
71+
writeln!(f, " | {}v", " ".repeat(before.len()))?;
72+
}
73+
writeln!(f, "{line:>6} + {before}{inside}{after}")?;
6474
if inside.len() >= 2 {
6575
writeln!(
6676
f,
@@ -69,7 +79,7 @@ impl<'a> Display for SourceContextLine<'a> {
6979
"-".repeat(inside.len() - 2),
7080
)
7181
} else {
72-
writeln!(f, " | {}^", " ".repeat(before.len()),)
82+
writeln!(f, " | {}^", " ".repeat(before.len()))
7383
}
7484
}
7585
SourceContextLine::Inside { line, inside } => {

crates/turbopack-cli-utils/src/issue.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,22 @@ fn format_source_content(source: &PlainIssueSource, formatted_issue: &mut String
127127
inside,
128128
after,
129129
} => {
130+
if inside.len() >= 2 {
131+
writeln!(
132+
f,
133+
" + {}{}{}{}",
134+
" ".repeat(before.len()),
135+
"v".bold(),
136+
"-".repeat(inside.len() - 2).bold(),
137+
"v".bold(),
138+
)
139+
.unwrap();
140+
} else {
141+
writeln!(f, " | {}{}", " ".repeat(before.len()), "v".bold()).unwrap();
142+
}
130143
writeln!(
131144
f,
132-
"{line:>6} | {}{}{}",
145+
"{line:>6} + {}{}{}",
133146
before.dimmed(),
134147
inside.bold(),
135148
after.dimmed()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PlainIssue {
33
context: "[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json",
44
category: "code generation",
55
title: "Code generation for chunk item errored",
6-
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",
6+
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",
77
detail: "",
88
documentation_link: "",
99
source: None,

crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)