forked from qt-creator/qt-creator
ClangTools: Run clang-tidy and clazy separately
They are two different tools and should not have been merged into a single runner in the first place. People can now actively decide to run clazy if they really want to, rather than getting confronted with its increasingly irrelevant complaints by default. We keep the common settings widget for now. Change-Id: I3c2b1db8c07ff5c128700d4a1deefd710967568a Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -75,7 +75,8 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ClangTool clangTool;
|
||||
ClangTidyTool clangTidyTool;
|
||||
ClazyTool clazyTool;
|
||||
ClangToolsOptionsPage optionsPage;
|
||||
QMap<Core::IDocument *, DocumentClangToolRunner *> documentRunners;
|
||||
DocumentQuickFixFactory quickFixFactory;
|
||||
@@ -133,22 +134,31 @@ void ClangToolsPlugin::onCurrentEditorChanged()
|
||||
|
||||
void ClangToolsPlugin::registerAnalyzeActions()
|
||||
{
|
||||
ActionManager::registerAction(d->clangTool.startAction(), Constants::RUN_ON_PROJECT);
|
||||
Command *cmd = ActionManager::registerAction(d->clangTool.startOnCurrentFileAction(),
|
||||
Constants::RUN_ON_CURRENT_FILE);
|
||||
ActionContainer *mtoolscpp = ActionManager::actionContainer(CppEditor::Constants::M_TOOLS_CPP);
|
||||
if (mtoolscpp)
|
||||
mtoolscpp->addAction(cmd);
|
||||
for (const auto &toolInfo : {std::make_tuple(ClangTidyTool::instance(),
|
||||
Constants::RUN_CLANGTIDY_ON_PROJECT,
|
||||
Constants::RUN_CLANGTIDY_ON_CURRENT_FILE),
|
||||
std::make_tuple(ClazyTool::instance(),
|
||||
Constants::RUN_CLAZY_ON_PROJECT,
|
||||
Constants::RUN_CLAZY_ON_CURRENT_FILE)}) {
|
||||
ClangTool * const tool = std::get<0>(toolInfo);
|
||||
ActionManager::registerAction(tool->startAction(), std::get<1>(toolInfo));
|
||||
Command *cmd = ActionManager::registerAction(tool->startOnCurrentFileAction(),
|
||||
std::get<2>(toolInfo));
|
||||
ActionContainer *mtoolscpp = ActionManager::actionContainer(CppEditor::Constants::M_TOOLS_CPP);
|
||||
if (mtoolscpp)
|
||||
mtoolscpp->addAction(cmd);
|
||||
|
||||
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(
|
||||
CppEditor::Constants::M_CONTEXT);
|
||||
if (mcontext)
|
||||
mcontext->addAction(cmd, CppEditor::Constants::G_CONTEXT_FIRST);
|
||||
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(
|
||||
CppEditor::Constants::M_CONTEXT);
|
||||
if (mcontext)
|
||||
mcontext->addAction(cmd, CppEditor::Constants::G_CONTEXT_FIRST);
|
||||
}
|
||||
|
||||
// add button to tool bar of C++ source files
|
||||
connect(EditorManager::instance(), &EditorManager::editorOpened, this, [this, cmd](IEditor *editor) {
|
||||
connect(EditorManager::instance(), &EditorManager::editorOpened, this,
|
||||
[this](IEditor *editor) {
|
||||
if (editor->document()->filePath().isEmpty()
|
||||
|| !Utils::mimeTypeForName(editor->document()->mimeType()).inherits("text/x-c++src"))
|
||||
|| !Utils::mimeTypeForName(editor->document()->mimeType()).inherits("text/x-c++src"))
|
||||
return;
|
||||
auto *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
|
||||
if (!textEditor)
|
||||
@@ -157,12 +167,25 @@ void ClangToolsPlugin::registerAnalyzeActions()
|
||||
if (!widget)
|
||||
return;
|
||||
const QIcon icon = Utils::Icon({{":/debugger/images/debugger_singleinstructionmode.png",
|
||||
Utils::Theme::IconsBaseColor}})
|
||||
.icon();
|
||||
QAction *action = widget->toolBar()->addAction(icon, tr("Analyze File"), [this, editor] {
|
||||
d->clangTool.startTool(editor->document()->filePath());
|
||||
});
|
||||
cmd->augmentActionWithShortcutToolTip(action);
|
||||
Utils::Theme::IconsBaseColor}}).icon();
|
||||
const auto button = new QToolButton;
|
||||
button->setPopupMode(QToolButton::InstantPopup);
|
||||
button->setIcon(icon);
|
||||
button->setToolTip(tr("Analyze File..."));
|
||||
widget->toolBar()->addWidget(button);
|
||||
const auto toolsMenu = new QMenu(widget);
|
||||
button->setMenu(toolsMenu);
|
||||
for (const auto &toolInfo : {std::make_pair(ClangTidyTool::instance(),
|
||||
Constants::RUN_CLANGTIDY_ON_CURRENT_FILE),
|
||||
std::make_pair(ClazyTool::instance(),
|
||||
Constants::RUN_CLAZY_ON_CURRENT_FILE)}) {
|
||||
ClangTool * const tool = toolInfo.first;
|
||||
Command * const cmd = ActionManager::command(toolInfo.second);
|
||||
QAction * const action = toolsMenu->addAction(tool->name(), [this, editor, tool] {
|
||||
tool->startTool(editor->document()->filePath());
|
||||
});
|
||||
cmd->augmentActionWithShortcutToolTip(action);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user