diff options
Diffstat (limited to 'src/plugins/qmljstools/qmljsmodelmanager.cpp')
-rw-r--r-- | src/plugins/qmljstools/qmljsmodelmanager.cpp | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index 61470f40c2..36324371c4 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -232,6 +232,7 @@ QStringList QmlJSTools::qmlAndJsGlobPatterns() ModelManager::ModelManager(QObject *parent): ModelManagerInterface(parent), + m_shouldScanImports(false), m_pluginDumper(new PluginDumper(this)) { m_synchronizer.setCancelOnWait(true); @@ -328,7 +329,7 @@ ModelManagerInterface::WorkingCopy ModelManager::workingCopy() const if (TextEditor::BaseTextDocument *textDocument = qobject_cast<TextEditor::BaseTextDocument *>(document)) { // TODO the language should be a property on the document, not the editor if (documentModel->editorsForDocument(document).first()->context().contains(ProjectExplorer::Constants::LANG_QMLJS)) - workingCopy.insert(key, textDocument->contents(), textDocument->document()->revision()); + workingCopy.insert(key, textDocument->plainText(), textDocument->document()->revision()); } } @@ -380,6 +381,20 @@ QFuture<void> ModelManager::refreshSourceFiles(const QStringList &sourceFiles, if (sourceFiles.count() > 1) ProgressManager::addTask(result, tr("Indexing"), Constants::TASK_INDEX); + if (sourceFiles.count() > 1 && !m_shouldScanImports) { + bool scan = false; + { + QMutexLocker l(&m_mutex); + if (!m_shouldScanImports) { + m_shouldScanImports = true; + scan = true; + } + } + if (scan) + updateImportPaths(); + } + + return result; } @@ -939,24 +954,28 @@ void ModelManager::importScan(QFutureInterface<void> &future, QVector<ScanItem> pathsToScan; pathsToScan.reserve(paths.size()); - foreach (const QString &path, paths) { - QString cPath = QDir::cleanPath(path); - if (modelManager->m_scannedPaths.contains(cPath)) - continue; - pathsToScan.append(ScanItem(cPath)); + { + QMutexLocker l(&modelManager->m_mutex); + foreach (const QString &path, paths) { + QString cPath = QDir::cleanPath(path); + if (modelManager->m_scannedPaths.contains(cPath)) + continue; + pathsToScan.append(ScanItem(cPath)); + modelManager->m_scannedPaths.insert(cPath); + } } const int maxScanDepth = 5; int progressRange = pathsToScan.size() * (1 << (2 + maxScanDepth)); int totalWork(progressRange), workDone(0); future.setProgressRange(0, progressRange); // update max length while iterating? const bool libOnly = true; // FIXME remove when tested more + const Snapshot snapshot = modelManager->snapshot(); while (!pathsToScan.isEmpty() && !future.isCanceled()) { ScanItem toScan = pathsToScan.last(); pathsToScan.pop_back(); int pathBudget = (maxScanDepth + 2 - toScan.depth); if (!scannedPaths.contains(toScan.path)) { QStringList importedFiles; - const Snapshot snapshot = modelManager->snapshot(); if (!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles, &scannedPaths, &newLibraries, true) && !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty()) @@ -989,6 +1008,12 @@ void ModelManager::importScan(QFutureInterface<void> &future, future.setProgressValue(progressRange * workDone / totalWork); } future.setProgressValue(progressRange); + if (future.isCanceled()) { + // assume no work has been done + QMutexLocker l(&modelManager->m_mutex); + foreach (const QString &path, paths) + modelManager->m_scannedPaths.remove(path); + } } // Check whether fileMimeType is the same or extends knownMimeType @@ -1103,10 +1128,16 @@ void ModelManager::updateImportPaths() updateSourceFiles(importedFiles, true); + if (!m_shouldScanImports) + return; QStringList pathToScan; - foreach (QString importPath, allImportPaths) - if (!m_scannedPaths.contains(importPath)) - pathToScan.append(importPath); + { + QMutexLocker l(&m_mutex); + foreach (QString importPath, allImportPaths) + if (!m_scannedPaths.contains(importPath)) { + pathToScan.append(importPath); + } + } if (pathToScan.count() > 1) { QFuture<void> result = QtConcurrent::run(&ModelManager::importScan, |