mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-09 20:21:16 -03:00
Mark the entire error location with a squiggle
This makes it so instead of marking the error location with a simple `^`, we mark it with a caret, then a run of `~`, and then an ending `^`. This makes it easier to see where exactly an error occured, e.g. which command substitution was meant. Note: Because this uses error locations that haven't been exposed like that, it's likely to shake out weirdnesses and inaccuracies. For that reason I've not adjusted the tests yet.
This commit is contained in:
@@ -126,6 +126,19 @@ wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring
|
||||
result.push_back(L'\n');
|
||||
result.append(caret_space_line);
|
||||
result.push_back(L'^');
|
||||
if (source_length > 1) {
|
||||
// Add a squiggle under the error location.
|
||||
// We do it like this
|
||||
// ^~~^
|
||||
// With a "^" under the start and end, and squiggles in-between.
|
||||
auto width = fish_wcswidth(src.c_str() + source_start, source_length);
|
||||
if (width > 2) {
|
||||
// Subtract one for each of the carets - this is important in case
|
||||
// the starting char has a width of > 1.
|
||||
result.append(width - 2, L'~');
|
||||
result.push_back(L'^');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user