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