forked from qt-creator/qt-creator
Debugger: Fix column offset for Links that replaced DiagnosticsLocation
Amends a40e803503
The DiagnosticsLocation used 1 based column offset, but the column
offset in Link is 0. This removes the need to substract 1 from column
before passing the Link to openEditorAt.
Change-Id: I81905eff4881320e197d55f5b1a27aa7a3b74864
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -255,8 +255,8 @@ public:
|
||||
const Link start = step.ranges.first();
|
||||
const Link end = step.ranges.last();
|
||||
const bool operationAdded = changeSet.replace(
|
||||
file->position(start.targetLine, start.targetColumn),
|
||||
file->position(end.targetLine, end.targetColumn),
|
||||
file->position(start.targetLine, start.targetColumn + 1),
|
||||
file->position(end.targetLine, end.targetColumn + 1),
|
||||
step.message);
|
||||
if (!operationAdded)
|
||||
return false;
|
||||
|
@@ -196,7 +196,7 @@ const QList<DiagnosticItem *> &ClangToolsDiagnosticModel::itemsWithSameFixits(
|
||||
|
||||
static QString lineColumnString(const Link &location)
|
||||
{
|
||||
return QString("%1:%2").arg(location.targetLine).arg(location.targetColumn);
|
||||
return QString("%1:%2").arg(location.targetLine).arg(location.targetColumn + 1);
|
||||
}
|
||||
|
||||
static QString createExplainingStepToolTipString(const ExplainingStep &step)
|
||||
|
@@ -485,11 +485,9 @@ void DiagnosticView::openEditorForCurrentIndex()
|
||||
{
|
||||
const QVariant v = model()->data(currentIndex(), Debugger::DetailedErrorView::LocationRole);
|
||||
Link loc = v.value<Link>();
|
||||
if (loc.hasValidTarget()) {
|
||||
--loc.targetColumn; // FIXME: Move this to the model side.
|
||||
if (loc.hasValidTarget())
|
||||
Core::EditorManager::openEditorAt(loc);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
|
@@ -38,7 +38,7 @@ std::optional<LineColumnInfo> byteOffsetInUtf8TextToLineColumn(const char *text,
|
||||
|
||||
// Advance to column
|
||||
if (c - text == offset) {
|
||||
int columnCounter = 1;
|
||||
int columnCounter = 0;
|
||||
c = lineStart;
|
||||
while (c < text + offset && Utils::Text::utf8AdvanceCodePoint(c))
|
||||
++columnCounter;
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
// Convert
|
||||
OptionalLineColumnInfo info = byteOffsetInUtf8TextToLineColumn(data, fileOffset, startLine);
|
||||
if (!info)
|
||||
return {m_filePath, 1, 1};
|
||||
return {m_filePath, 1, 0};
|
||||
|
||||
// Save/update lookup
|
||||
int lineStartOffset = info->lineStartOffset;
|
||||
|
@@ -28,7 +28,7 @@ Utils::Result<Diagnostics> readExportedDiagnostics(
|
||||
// Exposed for tests
|
||||
struct LineColumnInfo {
|
||||
int line = 1; // 1-based
|
||||
int column = 1; // 1-based
|
||||
int column = 0; // 0-based
|
||||
int lineStartOffset = 0; // for optimiation/caching purposes
|
||||
};
|
||||
using OptionalLineColumnInfo = std::optional<LineColumnInfo>;
|
||||
|
@@ -31,7 +31,7 @@ namespace Internal {
|
||||
|
||||
static QString lineColumnString(const Link &link)
|
||||
{
|
||||
return QString("%1:%2").arg(link.targetLine).arg(link.targetColumn);
|
||||
return QString("%1:%2").arg(link.targetLine).arg(link.targetColumn + 1);
|
||||
}
|
||||
|
||||
static QString fixitStatus(FixitStatus status)
|
||||
|
@@ -320,7 +320,7 @@ void DocumentClangToolRunner::onDone(const AnalyzeOutputData &output)
|
||||
QTextCursor cursor(doc->document());
|
||||
cursor.setPosition(Text::positionInText(doc->document(),
|
||||
diagnostic.location.targetLine,
|
||||
diagnostic.location.targetColumn));
|
||||
diagnostic.location.targetColumn + 1));
|
||||
cursor.movePosition(QTextCursor::EndOfLine);
|
||||
marker.cursor = cursor;
|
||||
marker.type = Constants::CLANG_TOOL_FIXIT_AVAILABLE_MARKER_ID;
|
||||
|
@@ -35,8 +35,8 @@ using DiagnosticRange = QPair<Link, Link>;
|
||||
static Range toRange(const QTextDocument *doc, DiagnosticRange locations)
|
||||
{
|
||||
Range range;
|
||||
range.start = Text::positionInText(doc, locations.first.targetLine, locations.first.targetColumn);
|
||||
range.end = Text::positionInText(doc, locations.second.targetLine, locations.second.targetColumn);
|
||||
range.start = Text::positionInText(doc, locations.first.targetLine, locations.first.targetColumn + 1);
|
||||
range.end = Text::positionInText(doc, locations.second.targetLine, locations.second.targetColumn + 1);
|
||||
return range;
|
||||
}
|
||||
|
||||
|
@@ -186,7 +186,7 @@ void ReadExportedDiagnosticsTest::testOffsetStartOfFirstLine()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(asciiWord, 0);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 1);
|
||||
QCOMPARE(info->column, 1);
|
||||
QCOMPARE(info->column, 0);
|
||||
}
|
||||
|
||||
void ReadExportedDiagnosticsTest::testOffsetEndOfFirstLine()
|
||||
@@ -194,7 +194,7 @@ void ReadExportedDiagnosticsTest::testOffsetEndOfFirstLine()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(asciiWord, 2);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 1);
|
||||
QCOMPARE(info->column, 3);
|
||||
QCOMPARE(info->column, 2);
|
||||
}
|
||||
|
||||
// The invocation
|
||||
@@ -220,7 +220,7 @@ void ReadExportedDiagnosticsTest::testOffsetOffsetPointingToLineSeparator_unix()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(asciiMultiLine, 3);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 1);
|
||||
QCOMPARE(info->column, 4);
|
||||
QCOMPARE(info->column, 3);
|
||||
}
|
||||
|
||||
// For a file with dos style line endings ("\r\n"), clang-tidy points to '\r'.
|
||||
@@ -229,7 +229,7 @@ void ReadExportedDiagnosticsTest::testOffsetOffsetPointingToLineSeparator_dos()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(asciiMultiLine_dos, 3);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 1);
|
||||
QCOMPARE(info->column, 4);
|
||||
QCOMPARE(info->column, 3);
|
||||
}
|
||||
|
||||
void ReadExportedDiagnosticsTest::testOffsetStartOfSecondLine()
|
||||
@@ -237,7 +237,7 @@ void ReadExportedDiagnosticsTest::testOffsetStartOfSecondLine()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(asciiMultiLine, 4);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 2);
|
||||
QCOMPARE(info->column, 1);
|
||||
QCOMPARE(info->column, 0);
|
||||
}
|
||||
|
||||
void ReadExportedDiagnosticsTest::testOffsetMultiByteCodePoint1()
|
||||
@@ -245,7 +245,7 @@ void ReadExportedDiagnosticsTest::testOffsetMultiByteCodePoint1()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(nonAsciiMultiLine, 3);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 2);
|
||||
QCOMPARE(info->column, 1);
|
||||
QCOMPARE(info->column, 0);
|
||||
}
|
||||
|
||||
void ReadExportedDiagnosticsTest::testOffsetMultiByteCodePoint2()
|
||||
@@ -253,7 +253,7 @@ void ReadExportedDiagnosticsTest::testOffsetMultiByteCodePoint2()
|
||||
const auto info = byteOffsetInUtf8TextToLineColumn(nonAsciiMultiLine, 11);
|
||||
QVERIFY(info);
|
||||
QCOMPARE(info->line, 3);
|
||||
QCOMPARE(info->column, 2);
|
||||
QCOMPARE(info->column, 1);
|
||||
}
|
||||
|
||||
// Replace FILE_PATH with a real absolute file path in the *.yaml files.
|
||||
|
@@ -81,11 +81,9 @@ void DiagnosticView::openEditorForCurrentIndex()
|
||||
{
|
||||
const QVariant v = model()->data(currentIndex(), Debugger::DetailedErrorView::LocationRole);
|
||||
Link loc = v.value<Link>();
|
||||
if (loc.hasValidTarget()) {
|
||||
--loc.targetColumn; // FIXME: Move adjustment to model side.
|
||||
if (loc.hasValidTarget())
|
||||
Core::EditorManager::openEditorAt(loc);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagnosticView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
|
@@ -44,11 +44,9 @@ DetailedErrorView::DetailedErrorView(QWidget *parent) :
|
||||
connect(this, &QAbstractItemView::clicked, [](const QModelIndex &index) {
|
||||
if (index.column() == LocationColumn) {
|
||||
Link loc = index.model()->data(index, DetailedErrorView::LocationRole).value<Link>();
|
||||
if (loc.hasValidTarget()) {
|
||||
--loc.targetColumn; // FIXME: Move adjustment to model side.
|
||||
if (loc.hasValidTarget())
|
||||
Core::EditorManager::openEditorAt(loc);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addAction(m_copyAction);
|
||||
@@ -106,7 +104,7 @@ QVariant DetailedErrorView::locationData(int role, const Link &location)
|
||||
return location.hasValidTarget() ? QString::fromLatin1("%1:%2:%3")
|
||||
.arg(location.targetFilePath.fileName())
|
||||
.arg(location.targetLine)
|
||||
.arg(location.targetColumn)
|
||||
.arg(location.targetColumn + 1)
|
||||
: QString();
|
||||
case Qt::ToolTipRole:
|
||||
return location.targetFilePath.isEmpty()
|
||||
|
Reference in New Issue
Block a user