]> granicus.if.org Git - clang/commitdiff
When a fix-it hint would span multiple lines, don't print it; half a
authorDouglas Gregor <dgregor@apple.com>
Sun, 3 May 2009 04:33:32 +0000 (04:33 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 3 May 2009 04:33:32 +0000 (04:33 +0000)
fix-it hint is much worse than no fix-it hint. (Fixes PR4084).

When we need to truncate a source line to fix in the terminal, make
sure to take the width of the fix-it information into account, too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70656 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnosticPrinter.cpp

index bcf30a5f561827167a38927049e469dae3585da9..a2cf8f958c2975191685d0df06e32485a17d4b8d 100644 (file)
@@ -132,7 +132,25 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
   for (; CaretEnd != CaretStart; --CaretEnd)
     if (!isspace(CaretLine[CaretEnd - 1]))
       break;
+   
+  // If we have a fix-it line, make sure the slice includes all of the
+  // fix-it information.
+  if (!FixItInsertionLine.empty()) {
+    unsigned FixItStart = 0, FixItEnd = FixItInsertionLine.size();
+    for (; FixItStart != FixItEnd; ++FixItStart)
+      if (!isspace(FixItInsertionLine[FixItStart]))
+        break;
     
+    for (; FixItEnd != FixItStart; --FixItEnd)
+      if (!isspace(FixItInsertionLine[FixItEnd - 1]))
+        break;
+
+    if (FixItStart < CaretStart)
+      CaretStart = FixItStart;
+    if (FixItEnd > CaretEnd)
+      CaretEnd = FixItEnd;
+  }
+
   // CaretLine[CaretStart, CaretEnd) contains all of the interesting
   // parts of the caret line. While this slice is smaller than the
   // number of columns we have, try to grow the slice to encompass
@@ -379,6 +397,9 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
             FixItInsertionLine.resize(LastColumnModified, ' ');
           std::copy(Hint->CodeToInsert.begin(), Hint->CodeToInsert.end(),
                     FixItInsertionLine.begin() + HintColNo - 1);
+        } else {
+          FixItInsertionLine.clear();
+          break;
         }
       }
     }