forked from qt-creator/qt-creator
ClangCodeModel: Fix handling of code actions in diagnostic tooltip
We need to create a sub-diagnostic for every clangd code action. Task-number: QTCREATORBUG-27514 Change-Id: I9a12bcb390c9cc157ba7bca5015bbf51d31263da Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -55,7 +55,7 @@ const char LINK_ACTION_APPLY_FIX[] = "#applyFix";
|
|||||||
QString fileNamePrefix(const QString &mainFilePath, const Utils::Link &location)
|
QString fileNamePrefix(const QString &mainFilePath, const Utils::Link &location)
|
||||||
{
|
{
|
||||||
const QString filePath = location.targetFilePath.toString();
|
const QString filePath = location.targetFilePath.toString();
|
||||||
if (filePath != mainFilePath)
|
if (!filePath.isEmpty() && filePath != mainFilePath)
|
||||||
return QFileInfo(filePath).fileName() + QLatin1Char(':');
|
return QFileInfo(filePath).fileName() + QLatin1Char(':');
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
@@ -63,6 +63,8 @@ QString fileNamePrefix(const QString &mainFilePath, const Utils::Link &location)
|
|||||||
|
|
||||||
QString locationToString(const Utils::Link &location)
|
QString locationToString(const Utils::Link &location)
|
||||||
{
|
{
|
||||||
|
if (location.targetLine <= 0 || location.targetColumn <= 0)
|
||||||
|
return {};
|
||||||
return QString::number(location.targetLine)
|
return QString::number(location.targetLine)
|
||||||
+ QStringLiteral(":")
|
+ QStringLiteral(":")
|
||||||
+ QString::number(location.targetColumn + 1);
|
+ QString::number(location.targetColumn + 1);
|
||||||
@@ -226,11 +228,11 @@ private:
|
|||||||
const bool hasFixit = m_displayHints.enableClickableFixits
|
const bool hasFixit = m_displayHints.enableClickableFixits
|
||||||
&& !diagnostic.fixIts.isEmpty();
|
&& !diagnostic.fixIts.isEmpty();
|
||||||
const QString diagnosticText = diagnostic.text.toHtmlEscaped();
|
const QString diagnosticText = diagnostic.text.toHtmlEscaped();
|
||||||
const QString text = QString::fromLatin1("%1: %2")
|
bool hasLocation = false;
|
||||||
.arg(clickableLocation(diagnostic, m_mainFilePath),
|
QString text = clickableLocation(diagnostic, m_mainFilePath, hasLocation);
|
||||||
clickableFixIt(diagnostic, diagnosticText, hasFixit));
|
if (hasLocation)
|
||||||
|
text += ": ";
|
||||||
return text;
|
return text += clickableFixIt(diagnostic, diagnosticText, hasFixit);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString diagnosticRow(const ClangDiagnostic &diagnostic, IndentMode indentMode)
|
QString diagnosticRow(const ClangDiagnostic &diagnostic, IndentMode indentMode)
|
||||||
@@ -273,7 +275,8 @@ private:
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString clickableLocation(const ClangDiagnostic &diagnostic, const QString &mainFilePath)
|
QString clickableLocation(const ClangDiagnostic &diagnostic, const QString &mainFilePath,
|
||||||
|
bool &hasContent)
|
||||||
{
|
{
|
||||||
const Utils::Link &location = diagnostic.location;
|
const Utils::Link &location = diagnostic.location;
|
||||||
|
|
||||||
@@ -281,6 +284,7 @@ private:
|
|||||||
const QString lineColumn = locationToString(location);
|
const QString lineColumn = locationToString(location);
|
||||||
const QString linkText = filePrefix + lineColumn;
|
const QString linkText = filePrefix + lineColumn;
|
||||||
const QString targetId = generateTargetId(LINK_ACTION_GOTO_LOCATION, diagnostic);
|
const QString targetId = generateTargetId(LINK_ACTION_GOTO_LOCATION, diagnostic);
|
||||||
|
hasContent = !linkText.isEmpty();
|
||||||
|
|
||||||
return wrapInLink(linkText, targetId);
|
return wrapInLink(linkText, targetId);
|
||||||
}
|
}
|
||||||
|
@@ -266,12 +266,15 @@ ClangDiagnostic convertDiagnostic(const ClangdDiagnostic &src, const FilePath &f
|
|||||||
const Utils::optional<WorkspaceEdit::Changes> changes = edit->changes();
|
const Utils::optional<WorkspaceEdit::Changes> changes = edit->changes();
|
||||||
if (!changes)
|
if (!changes)
|
||||||
continue;
|
continue;
|
||||||
|
ClangDiagnostic fixItDiag;
|
||||||
|
fixItDiag.text = codeAction.title();
|
||||||
for (auto it = changes->cbegin(); it != changes->cend(); ++it) {
|
for (auto it = changes->cbegin(); it != changes->cend(); ++it) {
|
||||||
for (const TextEdit &textEdit : it.value()) {
|
for (const TextEdit &textEdit : it.value()) {
|
||||||
target.fixIts << ClangFixIt(textEdit.newText(),
|
fixItDiag.fixIts << ClangFixIt(textEdit.newText(),
|
||||||
convertRange(it.key().toFilePath(), textEdit.range()));
|
convertRange(it.key().toFilePath(), textEdit.range()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
target.children << fixItDiag;
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user