From af2542f6b2f153e3de29901365ce05b68b3b70cc Mon Sep 17 00:00:00 2001 From: Yasser Grimes Date: Wed, 14 Jun 2023 18:49:05 +0300 Subject: [PATCH] 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 Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/mcusupport/CMakeLists.txt | 2 +- src/plugins/mcusupport/mcusupportplugin.cpp | 41 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/plugins/mcusupport/CMakeLists.txt b/src/plugins/mcusupport/CMakeLists.txt index e2d81ae5a73..cebf2e1a038 100644 --- a/src/plugins/mcusupport/CMakeLists.txt +++ b/src/plugins/mcusupport/CMakeLists.txt @@ -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 diff --git a/src/plugins/mcusupport/mcusupportplugin.cpp b/src/plugins/mcusupport/mcusupportplugin.cpp index ecdf89ded78..f0726e3895f 100644 --- a/src/plugins/mcusupport/mcusupportplugin.cpp +++ b/src/plugins/mcusupport/mcusupportplugin.cpp @@ -18,6 +18,7 @@ #include "test/unittest.h" #endif +#include #include #include #include @@ -34,9 +35,14 @@ #include +#include +#include + #include #include +#include +#include #include 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 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/");