From 3f27febc4c694506a7d1fef7ad5022b4ee08681f Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 9 Aug 2022 15:26:48 +0200 Subject: [PATCH] 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. --- src/parse_tree.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 323acbae9..5e387366b 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -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; }