forked from qt-creator/qt-creator
Use qmllint for QML/JS > Run Checks when possible
Move the code from cmakelocatorfilter.cpp that builds a custom cmake target to a non-internal header, and use it to trigger builds of the "all_qmllint" target when doing QML/JS > Run Checks. Also clean the warnings from qmllint when running embedded code model checks and vice-versa. Task-number: QTCREATORBUG-31410 Change-Id: If22941fc63590caad148804a53edc62f9eb76e34 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -3,10 +3,10 @@
|
||||
|
||||
#include "cmakelocatorfilter.h"
|
||||
|
||||
#include "cmakebuildstep.h"
|
||||
#include "cmakebuildsystem.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakeprojectmanagertr.h"
|
||||
#include "targethelper.h"
|
||||
|
||||
#include <coreplugin/locator/ilocatorfilter.h>
|
||||
|
||||
@@ -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<CMakeProject *>(
|
||||
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<CMakeBuildStep>();
|
||||
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
|
||||
|
48
src/plugins/cmakeprojectmanager/targethelper.cpp
Normal file
48
src/plugins/cmakeprojectmanager/targethelper.cpp
Normal file
@@ -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 <projectexplorer/buildmanager.h>
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#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<CMakeProject *>(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<Internal::CMakeBuildStep>();
|
||||
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
|
14
src/plugins/cmakeprojectmanager/targethelper.h
Normal file
14
src/plugins/cmakeprojectmanager/targethelper.h
Normal file
@@ -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 <utils/filepath.h>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
|
||||
CMAKE_EXPORT void buildTarget(const Utils::FilePath &projectPath, const QString &targetName);
|
||||
|
||||
} // namespace CMakeProjectManager
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -3,11 +3,16 @@
|
||||
|
||||
#include "qmltaskmanager.h"
|
||||
#include "qmljseditorconstants.h"
|
||||
#include "qmllssettings.h"
|
||||
|
||||
#include <cmakeprojectmanager/targethelper.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsconstants.h>
|
||||
@@ -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;
|
||||
|
Reference in New Issue
Block a user