Commit 8ab27353 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Be more efficient when looking for QML libraries.

Reviewed-by: Erik Verbruggen
parent abff92c0
......@@ -357,9 +357,7 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
if (import.type() != Interpreter::ImportInfo::LibraryImport)
continue;
foreach (const QString &importPath, importPaths) {
QDir dir(importPath);
dir.cd(import.name());
const QString targetPath = dir.absolutePath();
const QString targetPath = QDir(importPath).filePath(import.name());
// if we know there is a library, done
if (snapshot.libraryInfo(targetPath).isValid())
......@@ -367,30 +365,37 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
if (newLibraries->contains(targetPath))
break;
// if there is a qmldir file, we found a new library!
if (dir.exists("qmldir")) {
QFile qmldirFile(dir.filePath("qmldir"));
qmldirFile.open(QFile::ReadOnly);
QString qmldirData = QString::fromUtf8(qmldirFile.readAll());
QmlDirParser qmldirParser;
qmldirParser.setSource(qmldirData);
qmldirParser.parse();
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
newLibraries->insert(libraryPath);
modelManager->updateLibraryInfo(libraryPath,
LibraryInfo(qmldirParser));
// scan the qml files in the library
foreach (const QmlDirParser::Component &component, qmldirParser.components()) {
if (! component.fileName.isEmpty()) {
QFileInfo componentFileInfo(dir.filePath(component.fileName));
const QString path = componentFileInfo.absolutePath();
if (! scannedPaths->contains(path)) {
*importedFiles += qmlFilesInDirectory(path);
scannedPaths->insert(path);
}
// check for a qmldir file
const QDir targetDir(targetPath);
QFile qmldirFile(targetDir.filePath(QLatin1String("qmldir")));
if (!qmldirFile.exists())
continue;
#ifdef Q_OS_WIN
// QTCREATORBUG-3402 - be case sensitive even here?
#endif
// found a new library!
qmldirFile.open(QFile::ReadOnly);
QString qmldirData = QString::fromUtf8(qmldirFile.readAll());
QmlDirParser qmldirParser;
qmldirParser.setSource(qmldirData);
qmldirParser.parse();
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
newLibraries->insert(libraryPath);
modelManager->updateLibraryInfo(libraryPath,
LibraryInfo(qmldirParser));
// scan the qml files in the library
foreach (const QmlDirParser::Component &component, qmldirParser.components()) {
if (! component.fileName.isEmpty()) {
const QFileInfo componentFileInfo(targetDir.filePath(component.fileName));
const QString path = QDir::cleanPath(componentFileInfo.absolutePath());
if (! scannedPaths->contains(path)) {
*importedFiles += qmlFilesInDirectory(path);
scannedPaths->insert(path);
}
}
}
......@@ -544,7 +549,11 @@ void ModelManager::updateImportPaths()
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projects);
while (it.hasNext()) {
it.next();
m_allImportPaths += it.value().importPaths;
foreach (const QString &path, it.value().importPaths) {
const QString canonicalPath = QFileInfo(path).canonicalFilePath();
if (!canonicalPath.isEmpty())
m_allImportPaths += canonicalPath;
}
}
m_allImportPaths += m_defaultImportPaths;
m_allImportPaths.removeDuplicates();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment