summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-08 21:14:19 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-08 21:14:19 +0000
commitb5a94f45d22e43241c80c4a26994de0c4c28b92b (patch)
tree9633bbb604ce74d4427bc1a0ddc461645da3a43b
parent12f247f43f7c82c252b1c85b9a94f6494d362996 (diff)
downloadbcm5719-llvm-b5a94f45d22e43241c80c4a26994de0c4c28b92b.tar.gz
bcm5719-llvm-b5a94f45d22e43241c80c4a26994de0c4c28b92b.zip
If fixits appear to overlap, move the second one over in the output.
This occurs when you have two insertions and the first one is so long that the second fixit's column is before the first fixit ends. The edits themselves don't actually overlap, but our command-line preview does. llvm-svn: 158229
-rw-r--r--clang/lib/Frontend/TextDiagnostic.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 99e89f246bf..5c8da05c7bb 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1090,6 +1090,7 @@ std::string TextDiagnostic::buildFixItInsertionLine(
std::string FixItInsertionLine;
if (Hints.empty() || !DiagOpts.ShowFixits)
return FixItInsertionLine;
+ unsigned PrevHintEnd = 0;
for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end();
I != E; ++I) {
@@ -1107,6 +1108,16 @@ std::string TextDiagnostic::buildFixItInsertionLine(
assert(HintColNo<static_cast<unsigned>(map.bytes())+1);
HintColNo = map.byteToColumn(HintColNo);
+ // If we inserted a long previous hint, push this one forwards, and add
+ // an extra space to show that this is not part of the previous
+ // completion. This is sort of the best we can do when two hints appear
+ // to overlap.
+ //
+ // Note that if this hint is located immediately after the previous
+ // hint, no space will be added, since the location is more important.
+ if (HintColNo < PrevHintEnd)
+ HintColNo = PrevHintEnd + 1;
+
// FIXME: if the fixit includes tabs or other characters that do not
// take up a single column per byte when displayed then
// I->CodeToInsert.size() is not a column number and we're mixing
@@ -1115,19 +1126,16 @@ std::string TextDiagnostic::buildFixItInsertionLine(
unsigned LastColumnModified
= HintColNo + I->CodeToInsert.size();
- if (LastColumnModified > static_cast<unsigned>(map.bytes())) {
- unsigned LastExistingColumn = map.byteToColumn(map.bytes());
- unsigned AddedColumns = LastColumnModified-LastExistingColumn;
- LastColumnModified = LastExistingColumn + AddedColumns;
- } else {
+ if (LastColumnModified <= static_cast<unsigned>(map.bytes()))
LastColumnModified = map.byteToColumn(LastColumnModified);
- }
if (LastColumnModified > FixItInsertionLine.size())
FixItInsertionLine.resize(LastColumnModified, ' ');
assert(HintColNo+I->CodeToInsert.size() <= FixItInsertionLine.size());
std::copy(I->CodeToInsert.begin(), I->CodeToInsert.end(),
FixItInsertionLine.begin() + HintColNo);
+
+ PrevHintEnd = LastColumnModified;
} else {
FixItInsertionLine.clear();
break;
OpenPOWER on IntegriCloud