diff --git a/src/command_line.cc b/src/command_line.cc index cc01ba81..35353a8c 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -488,6 +488,15 @@ optional GetLsRange(WorkingFile* working_file, const Range& location) { if (!start || !end) return nullopt; + // If remapping end fails (end can never be < start), just guess that the + // final location didn't move. This only screws up the highlighted code + // region if we guess wrong, so not a big deal. + // + // Remapping fails often in C++ since there are a lot of "};" at the end of + // class/struct definitions. + if (*end < *start) + *end = *start + (location.end.line - location.start.line); + return lsRange( lsPosition(*start - 1, location.start.column - 1), lsPosition(*end - 1, location.end.column - 1));