diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index f76e6089c..1158d4a33 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -29,13 +29,13 @@ static bool production_is_empty(const production_element_t *production) { /// Returns a string description of this parse error. wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring &prefix, bool is_interactive, bool skip_caret) const { + if (skip_caret || source_start >= src.size() || source_start + source_length > src.size()) { + return L""; + } + wcstring result = prefix; result.append(this->text); - if (skip_caret || source_start >= src.size() || source_start + source_length > src.size()) { - return result; - } - // Locate the beginning of this line of source. size_t line_start = 0; @@ -64,15 +64,12 @@ wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring // Don't include the caret and line if we're interactive this is the first line, because // then it's obvious. bool interactive_skip_caret = is_interactive && source_start == 0; - if (interactive_skip_caret) { return result; } // Append the line of text. - if (!result.empty()) { - result.push_back(L'\n'); - } + result.push_back(L'\n'); result.append(src, line_start, line_end - line_start); // Append the caret line. The input source may include tabs; for that reason we diff --git a/src/parser.h b/src/parser.h index a02fbc17f..3ebdbda31 100644 --- a/src/parser.h +++ b/src/parser.h @@ -3,6 +3,7 @@ #define FISH_PARSER_H #include +#include #include #include