tooling: derive import paths from QML engine import paths

Due to distro patches and default locations, we can't correctly derive
it without calling the QQmlEngine function.
This commit is contained in:
outfoxxed 2025-07-18 00:33:58 -07:00
parent e885f4aec1
commit 6572a7f61d
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -9,7 +9,7 @@
#include <qlist.h> #include <qlist.h>
#include <qlogging.h> #include <qlogging.h>
#include <qloggingcategory.h> #include <qloggingcategory.h>
#include <qnamespace.h> #include <qqmlengine.h>
#include <qtenvironmentvariables.h> #include <qtenvironmentvariables.h>
#include "logcat.hpp" #include "logcat.hpp"
@ -78,16 +78,10 @@ bool QmlToolingSupport::lockTooling() {
QString QmlToolingSupport::getQmllsConfig() { QString QmlToolingSupport::getQmllsConfig() {
static auto config = []() { static auto config = []() {
QList<QString> importPaths; // We can't replicate the algorithm used to create the import path list as it can have distro
// specific patches, e.g. nixos.
auto addPaths = [&](const QList<QString>& paths) { auto importPaths = QQmlEngine().importPathList();
for (const auto& path: paths) { importPaths.removeIf([](const QString& path) { return path.startsWith("qrc:"); });
if (!importPaths.contains(path)) importPaths.append(path);
}
};
addPaths(qEnvironmentVariable("QML_IMPORT_PATH").split(u':', Qt::SkipEmptyParts));
addPaths(qEnvironmentVariable("QML2_IMPORT_PATH").split(u':', Qt::SkipEmptyParts));
auto vfsPath = QsPaths::instance()->shellVfsDir()->path(); auto vfsPath = QsPaths::instance()->shellVfsDir()->path();
auto importPathsStr = importPaths.join(u':'); auto importPathsStr = importPaths.join(u':');