[clang] [clang] Adjust TextDiagnostic style ranges for interesting source region (PR #164941)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 31 03:59:22 PDT 2025


================
@@ -521,8 +518,41 @@ static void selectInterestingSourceRegion(std::string &SourceLine,
   if (BackColumnsRemoved > Columns(BackEllipse.size()))
     SourceLine.replace(SourceEnd.V, std::string::npos, BackEllipse);
 
+  // Since we've modified the SourceLine, we also need to adjust the line's
+  // highlighting information. In particular, if we've removed
+  // from the front of the line, we need to move the style ranges to the
+  // left and remove unneeded ranges.
+  Columns FrontDiff = FrontColumnsRemoved > FrontEllipse.size()
+                          ? FrontColumnsRemoved - FrontEllipse.size()
+                          : 0;
+  Columns CodeStart = FrontColumnsRemoved > FrontEllipse.size()
+                          ? FrontEllipse.size()
+                          : FrontColumnsRemoved;
----------------
Sirraide wrote:

I think we should be able to use `std::min`/`std::max` for these.

https://github.com/llvm/llvm-project/pull/164941


More information about the cfe-commits mailing list