From 226c03c1eb5553607bf8455009f00099086a02f8 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 12 Apr 2021 12:58:52 +0200 Subject: [PATCH] ClangTools: Give a hint to users as to why we didn't do anything Task-number: QTCREATORBUG-25565 Change-Id: I27cb0e5bc2a02a88ddf1d42b996e45840d6c1385 Reviewed-by: David Schulz --- src/plugins/clangtools/clangtool.cpp | 14 +++++++++++++- src/plugins/clangtools/clangtoolsplugin.cpp | 3 +++ src/plugins/clangtools/clangtoolsutils.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp index 5866103df4b..668031da211 100644 --- a/src/plugins/clangtools/clangtool.cpp +++ b/src/plugins/clangtools/clangtool.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include @@ -650,6 +651,8 @@ void ClangTool::startTool(ClangTool::FileSelection fileSelection, return; } + TaskHub::clearTasks(taskCategory()); + // Collect files to analyze const FileInfos fileInfos = collectFileInfos(project, fileSelection); if (fileInfos.empty()) @@ -726,8 +729,12 @@ FileInfos ClangTool::collectFileInfos(Project *project, FileSelection fileSelect FileSelectionType *selectionType = get_if(&fileSelection); // early bailout if (selectionType && *selectionType == FileSelectionType::CurrentFile - && !EditorManager::currentDocument()) + && !EditorManager::currentDocument()) { + TaskHub::addTask(Task::Error, tr("Cannot analyze current file: No files open."), + taskCategory()); + TaskHub::requestPopup(); return {}; + } auto projectInfo = CppTools::CppModelManager::instance()->projectInfo(project); QTC_ASSERT(projectInfo.isValid(), return FileInfos()); @@ -757,6 +764,11 @@ FileInfos ClangTool::collectFileInfos(Project *project, FileSelection fileSelect }); if (!fileInfo.file.isEmpty()) return {fileInfo}; + TaskHub::addTask(Task::Error, + tr("Cannot analyze current file: \"%1\" is not a known source file.") + .arg(filePath.toUserOutput()), + taskCategory()); + TaskHub::requestPopup(); } return {}; diff --git a/src/plugins/clangtools/clangtoolsplugin.cpp b/src/plugins/clangtools/clangtoolsplugin.cpp index 9a22ea8b5a6..d9c937dadb9 100644 --- a/src/plugins/clangtools/clangtoolsplugin.cpp +++ b/src/plugins/clangtools/clangtoolsplugin.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,8 @@ bool ClangToolsPlugin::initialize(const QStringList &arguments, QString *errorSt Q_UNUSED(arguments) Q_UNUSED(errorString) + TaskHub::addCategory(taskCategory(), tr("Clang Tools")); + // Import tidy/clazy diagnostic configs from CppTools now // instead of at opening time of the settings page ClangToolsSettings::instance(); diff --git a/src/plugins/clangtools/clangtoolsutils.h b/src/plugins/clangtools/clangtoolsutils.h index 7b49dd9e0f5..4ee378cdc1e 100644 --- a/src/plugins/clangtools/clangtoolsutils.h +++ b/src/plugins/clangtools/clangtoolsutils.h @@ -27,6 +27,7 @@ #include +#include #include #include @@ -87,5 +88,7 @@ CppTools::ClangDiagnosticConfig diagnosticConfig(const Utils::Id &diagConfigId); QStringList extraClangToolsPrependOptions(); QStringList extraClangToolsAppendOptions(); +inline Utils::Id taskCategory() { return "ClangTools"; } + } // namespace Internal } // namespace ClangTools