QmlJS: Allow forced rescan on already known paths

Qml files used by Quick tests are not necessarily added to the
project file and therefore not fully handled by the QmlJS code
model / snapshot.
When adding qml files to a directory that is handled by the
code model these folders are not scanned again - we need to
enforce such a scan on AutoTest plugin's side.

Task-number: QTCREATORBUG-17805
Change-Id: Ie3d071a9aa03297d618648b06d52fb298c856d25
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
Christian Stenger
2017-03-07 15:49:02 +01:00
parent 179b845acb
commit 05e8f34d3e
3 changed files with 10 additions and 10 deletions

View File

@@ -990,7 +990,7 @@ struct ScanItem {
void ModelManagerInterface::importScan(QFutureInterface<void> &future,
ModelManagerInterface::WorkingCopy workingCopy,
PathsAndLanguages paths, ModelManagerInterface *modelManager,
bool emitDocChangedOnDisk, bool libOnly)
bool emitDocChangedOnDisk, bool libOnly, bool forceRescan)
{
// paths we have scanned for files and added to the files list
QSet<QString> scannedPaths;
@@ -1008,7 +1008,7 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
for (int i = 0; i < paths.size(); ++i) {
PathAndLanguage pAndL = paths.at(i);
QString cPath = QDir::cleanPath(pAndL.path().toString());
if (modelManager->m_scannedPaths.contains(cPath))
if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
continue;
pathsToScan.append(ScanItem(cPath, 0, pAndL.language()));
modelManager->m_scannedPaths.insert(cPath);
@@ -1024,13 +1024,15 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
ScanItem toScan = pathsToScan.last();
pathsToScan.pop_back();
int pathBudget = (1 << (maxScanDepth + 2 - toScan.depth));
if (!scannedPaths.contains(toScan.path)) {
if (forceRescan || !scannedPaths.contains(toScan.path)) {
QStringList importedFiles;
if (!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
if (forceRescan ||
(!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
&scannedPaths, &newLibraries, true)
&& !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty())
&& !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty())) {
importedFiles += filesInDirectoryForLanguages(toScan.path,
toScan.language.companionLanguages());
}
workDone += 1;
future.setProgressValue(progressRange * workDone / totalWork);
if (!importedFiles.isEmpty()) {
@@ -1101,7 +1103,7 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
if (pathToScan.length() > 1) {
QFuture<void> result = Utils::runAsync(&ModelManagerInterface::importScan,
workingCopyInternal(), pathToScan,
this, true, true);
this, true, true, false);
cleanupFutures();
m_futures.append(result);

View File

@@ -205,7 +205,7 @@ public:
WorkingCopy workingCopyInternal,
PathsAndLanguages paths,
ModelManagerInterface *modelManager,
bool emitDocChangedOnDisk, bool libOnly = true);
bool emitDocChangedOnDisk, bool libOnly = true, bool forceRescan = false);
virtual void resetCodeModel();
void removeProjectInfo(ProjectExplorer::Project *project);

View File

@@ -134,10 +134,8 @@ static QList<QmlJS::Document::Ptr> scanDirectoryForQuickTestQmlFiles(const QStri
QFutureInterface<void> future;
QmlJS::PathsAndLanguages paths;
paths.maybeInsert(Utils::FileName::fromString(srcDir), QmlJS::Dialect::Qml);
const bool emitDocumentChanges = false;
const bool onlyTheLib = false;
QmlJS::ModelManagerInterface::importScan(future, qmlJsMM->workingCopy(), paths, qmlJsMM,
emitDocumentChanges, onlyTheLib);
false /*emitDocumentChanges*/, false /*onlyTheLib*/, true /*forceRescan*/ );
const QmlJS::Snapshot snapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot();
QDirIterator it(srcDir, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);