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