diff options
author | Filippo Cucchetto <filippocucchetto@gmail.com> | 2018-12-15 14:08:06 +0100 |
---|---|---|
committer | Filippo Cucchetto <filippocucchetto@gmail.com> | 2018-12-18 13:16:41 +0000 |
commit | f861ffd74342acff7305f82baf0cda173ae3e3ae (patch) | |
tree | ec9c290e748f6c2d9acae1fbdc596a4aad478e0f /src/plugins/nim | |
parent | 42f5c8516ae98db76ea547d1c236a3d297d4b777 (diff) |
Nim: Change remove_if to erase and fix missing emission of parsingFinished
Invoking remove_if without erase does nothing except placing the
removed elements to end of the container. This is fixed by using the
Utils::erase.
Furthermore the early return in the old code could cause the missing
emission of the parsingFinished signal.
Being there we applied some beautifications.
Change-Id: Icd11acb3ac4ab4735be1b5fba9cc785e9353a853
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/nim')
-rw-r--r-- | src/plugins/nim/project/nimproject.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/plugins/nim/project/nimproject.cpp b/src/plugins/nim/project/nimproject.cpp index 50a903044f3..fea3b457906 100644 --- a/src/plugins/nim/project/nimproject.cpp +++ b/src/plugins/nim/project/nimproject.cpp @@ -114,8 +114,9 @@ void NimProject::collectProjectFiles() QTC_ASSERT(!m_futureWatcher.future().isRunning(), return); FileName prjDir = projectDirectory(); QFuture<QList<ProjectExplorer::FileNode *>> future = Utils::runAsync([prjDir] { - return FileNode::scanForFiles( - prjDir, [](const FileName &fn) { return new FileNode(fn, FileType::Source, false); }); + return FileNode::scanForFiles(prjDir, [](const FileName &fn) { + return new FileNode(fn, FileType::Source, false); + }); }); m_futureWatcher.setFuture(future); Core::ProgressManager::addTask(future, tr("Scanning for Nim files"), "Nim.Project.Scan"); @@ -124,33 +125,33 @@ void NimProject::collectProjectFiles() void NimProject::updateProject() { emitParsingStarted(); - const QStringList oldFiles = m_files; - m_files.clear(); - - std::vector<std::unique_ptr<FileNode>> fileNodes - = transform<std::vector>(m_futureWatcher.future().result(), - [](FileNode *fn) { return std::unique_ptr<FileNode>(fn); }); - std::remove_if(std::begin(fileNodes), std::end(fileNodes), - [this](const std::unique_ptr<FileNode> &fn) { - const FileName path = fn->filePath(); + + auto fileNodes = Utils::transform<std::vector>(m_futureWatcher.future().result(), [](FileNode *node) { + return std::unique_ptr<FileNode>(node); + }); + + Utils::erase(fileNodes, [this](const std::unique_ptr<FileNode> &fn) { + const FileName &path = fn->filePath(); const QString fileName = path.fileName(); return m_excludedFiles.contains(path.toString()) || fileName.endsWith(".nimproject", HostOsInfo::fileNameCaseSensitivity()) || fileName.contains(".nimproject.user", HostOsInfo::fileNameCaseSensitivity()); }); - m_files = transform<QList>(fileNodes, [](const std::unique_ptr<FileNode> &fn) { + QStringList files = Utils::transform<QList>(fileNodes, [](const std::unique_ptr<FileNode> &fn) { return fn->filePath().toString(); }); - Utils::sort(m_files); - if (oldFiles == m_files) - return; + Utils::sort(files); + + if (files != m_files) { + m_files = std::move(files); + auto newRoot = std::make_unique<NimProjectNode>(*this, projectDirectory()); + newRoot->setDisplayName(displayName()); + newRoot->addNestedNodes(std::move(fileNodes)); + setRootProjectNode(std::move(newRoot)); + } - auto newRoot = std::make_unique<NimProjectNode>(*this, projectDirectory()); - newRoot->setDisplayName(displayName()); - newRoot->addNestedNodes(std::move(fileNodes)); - setRootProjectNode(std::move(newRoot)); emitParsingFinished(true); } |