forked from qt-creator/qt-creator
ClangCodeModel: Fix suppressing warnings via textmark tooltip
This functionality was never properly converted when we switched to clangd. Fixes: QTCREATORBUG-29385 Change-Id: Ie06c9ec8bbed6a539ce9f9bf5ba512ae1a7f4b98 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
#include "clangconstants.h"
|
#include "clangconstants.h"
|
||||||
#include "clangdclient.h"
|
#include "clangdclient.h"
|
||||||
#include "clangdiagnostictooltipwidget.h"
|
#include "clangdiagnostictooltipwidget.h"
|
||||||
#include "clangeditordocumentprocessor.h"
|
|
||||||
#include "clangutils.h"
|
#include "clangutils.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -49,46 +48,15 @@ Project *projectForCurrentEditor()
|
|||||||
if (filePath.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (auto processor = ClangEditorDocumentProcessor::get(filePath)) {
|
if (ProjectPart::ConstPtr projectPart = projectPartForFile(filePath))
|
||||||
if (ProjectPart::ConstPtr projectPart = processor->projectPart())
|
return projectForProjectPart(*projectPart);
|
||||||
return projectForProjectPart(*projectPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DiagnosticType { Clang, Tidy, Clazy };
|
|
||||||
DiagnosticType diagnosticType(const ClangDiagnostic &diagnostic)
|
|
||||||
|
|
||||||
{
|
|
||||||
if (!diagnostic.disableOption.isEmpty())
|
|
||||||
return DiagnosticType::Clang;
|
|
||||||
|
|
||||||
const DiagnosticTextInfo textInfo(diagnostic.text);
|
|
||||||
if (DiagnosticTextInfo::isClazyOption(textInfo.option()))
|
|
||||||
return DiagnosticType::Clazy;
|
|
||||||
return DiagnosticType::Tidy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void disableDiagnosticInConfig(ClangDiagnosticConfig &config, const ClangDiagnostic &diagnostic)
|
void disableDiagnosticInConfig(ClangDiagnosticConfig &config, const ClangDiagnostic &diagnostic)
|
||||||
{
|
{
|
||||||
switch (diagnosticType(diagnostic)) {
|
config.setClangOptions(config.clangOptions() + QStringList(diagnostic.disableOption));
|
||||||
case DiagnosticType::Clang:
|
|
||||||
config.setClangOptions(config.clangOptions() + QStringList(diagnostic.disableOption));
|
|
||||||
break;
|
|
||||||
case DiagnosticType::Tidy:
|
|
||||||
config.setChecks(ClangToolType::Tidy, config.checks(ClangToolType::Tidy) + QString(",-")
|
|
||||||
+ DiagnosticTextInfo(diagnostic.text).option());
|
|
||||||
break;
|
|
||||||
case DiagnosticType::Clazy: {
|
|
||||||
const DiagnosticTextInfo textInfo(diagnostic.text);
|
|
||||||
const QString checkName = DiagnosticTextInfo::clazyCheckName(textInfo.option());
|
|
||||||
QStringList newChecks = config.checks(ClangToolType::Clazy).split(',');
|
|
||||||
newChecks.removeOne(checkName);
|
|
||||||
config.setChecks(ClangToolType::Clazy, newChecks.join(','));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangDiagnosticConfig diagnosticConfig()
|
ClangDiagnosticConfig diagnosticConfig()
|
||||||
@@ -210,8 +178,10 @@ ClangDiagnostic convertDiagnostic(const ClangdDiagnostic &src,
|
|||||||
target.severity = convertSeverity(*src.severity());
|
target.severity = convertSeverity(*src.severity());
|
||||||
const Diagnostic::Code code = src.code().value_or(Diagnostic::Code());
|
const Diagnostic::Code code = src.code().value_or(Diagnostic::Code());
|
||||||
const QString * const codeString = std::get_if<QString>(&code);
|
const QString * const codeString = std::get_if<QString>(&code);
|
||||||
if (codeString && codeString->startsWith("-W"))
|
if (codeString && codeString->startsWith("-W")) {
|
||||||
target.enableOption = *codeString;
|
target.enableOption = *codeString;
|
||||||
|
target.disableOption = "-Wno-" + codeString->mid(2);
|
||||||
|
}
|
||||||
for (const CodeAction &codeAction : src.codeActions().value_or(QList<CodeAction>())) {
|
for (const CodeAction &codeAction : src.codeActions().value_or(QList<CodeAction>())) {
|
||||||
const std::optional<WorkspaceEdit> edit = codeAction.edit();
|
const std::optional<WorkspaceEdit> edit = codeAction.edit();
|
||||||
if (!edit)
|
if (!edit)
|
||||||
@@ -304,15 +274,17 @@ ClangdTextMark::ClangdTextMark(TextEditor::TextDocument *doc,
|
|||||||
actions << action;
|
actions << action;
|
||||||
|
|
||||||
// Remove diagnostic warning action
|
// Remove diagnostic warning action
|
||||||
Project *project = projectForCurrentEditor();
|
if (!diag.disableOption.isEmpty()) {
|
||||||
if (project && isDiagnosticConfigChangable(project)) {
|
if (Project * const project = projectForCurrentEditor();
|
||||||
action = new QAction();
|
project && isDiagnosticConfigChangable(project)) {
|
||||||
action->setIcon(Icons::BROKEN.icon());
|
action = new QAction();
|
||||||
action->setToolTip(Tr::tr("Disable Diagnostic in Current Project"));
|
action->setIcon(Icons::BROKEN.icon());
|
||||||
QObject::connect(action, &QAction::triggered, [diag] {
|
action->setToolTip(Tr::tr("Disable Diagnostic in Current Project"));
|
||||||
disableDiagnosticInCurrentProjectConfig(diag);
|
QObject::connect(action, &QAction::triggered, [diag] {
|
||||||
});
|
disableDiagnosticInCurrentProjectConfig(diag);
|
||||||
actions << action;
|
});
|
||||||
|
actions << action;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return actions;
|
return actions;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -492,6 +492,7 @@ void ClangdProjectSettings::setDiagnosticConfigId(Utils::Id configId)
|
|||||||
{
|
{
|
||||||
m_customSettings.diagnosticConfigId = configId;
|
m_customSettings.diagnosticConfigId = configId;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
emit ClangdSettings::instance().changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdProjectSettings::blockIndexing()
|
void ClangdProjectSettings::blockIndexing()
|
||||||
|
|||||||
Reference in New Issue
Block a user