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)
|
||||
{
|
||||
const QString filePath = location.targetFilePath.toString();
|
||||
if (filePath != mainFilePath)
|
||||
if (!filePath.isEmpty() && filePath != mainFilePath)
|
||||
return QFileInfo(filePath).fileName() + QLatin1Char(':');
|
||||
|
||||
return QString();
|
||||
@@ -63,6 +63,8 @@ QString fileNamePrefix(const QString &mainFilePath, const Utils::Link &location)
|
||||
|
||||
QString locationToString(const Utils::Link &location)
|
||||
{
|
||||
if (location.targetLine <= 0 || location.targetColumn <= 0)
|
||||
return {};
|
||||
return QString::number(location.targetLine)
|
||||
+ QStringLiteral(":")
|
||||
+ QString::number(location.targetColumn + 1);
|
||||
@@ -226,11 +228,11 @@ private:
|
||||
const bool hasFixit = m_displayHints.enableClickableFixits
|
||||
&& !diagnostic.fixIts.isEmpty();
|
||||
const QString diagnosticText = diagnostic.text.toHtmlEscaped();
|
||||
const QString text = QString::fromLatin1("%1: %2")
|
||||
.arg(clickableLocation(diagnostic, m_mainFilePath),
|
||||
clickableFixIt(diagnostic, diagnosticText, hasFixit));
|
||||
|
||||
return text;
|
||||
bool hasLocation = false;
|
||||
QString text = clickableLocation(diagnostic, m_mainFilePath, hasLocation);
|
||||
if (hasLocation)
|
||||
text += ": ";
|
||||
return text += clickableFixIt(diagnostic, diagnosticText, hasFixit);
|
||||
}
|
||||
|
||||
QString diagnosticRow(const ClangDiagnostic &diagnostic, IndentMode indentMode)
|
||||
@@ -273,7 +275,8 @@ private:
|
||||
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;
|
||||
|
||||
@@ -281,6 +284,7 @@ private:
|
||||
const QString lineColumn = locationToString(location);
|
||||
const QString linkText = filePrefix + lineColumn;
|
||||
const QString targetId = generateTargetId(LINK_ACTION_GOTO_LOCATION, diagnostic);
|
||||
hasContent = !linkText.isEmpty();
|
||||
|
||||
return wrapInLink(linkText, targetId);
|
||||
}
|
||||
|
@@ -266,12 +266,15 @@ ClangDiagnostic convertDiagnostic(const ClangdDiagnostic &src, const FilePath &f
|
||||
const Utils::optional<WorkspaceEdit::Changes> changes = edit->changes();
|
||||
if (!changes)
|
||||
continue;
|
||||
ClangDiagnostic fixItDiag;
|
||||
fixItDiag.text = codeAction.title();
|
||||
for (auto it = changes->cbegin(); it != changes->cend(); ++it) {
|
||||
for (const TextEdit &textEdit : it.value()) {
|
||||
target.fixIts << ClangFixIt(textEdit.newText(),
|
||||
fixItDiag.fixIts << ClangFixIt(textEdit.newText(),
|
||||
convertRange(it.key().toFilePath(), textEdit.range()));
|
||||
}
|
||||
}
|
||||
target.children << fixItDiag;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
Reference in New Issue
Block a user