diff --git a/src/plugins/cmakeprojectmanager/CMakeLists.txt b/src/plugins/cmakeprojectmanager/CMakeLists.txt index 2c58b4f08b3..7b282e79c85 100644 --- a/src/plugins/cmakeprojectmanager/CMakeLists.txt +++ b/src/plugins/cmakeprojectmanager/CMakeLists.txt @@ -43,6 +43,7 @@ add_qtc_plugin(CMakeProjectManager presetsparser.cpp presetsparser.h presetsmacros.cpp presetsmacros.h projecttreehelper.cpp projecttreehelper.h + targethelper.cpp targethelper.h 3rdparty/cmake/cmListFileCache.cxx 3rdparty/cmake/cmListFileLexer.cxx 3rdparty/cmake/cmListFileCache.h diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp index 2445cf58b60..01ed02bdb0c 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp @@ -3,10 +3,10 @@ #include "cmakelocatorfilter.h" -#include "cmakebuildstep.h" #include "cmakebuildsystem.h" #include "cmakeproject.h" #include "cmakeprojectmanagertr.h" +#include "targethelper.h" #include @@ -108,36 +108,6 @@ static void setupFilter(ILocatorFilter *filter) filter, projectListUpdated); } -static void buildAcceptor(const FilePath &projectPath, const QString &displayName) -{ - // Get the project containing the target selected - const auto cmakeProject = qobject_cast( - Utils::findOrDefault(ProjectManager::projects(), [projectPath](Project *p) { - return p->projectFilePath() == projectPath; - })); - if (!cmakeProject || !cmakeProject->activeTarget() - || !cmakeProject->activeTarget()->activeBuildConfiguration()) - return; - - if (BuildManager::isBuilding(cmakeProject)) - BuildManager::cancel(); - - // Find the make step - const BuildStepList *buildStepList = - cmakeProject->activeTarget()->activeBuildConfiguration()->buildSteps(); - const auto buildStep = buildStepList->firstOfType(); - if (!buildStep) - return; - - // Change the make step to build only the given target - const QStringList oldTargets = buildStep->buildTargets(); - buildStep->setBuildTargets({displayName}); - - // Build - BuildManager::buildProjectWithDependencies(cmakeProject); - buildStep->setBuildTargets(oldTargets); -} - class CMakeBuildTargetFilter final : ILocatorFilter { public: @@ -152,7 +122,7 @@ public: } private: - LocatorMatcherTasks matchers() final { return cmakeMatchers(&buildAcceptor); } + LocatorMatcherTasks matchers() final { return cmakeMatchers(&buildTarget); } }; // OpenCMakeTargetLocatorFilter diff --git a/src/plugins/cmakeprojectmanager/targethelper.cpp b/src/plugins/cmakeprojectmanager/targethelper.cpp new file mode 100644 index 00000000000..3d18deaa84a --- /dev/null +++ b/src/plugins/cmakeprojectmanager/targethelper.cpp @@ -0,0 +1,48 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "targethelper.h" + +#include +#include +#include +#include +#include + +#include "cmakebuildstep.h" +#include "cmakebuildsystem.h" +#include "cmakeproject.h" + +namespace CMakeProjectManager { + +void buildTarget(const Utils::FilePath &projectPath, const QString &targetName) +{ + // Get the project containing the target selected + const auto cmakeProject = qobject_cast(Utils::findOrDefault( + ProjectExplorer::ProjectManager::projects(), [projectPath](ProjectExplorer::Project *p) { + return p->projectFilePath() == projectPath; + })); + if (!cmakeProject || !cmakeProject->activeTarget() + || !cmakeProject->activeTarget()->activeBuildConfiguration()) + return; + + if (ProjectExplorer::BuildManager::isBuilding(cmakeProject)) + ProjectExplorer::BuildManager::cancel(); + + // Find the make step + const ProjectExplorer::BuildStepList *buildStepList + = cmakeProject->activeTarget()->activeBuildConfiguration()->buildSteps(); + const auto buildStep = buildStepList->firstOfType(); + if (!buildStep) + return; + + // Change the make step to build only the given target + const QStringList oldTargets = buildStep->buildTargets(); + buildStep->setBuildTargets({targetName}); + + // Build + ProjectExplorer::BuildManager::buildProjectWithDependencies(cmakeProject); + buildStep->setBuildTargets(oldTargets); +} + +} // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/targethelper.h b/src/plugins/cmakeprojectmanager/targethelper.h new file mode 100644 index 00000000000..1053d2b6d1b --- /dev/null +++ b/src/plugins/cmakeprojectmanager/targethelper.h @@ -0,0 +1,14 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "cmake_global.h" + +#include + +namespace CMakeProjectManager { + +CMAKE_EXPORT void buildTarget(const Utils::FilePath &projectPath, const QString &targetName); + +} // namespace CMakeProjectManager diff --git a/src/plugins/qmljseditor/CMakeLists.txt b/src/plugins/qmljseditor/CMakeLists.txt index 122bb39aed1..6f42b6794e5 100644 --- a/src/plugins/qmljseditor/CMakeLists.txt +++ b/src/plugins/qmljseditor/CMakeLists.txt @@ -1,5 +1,5 @@ add_qtc_plugin(QmlJSEditor - DEPENDS LanguageUtils QmlJS QmlEditorWidgets + DEPENDS LanguageUtils QmlJS QmlEditorWidgets CMakeProjectManager PLUGIN_DEPENDS Core ProjectExplorer QmlJSTools TextEditor LanguageClient SOURCES qmlexpressionundercursor.cpp qmlexpressionundercursor.h diff --git a/src/plugins/qmljseditor/qmljseditorconstants.h b/src/plugins/qmljseditor/qmljseditorconstants.h index 25cc711bf0c..5ffbbc98c3b 100644 --- a/src/plugins/qmljseditor/qmljseditorconstants.h +++ b/src/plugins/qmljseditor/qmljseditorconstants.h @@ -23,5 +23,7 @@ const char TASK_CATEGORY_QML_ANALYSIS[] = "Task.Category.QmlAnalysis"; const char QML_SNIPPETS_GROUP_ID[] = "QML"; +const char QMLLINT_BUILD_TARGET[] = "all_qmllint"; + } // namespace Constants } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmltaskmanager.cpp b/src/plugins/qmljseditor/qmltaskmanager.cpp index ca985f4022e..46cabe60992 100644 --- a/src/plugins/qmljseditor/qmltaskmanager.cpp +++ b/src/plugins/qmljseditor/qmltaskmanager.cpp @@ -3,11 +3,16 @@ #include "qmltaskmanager.h" #include "qmljseditorconstants.h" +#include "qmllssettings.h" +#include #include #include +#include #include +#include #include +#include #include #include #include @@ -113,8 +118,27 @@ void QmlTaskManager::updateSemanticMessagesNow() updateMessagesNow(true); } +static void triggerQmllintCMakeTarget() +{ + CMakeProjectManager::buildTarget( + ProjectManager::startupProject()->projectFilePath(), Constants::QMLLINT_BUILD_TARGET); +} + + void QmlTaskManager::updateMessagesNow(bool updateSemantic) { + // heuristic: qmllint will output meaningful warnings if qmlls is enabled + if (QmllsSettingsManager::instance()->lastSettings().useQmlls) { + // abort any update that's going on already, and remove old codemodel warnings + m_messageCollector.cancel(); + removeAllTasks(true); + triggerQmllintCMakeTarget(); + return; + } + + // clear out the qmllint warnings when qmlls was disabled after being enabled + TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_COMPILE); + // don't restart a small update if a big one is running if (!updateSemantic && m_updatingSemantic) return;