McuSupport: Add workaround for CodeModel/SymanticsChecker race condition

Currently it can happen that some qml files will not be picked in the
CodeModel Snapshot when the Semantic Checks are performed resulting in
wrong errors in the code editor QTCREATORBUG-29269
Triggering QmlJS ResetModel fix the errors.

This change will make triggering the Reset automatic.

Fixes: QTCREATORBUG-29155
Fixes: QTCREATORBUG-26655
Change-Id: I8a7fb4d3bca336fde9029fe3e7fb54e9281c44f4
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Yasser Grimes
2023-06-14 18:49:05 +03:00
parent ff856ed030
commit af2542f6b2
2 changed files with 42 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
add_qtc_plugin(McuSupport
DEPENDS Qt::Core
DEPENDS Qt::Core QmlJS
PLUGIN_DEPENDS Core BareMetal ProjectExplorer Debugger CMakeProjectManager QtSupport
SOURCES
mcukitinformation.cpp mcukitinformation.h

View File

@@ -18,6 +18,7 @@
#include "test/unittest.h"
#endif
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
@@ -34,9 +35,14 @@
#include <cmakeprojectmanager/cmakeprojectconstants.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljstools/qmljstoolsconstants.h>
#include <utils/filepath.h>
#include <utils/infobar.h>
#include <QAction>
#include <QDateTime>
#include <QTimer>
using namespace Core;
@@ -119,6 +125,41 @@ void McuSupportPlugin::initialize()
&ProjectManager::projectFinishedParsing,
updateMCUProjectTree);
// Temporary fix for CodeModel/Checker race condition
// Remove after https://bugreports.qt.io/browse/QTCREATORBUG-29269 is closed
connect(QmlJS::ModelManagerInterface::instance(),
&QmlJS::ModelManagerInterface::documentUpdated,
[lasttime = QTime::currentTime()](QmlJS::Document::Ptr doc) mutable {
// Prevent inifinite recall loop
auto currenttime = QTime::currentTime();
if (lasttime.msecsTo(currenttime) < 1000) {
lasttime = currenttime;
return;
}
lasttime = currenttime;
if (!doc)
return;
//Reset code model only for QtMCUs documents
const Project *project = ProjectManager::projectForFile(doc->path());
if (!project)
return;
const QList<Target *> targets = project->targets();
bool isMcuDocument
= std::any_of(std::begin(targets), std::end(targets), [](const Target *target) {
if (!target || !target->kit()
|| !target->kit()->hasValue(Constants::KIT_MCUTARGET_KITVERSION_KEY))
return false;
return true;
});
if (!isMcuDocument)
return;
Core::ActionManager::command(QmlJSTools::Constants::RESET_CODEMODEL)
->action()
->trigger();
});
dd->m_options.registerQchFiles();
dd->m_options.registerExamples();
ProjectExplorer::JsonWizardFactory::addWizardPath(":/mcusupport/wizards/");