Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,14 @@ impl<'src> Lexer<'src> {
// The width of the error site to highlight depends on the kind of error:
let length = match kind {
UnterminatedString | UnterminatedBacktick => {
let Some(kind) = StringKind::from_token_start(self.lexeme()) else {
return self.internal_error("Lexer::error: expected string or backtick token start");
};
kind.delimiter().len()
if self.lexeme().starts_with(Self::INTERPOLATION_END) {
Self::INTERPOLATION_END.len()
} else {
let Some(kind) = StringKind::from_token_start(self.lexeme()) else {
return self.internal_error("Lexer::error: expected string or backtick token start");
};
kind.delimiter().len()
}
}
// highlight the full token
_ => self.lexeme().len(),
Expand Down
16 changes: 16 additions & 0 deletions tests/format_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,19 @@ fn format_string_followed_by_recipe() {
)
.success();
}

#[test]
fn unterminated_format_string_error() {
Test::new()
.justfile("x := f'{{}}")
.stderr(
"
error: unterminated string
——▶ justfile:1:10
1 │ x := f'{{}}
│ ^^
",
)
.failure();
}
Loading