aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSami Shalayel <[email protected]>2025-11-24 14:57:53 +0100
committerSami Shalayel <[email protected]>2025-12-05 19:36:07 +0100
commit8c93c5ee591a4bdb8edcb9350fe996fa481e112f (patch)
tree06ca70bc4177b7a904d3cb03f44ff7cf52e0c720 /src
parent7288db71848f7f52ebeb20d6680ac00dd16eafd7 (diff)
qmlls: don't use build directories as import paths
Don't mix build and import paths in qmlls. Use build paths for build path operation (finding .qmlls.build.ini, eventually resource files, CMake invocations, ...) and the import paths for imports (when linting and constructing the DOM). Only use build paths as import paths as a fallback, for projects running on Qt < 6.10. It turns out that our tests were making heavy use of "build folders are import paths". Modernize the tst_qmlls_modules tests to write a .qmlls.build.ini file in the build folder which contains the import paths. Also don't read the import path twice from the qmlls.build.ini file, and read it from the QQmlCodeModelManager, not the QQmlCodeModel. Add a test for importPathsForFileUrl() that used to duplicate the import paths. Task-number: QTBUG-141707 Change-Id: I9eceb743bf37bc0f743954a0e7b1e5831f1989fa Reviewed-by: Ulf Hermann <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/qmlls/qqmlcodemodel.cpp29
-rw-r--r--src/qmlls/qqmlcodemodel_p.h3
-rw-r--r--src/qmlls/qqmllintsuggestions.cpp3
3 files changed, 11 insertions, 24 deletions
diff --git a/src/qmlls/qqmlcodemodel.cpp b/src/qmlls/qqmlcodemodel.cpp
index 9e1e1e96dc..84ac0f0350 100644
--- a/src/qmlls/qqmlcodemodel.cpp
+++ b/src/qmlls/qqmlcodemodel.cpp
@@ -572,8 +572,7 @@ void QQmlCodeModel::newDocForOpenFile(const QByteArray &url, int version, const
Path p;
auto newCurrentPtr = newCurrent.ownerAs<DomEnvironment>();
- const QStringList loadPaths = buildPathsForFileUrl(url) + importPathsForUrl(url);
- newCurrentPtr->setLoadPaths(loadPaths);
+ newCurrentPtr->setLoadPaths(importPathsForUrl(url));
newCurrentPtr->loadFile(FileToLoad::fromMemory(newCurrentPtr, fPath, docText),
[&p, this](Path, const DomItem &, const DomItem &newValue) {
const DomItem file = newValue.fileObject();
@@ -623,35 +622,28 @@ QStringList QQmlCodeModel::importPathsForUrl(const QByteArray &url)
{
QStringList result = importPaths();
+ // fallback for projects targeting Qt < 6.10, that don't have .qmlls.build.ini files
+ if (result.isEmpty() || result == QLibraryInfo::paths(QLibraryInfo::QmlImportsPath))
+ result << buildPathsForFileUrl(url);
+
const QString importPathsKey = u"importPaths"_s;
const QString fileName = url2Path(url);
if (m_settings && m_settings->search(fileName, { QString(), verbose() }).isValid()
&& m_settings->isSet(importPathsKey)) {
result.append(m_settings->valueAsAbsolutePathList(importPathsKey, fileName));
}
-
- const QStringList buildPath = buildPathsForFileUrl(url);
- QMutexLocker l(&m_mutex);
- m_buildInformation.loadSettingsFrom(buildPath);
- result.append(m_buildInformation.importPathsFor(fileName));
-
return result;
}
-void QQmlCodeModel::onBuildOrImportPathChanged()
-{
- const QStringList loadPaths = m_importPaths + m_buildPaths;
- if (const auto &env = m_currentEnv.ownerAs<DomEnvironment>())
- env->setLoadPaths(loadPaths);
- if (const auto &env = m_validEnv.ownerAs<DomEnvironment>())
- env->setLoadPaths(loadPaths);
-}
-
void QQmlCodeModel::setImportPaths(const QStringList &importPaths)
{
QMutexLocker guard(&m_mutex);
m_importPaths = importPaths;
- onBuildOrImportPathChanged();
+
+ if (const auto &env = m_currentEnv.ownerAs<DomEnvironment>())
+ env->setLoadPaths(importPaths);
+ if (const auto &env = m_validEnv.ownerAs<DomEnvironment>())
+ env->setLoadPaths(importPaths);
}
QStringList QQmlCodeModel::importPaths() const
@@ -712,7 +704,6 @@ void QQmlCodeModel::setBuildPaths(const QStringList &paths)
{
QMutexLocker l(&m_mutex);
m_buildPaths = paths;
- onBuildOrImportPathChanged();
}
void QQmlCodeModel::openUpdate(const QByteArray &url, UpdatePolicy policy)
diff --git a/src/qmlls/qqmlcodemodel_p.h b/src/qmlls/qqmlcodemodel_p.h
index e319a183fc..63f6241964 100644
--- a/src/qmlls/qqmlcodemodel_p.h
+++ b/src/qmlls/qqmlcodemodel_p.h
@@ -189,8 +189,6 @@ private:
void addFileWatches(const QQmlJS::Dom::DomItem &qmlFile);
- void onBuildOrImportPathChanged();
-
enum CMakeStatus { RequiresInitialization, HasCMake, DoesNotHaveCMake };
CMakeStatus cmakeStatus() const
{
@@ -218,7 +216,6 @@ private:
QHash<QByteArray, QString> m_url2path;
QHash<QString, QByteArray> m_path2url;
QHash<QByteArray, OpenDocument> m_openDocuments;
- QQmllsBuildInformation m_buildInformation;
QFileSystemWatcher m_cppFileWatcher;
RegisteredSemanticTokens m_tokens;
QString m_documentationRootPath;
diff --git a/src/qmlls/qqmllintsuggestions.cpp b/src/qmlls/qqmllintsuggestions.cpp
index 6eef7fb022..9ff28bda27 100644
--- a/src/qmlls/qqmllintsuggestions.cpp
+++ b/src/qmlls/qqmllintsuggestions.cpp
@@ -313,9 +313,8 @@ void QmlLintSuggestions::diagnoseHelper(const QByteArray &url,
diagnosticParams.version = version;
qCDebug(lintLog) << "has doc, do real lint";
- QStringList imports = m_codeModelManager->buildPathsForFileUrl(url);
+ QStringList imports = m_codeModelManager->importPathsForUrl(url);
const QString filename = doc.canonicalFilePath();
- imports.append(m_codeModelManager->importPathsForUrl(url));
// add source directory as last import as fallback in case there is no qmldir in the build
// folder this mimics qmllint behaviors
imports.append(QFileInfo(filename).dir().absolutePath());