forked from qt-creator/qt-creator
Nim: Collect project data asynchronously
... and provide a progress bar. Change-Id: I9d57c0dd1d26325eb9e6f15c8fada9e1fc398d9f Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "../nimconstants.h"
|
#include "../nimconstants.h"
|
||||||
|
|
||||||
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <projectexplorer/buildconfiguration.h>
|
#include <projectexplorer/buildconfiguration.h>
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
@@ -37,6 +38,8 @@
|
|||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/runextensions.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
@@ -60,9 +63,12 @@ NimProject::NimProject(NimProjectManager *projectManager, const QString &fileNam
|
|||||||
rootProjectNode()->setDisplayName(dir.dirName());
|
rootProjectNode()->setDisplayName(dir.dirName());
|
||||||
|
|
||||||
m_projectScanTimer.setSingleShot(true);
|
m_projectScanTimer.setSingleShot(true);
|
||||||
connect(&m_projectScanTimer, &QTimer::timeout, this, &NimProject::populateProject);
|
connect(&m_projectScanTimer, &QTimer::timeout, this, &NimProject::collectProjectFiles);
|
||||||
|
|
||||||
populateProject();
|
m_futureWatcher.setFuture(m_futureInterface.future());
|
||||||
|
connect(&m_futureWatcher, &QFutureWatcher<QList<FileNode *>>::finished, this, &NimProject::updateProject);
|
||||||
|
|
||||||
|
collectProjectFiles();
|
||||||
|
|
||||||
connect(&m_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &NimProject::scheduleProjectScan);
|
connect(&m_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &NimProject::scheduleProjectScan);
|
||||||
}
|
}
|
||||||
@@ -74,7 +80,7 @@ QString NimProject::displayName() const
|
|||||||
|
|
||||||
QStringList NimProject::files(FilesMode) const
|
QStringList NimProject::files(FilesMode) const
|
||||||
{
|
{
|
||||||
return QStringList(m_files.toList());
|
return m_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NimProject::needsConfiguration() const
|
bool NimProject::needsConfiguration() const
|
||||||
@@ -91,45 +97,51 @@ void NimProject::scheduleProjectScan()
|
|||||||
m_projectScanTimer.start();
|
m_projectScanTimer.start();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
populateProject();
|
collectProjectFiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimProject::populateProject()
|
void NimProject::collectProjectFiles()
|
||||||
{
|
{
|
||||||
m_lastProjectScan.start();
|
m_lastProjectScan.start();
|
||||||
|
QTC_ASSERT(!m_futureInterface.isRunning(), return);
|
||||||
|
|
||||||
QSet<QString> oldFiles = m_files;
|
runAsync([this]() {
|
||||||
|
m_futureInterface.reportStarted();
|
||||||
|
QList<FileNode *> nodes
|
||||||
|
= FileNode::scanForFiles(projectDirectory(),
|
||||||
|
[](const FileName &fn) { return new FileNode(fn, SourceType, false); },
|
||||||
|
&m_futureInterface);
|
||||||
|
m_futureInterface.setProgressValue(m_futureInterface.progressMaximum());
|
||||||
|
m_futureInterface.reportResult(nodes);
|
||||||
|
m_futureInterface.reportFinished();
|
||||||
|
});
|
||||||
|
Core::ProgressManager::addTask(m_futureInterface.future(), tr("Scanning for Nim files"), "Nim.Project.Scan");
|
||||||
|
}
|
||||||
|
|
||||||
|
void NimProject::updateProject()
|
||||||
|
{
|
||||||
|
QStringList oldFiles = m_files;
|
||||||
m_files.clear();
|
m_files.clear();
|
||||||
recursiveScanDirectory(QDir(projectDirectory().toString()), m_files);
|
|
||||||
|
|
||||||
if (m_files == oldFiles)
|
QList<FileNode *> fileNodes = Utils::filtered(m_futureInterface.future().result(),
|
||||||
|
[](const FileNode *fn) {
|
||||||
|
const QString fileName = fn->filePath().fileName();
|
||||||
|
return !fileName.endsWith(".nimproject", HostOsInfo::fileNameCaseSensitivity())
|
||||||
|
&& !fileName.contains(".nimproject.user", HostOsInfo::fileNameCaseSensitivity());
|
||||||
|
});
|
||||||
|
|
||||||
|
m_files = Utils::transform(fileNodes, [](const FileNode *fn) { return fn->filePath().toString(); });
|
||||||
|
Utils::sort(m_files, [](const QString &a, const QString &b) { return a < b; });
|
||||||
|
|
||||||
|
if (oldFiles == m_files)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList<FileNode *> fileNodes = Utils::transform(m_files.toList(), [](const QString &f) {
|
|
||||||
return new FileNode(FileName::fromString(f), SourceType, false);
|
|
||||||
});
|
|
||||||
rootProjectNode()->buildTree(fileNodes);
|
rootProjectNode()->buildTree(fileNodes);
|
||||||
|
|
||||||
emit fileListChanged();
|
emit fileListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimProject::recursiveScanDirectory(const QDir &dir, QSet<QString> &container)
|
|
||||||
{
|
|
||||||
static const QRegExp projectFilePattern(QLatin1String(".*\\.nimproject(?:\\.user)?$"));
|
|
||||||
for (const QFileInfo &info : dir.entryInfoList(QDir::AllDirs |
|
|
||||||
QDir::Files |
|
|
||||||
QDir::NoDotAndDotDot |
|
|
||||||
QDir::NoSymLinks |
|
|
||||||
QDir::CaseSensitive)) {
|
|
||||||
if (info.isDir())
|
|
||||||
recursiveScanDirectory(QDir(info.filePath()), container);
|
|
||||||
else if (projectFilePattern.indexIn(info.fileName()) == -1)
|
|
||||||
container << info.filePath();
|
|
||||||
}
|
|
||||||
m_fsWatcher.addPath(dir.absolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NimProject::supportsKit(Kit *k, QString *) const
|
bool NimProject::supportsKit(Kit *k, QString *) const
|
||||||
{
|
{
|
||||||
return k->isValid();
|
return k->isValid();
|
||||||
|
|||||||
@@ -28,8 +28,9 @@
|
|||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
|
|
||||||
#include <QFileSystemWatcher>
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QFutureWatcher>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace TextEditor { class TextDocument; }
|
namespace TextEditor { class TextDocument; }
|
||||||
@@ -54,11 +55,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void scheduleProjectScan();
|
void scheduleProjectScan();
|
||||||
void populateProject();
|
void collectProjectFiles();
|
||||||
void recursiveScanDirectory(const QDir &dir, QSet<QString> &container);
|
void updateProject();
|
||||||
|
|
||||||
QSet<QString> m_files;
|
QStringList m_files;
|
||||||
QFileSystemWatcher m_fsWatcher;
|
QFileSystemWatcher m_fsWatcher;
|
||||||
|
QFutureInterface<QList<ProjectExplorer::FileNode *>> m_futureInterface;
|
||||||
|
QFutureWatcher<QList<ProjectExplorer::FileNode *>> m_futureWatcher;
|
||||||
|
|
||||||
QElapsedTimer m_lastProjectScan;
|
QElapsedTimer m_lastProjectScan;
|
||||||
QTimer m_projectScanTimer;
|
QTimer m_projectScanTimer;
|
||||||
|
|||||||
Reference in New Issue
Block a user