Clang: Add progress bars for creating PCHs and indexing

Task-number: QTCREATORBUG-21112
Change-Id: Ie0c00a58f479a2fe7cbc7322490808509733ff0f
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-09-27 17:52:44 +02:00
parent ffc070a3f2
commit 391cfab5d7
60 changed files with 865 additions and 49 deletions

View File

@@ -25,7 +25,8 @@
#pragma once #pragma once
#include "alivemessage.h"
#include "progressmessage.h"
#include "sourcelocationsforrenamingmessage.h" #include "sourcelocationsforrenamingmessage.h"
#include "sourcerangesanddiagnosticsforquerymessage.h" #include "sourcerangesanddiagnosticsforquerymessage.h"
#include "sourcerangesforquerymessage.h" #include "sourcerangesforquerymessage.h"
#include "alivemessage.h"

View File

@@ -203,6 +203,8 @@ HEADERS += \
$$PWD/updategeneratedfilesmessage.h \ $$PWD/updategeneratedfilesmessage.h \
$$PWD/removegeneratedfilesmessage.h \ $$PWD/removegeneratedfilesmessage.h \
$$PWD/generatedfiles.h \ $$PWD/generatedfiles.h \
$$PWD/generatedfilesinterface.h $$PWD/generatedfilesinterface.h \
$$PWD/progressmessage.h \
$$PWD/progresscounter.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

View File

@@ -177,7 +177,8 @@ enum class MessageType : quint8 {
RemoveProjectPartsMessage, RemoveProjectPartsMessage,
PrecompiledHeadersUpdatedMessage, PrecompiledHeadersUpdatedMessage,
UpdateGeneratedFilesMessage, UpdateGeneratedFilesMessage,
RemoveGeneratedFilesMessage RemoveGeneratedFilesMessage,
ProgressMessage
}; };
template<MessageType messageEnumeration> template<MessageType messageEnumeration>
@@ -234,4 +235,11 @@ enum class SymbolTag : uchar
using SymbolTags = Utils::SizedArray<SymbolTag, 7>; using SymbolTags = Utils::SizedArray<SymbolTag, 7>;
enum class ProgressType
{
Invalid,
PrecompiledHeader,
Indexing
};
} }

View File

@@ -27,6 +27,7 @@
#include "messageenvelop.h" #include "messageenvelop.h"
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmessage.h>
#include <QDebug> #include <QDebug>
@@ -41,6 +42,9 @@ void PchManagerClientInterface::dispatch(const MessageEnvelop &messageEnvelop)
case MessageType::PrecompiledHeadersUpdatedMessage: case MessageType::PrecompiledHeadersUpdatedMessage:
precompiledHeadersUpdated(messageEnvelop.message<PrecompiledHeadersUpdatedMessage>()); precompiledHeadersUpdated(messageEnvelop.message<PrecompiledHeadersUpdatedMessage>());
break; break;
case MessageType::ProgressMessage:
progress(messageEnvelop.message<ProgressMessage>());
break;
default: default:
qWarning() << "Unknown IpcClientMessage"; qWarning() << "Unknown IpcClientMessage";
} }

View File

@@ -30,6 +30,7 @@
namespace ClangBackEnd { namespace ClangBackEnd {
class PrecompiledHeadersUpdatedMessage; class PrecompiledHeadersUpdatedMessage;
class ProgressMessage;
class CLANGSUPPORT_EXPORT PchManagerClientInterface : public IpcClientInterface class CLANGSUPPORT_EXPORT PchManagerClientInterface : public IpcClientInterface
{ {
@@ -38,6 +39,7 @@ public:
virtual void alive() = 0; virtual void alive() = 0;
virtual void precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) = 0; virtual void precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) = 0;
virtual void progress(ProgressMessage &&message) = 0;
protected: protected:
~PchManagerClientInterface() = default; ~PchManagerClientInterface() = default;

View File

@@ -29,6 +29,7 @@
#include "messageenvelop.h" #include "messageenvelop.h"
#include "pchmanagerserverinterface.h" #include "pchmanagerserverinterface.h"
#include "precompiledheadersupdatedmessage.h" #include "precompiledheadersupdatedmessage.h"
#include "progressmessage.h"
#include <QDebug> #include <QDebug>
#include <QIODevice> #include <QIODevice>
@@ -78,4 +79,9 @@ void PchManagerClientProxy::precompiledHeadersUpdated(PrecompiledHeadersUpdatedM
writeMessageBlock.write(message); writeMessageBlock.write(message);
} }
void PchManagerClientProxy::progress(ProgressMessage &&message)
{
writeMessageBlock.write(message);
}
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -48,6 +48,7 @@ public:
void alive() override; void alive() override;
void precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) override; void precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) override;
void progress(ProgressMessage &&message) override;
private: private:
ClangBackEnd::WriteMessageBlock writeMessageBlock; ClangBackEnd::WriteMessageBlock writeMessageBlock;

View File

@@ -0,0 +1,88 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <functional>
namespace ClangBackEnd {
class ProgressCounter
{
public:
using SetProgressCallback = std::function<void(int, int)>;
ProgressCounter(SetProgressCallback &&progressCallback)
: m_progressCallback(std::move(progressCallback))
{}
void addTotal(int total)
{
m_total += total;
m_progressCallback(m_progress, m_total);
}
void removeTotal(int total)
{
m_total -= total;
sendProgress();
}
void addProgress(int progress)
{
m_progress += progress;
sendProgress();
}
void sendProgress()
{
m_progressCallback(m_progress, m_total);
if (m_progress >= m_total) {
m_progress = 0;
m_total = 0;
}
}
int total() const
{
return m_total;
}
int progress() const
{
return m_total;
}
private:
std::function<void(int, int)> m_progressCallback;
int m_progress = 0;
int m_total = 0;
};
}

View File

@@ -0,0 +1,79 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "clangsupport_global.h"
#include <QDataStream>
namespace ClangBackEnd {
class ProgressMessage
{
public:
ProgressMessage() = default;
ProgressMessage(ProgressType progressType, int progress, int total)
: progressType(progressType),
progress(progress),
total(total)
{}
friend QDataStream &operator<<(QDataStream &out, const ProgressMessage &message)
{
out << message.progress;
out << message.total;
return out;
}
friend QDataStream &operator>>(QDataStream &in, ProgressMessage &message)
{
in >> message.progress;
in >> message.total;
return in;
}
friend bool operator==(const ProgressMessage &first, const ProgressMessage &second)
{
return first.progress == second.progress
&& first.total == second.total;
}
ProgressMessage clone() const
{
return *this;
}
public:
ProgressType progressType = ProgressType::Invalid;
int progress = 0;
int total = 0;
};
DECLARE_MESSAGE(ProgressMessage)
} // namespace ClangBackEnd

View File

@@ -47,6 +47,9 @@ void RefactoringClientInterface::dispatch(const MessageEnvelop &messageEnvelop)
case MessageType::SourceRangesForQueryMessage: case MessageType::SourceRangesForQueryMessage:
sourceRangesForQueryMessage(messageEnvelop.message<SourceRangesForQueryMessage>()); sourceRangesForQueryMessage(messageEnvelop.message<SourceRangesForQueryMessage>());
break; break;
case MessageType::ProgressMessage:
progress(messageEnvelop.message<ProgressMessage>());
break;
default: default:
qWarning() << "Unknown IpcClientMessage"; qWarning() << "Unknown IpcClientMessage";
} }

View File

@@ -31,6 +31,7 @@
namespace ClangBackEnd { namespace ClangBackEnd {
class ProgressMessage;
class SourceLocationsForRenamingMessage; class SourceLocationsForRenamingMessage;
class SourceRangesAndDiagnosticsForQueryMessage; class SourceRangesAndDiagnosticsForQueryMessage;
class SourceRangesForQueryMessage; class SourceRangesForQueryMessage;
@@ -49,8 +50,8 @@ public:
virtual void sourceLocationsForRenamingMessage(SourceLocationsForRenamingMessage &&message) = 0; virtual void sourceLocationsForRenamingMessage(SourceLocationsForRenamingMessage &&message) = 0;
virtual void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) = 0; virtual void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) = 0;
virtual void sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) = 0; virtual void sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) = 0;
virtual void setLocalRenamingCallback(RenameCallback &&localRenamingCallback) = 0; virtual void setLocalRenamingCallback(RenameCallback &&localRenamingCallback) = 0;
virtual void progress(ProgressMessage &&message) = 0;
protected: protected:
~RefactoringClientInterface() = default; ~RefactoringClientInterface() = default;

View File

@@ -86,7 +86,12 @@ void RefactoringClientProxy::sourceRangesAndDiagnosticsForQueryMessage(SourceRan
void RefactoringClientProxy::sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) void RefactoringClientProxy::sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message)
{ {
writeMessageBlock.write(message); writeMessageBlock.write(message);
}
void RefactoringClientProxy::progress(ProgressMessage &&message)
{
writeMessageBlock.write(message);
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -52,6 +52,7 @@ public:
void sourceLocationsForRenamingMessage(SourceLocationsForRenamingMessage &&message) override; void sourceLocationsForRenamingMessage(SourceLocationsForRenamingMessage &&message) override;
void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) override; void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) override;
void sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) override; void sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) override;
void progress(ProgressMessage &&message) override;
void setLocalRenamingCallback(RenameCallback &&) final {} void setLocalRenamingCallback(RenameCallback &&) final {}

View File

@@ -12,7 +12,9 @@ HEADERS += \
$$PWD/pchmanagerconnectionclient.h \ $$PWD/pchmanagerconnectionclient.h \
$$PWD/clangpchmanager_global.h \ $$PWD/clangpchmanager_global.h \
$$PWD/projectupdater.h \ $$PWD/projectupdater.h \
$$PWD/pchmanagerprojectupdater.h $$PWD/pchmanagerprojectupdater.h \
$$PWD/progressmanager.h \
$$PWD/progressmanagerinterface.h
SOURCES += \ SOURCES += \
$$PWD/pchmanagerclient.cpp \ $$PWD/pchmanagerclient.cpp \

View File

@@ -13,6 +13,7 @@ win32 {
HEADERS += \ HEADERS += \
$$PWD/clangpchmanagerplugin.h \ $$PWD/clangpchmanagerplugin.h \
qtcreatorprojectupdater.h qtcreatorprojectupdater.h
SOURCES += \ SOURCES += \
$$PWD/clangpchmanagerplugin.cpp \ $$PWD/clangpchmanagerplugin.cpp \
qtcreatorprojectupdater.cpp qtcreatorprojectupdater.cpp

View File

@@ -27,6 +27,7 @@
#include "pchmanagerconnectionclient.h" #include "pchmanagerconnectionclient.h"
#include "pchmanagerclient.h" #include "pchmanagerclient.h"
#include "progressmanager.h"
#include "qtcreatorprojectupdater.h" #include "qtcreatorprojectupdater.h"
#include <filepathcaching.h> #include <filepathcaching.h>
@@ -34,10 +35,13 @@
#include <sqlitedatabase.h> #include <sqlitedatabase.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <QFutureInterface>
#include <chrono> #include <chrono>
using namespace std::chrono_literals; using namespace std::chrono_literals;
@@ -61,7 +65,12 @@ public:
Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}, 1000ms}; Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}, 1000ms};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
ClangBackEnd::FilePathCaching filePathCache{database}; ClangBackEnd::FilePathCaching filePathCache{database};
PchManagerClient pchManagerClient; ClangPchManager::ProgressManager progressManager{
[] (QFutureInterface<void> &promise) {
auto title = QCoreApplication::translate("ClangPchProgressManager", "Creating PCHs", "PCH stands for precompiled header");
Core::ProgressManager::addTask(promise.future(), title, "pch creation", nullptr);
}};
PchManagerClient pchManagerClient{progressManager};
PchManagerConnectionClient connectionClient{&pchManagerClient}; PchManagerConnectionClient connectionClient{&pchManagerClient};
QtCreatorProjectUpdater<PchManagerProjectUpdater> projectUpdate{connectionClient.serverProxy(), QtCreatorProjectUpdater<PchManagerProjectUpdater> projectUpdate{connectionClient.serverProxy(),
pchManagerClient, pchManagerClient,

View File

@@ -26,8 +26,9 @@
#include "pchmanagerclient.h" #include "pchmanagerclient.h"
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmanagerinterface.h>
#include <progressmessage.h>
#include <pchmanagerconnectionclient.h> #include <pchmanagerconnectionclient.h>
#include <pchmanagernotifierinterface.h> #include <pchmanagernotifierinterface.h>
#include <algorithm> #include <algorithm>
@@ -50,6 +51,11 @@ void PchManagerClient::precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeader
} }
} }
void PchManagerClient::progress(ClangBackEnd::ProgressMessage &&message)
{
m_progressManager.setProgress(message.progress, message.total);
}
void PchManagerClient::precompiledHeaderRemoved(const QString &projectPartId) void PchManagerClient::precompiledHeaderRemoved(const QString &projectPartId)
{ {
for (auto notifier : m_notifiers) { for (auto notifier : m_notifiers) {

View File

@@ -34,7 +34,7 @@
namespace ClangPchManager { namespace ClangPchManager {
class PchManagerConnectionClient; class PchManagerConnectionClient;
class ProgressManagerInterface;
class PchManagerNotifierInterface; class PchManagerNotifierInterface;
class CLANGPCHMANAGER_EXPORT PchManagerClient final : public ClangBackEnd::PchManagerClientInterface, class CLANGPCHMANAGER_EXPORT PchManagerClient final : public ClangBackEnd::PchManagerClientInterface,
@@ -42,9 +42,13 @@ class CLANGPCHMANAGER_EXPORT PchManagerClient final : public ClangBackEnd::PchMa
{ {
friend class PchManagerNotifierInterface; friend class PchManagerNotifierInterface;
public: public:
PchManagerClient() = default; PchManagerClient(ProgressManagerInterface &progressManager)
: m_progressManager(progressManager)
{}
void alive() override; void alive() override;
void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override; void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override;
void progress(ClangBackEnd::ProgressMessage &&message) override;
void precompiledHeaderRemoved(const QString &projectPartId); void precompiledHeaderRemoved(const QString &projectPartId);
@@ -74,6 +78,7 @@ private:
ClangBackEnd::ProjectPartPchs m_projectPartPchs; ClangBackEnd::ProjectPartPchs m_projectPartPchs;
std::vector<PchManagerNotifierInterface*> m_notifiers; std::vector<PchManagerNotifierInterface*> m_notifiers;
PchManagerConnectionClient *m_connectionClient=nullptr; PchManagerConnectionClient *m_connectionClient=nullptr;
ProgressManagerInterface &m_progressManager;
}; };
} // namespace ClangPchManager } // namespace ClangPchManager

View File

@@ -0,0 +1,84 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "progressmanagerinterface.h"
#include <QFutureInterface>
#include <QCoreApplication>
#include <QString>
#include <functional>
#include <memory>
namespace ClangPchManager {
class ProgressManager : public ProgressManagerInterface
{
public:
using Promise = QFutureInterface<void>;
using Callback = std::function<void(Promise &)>;
ProgressManager(Callback &&callback)
: m_callback(std::move(callback))
{}
void setProgress(int currentProgress, int maximumProgress)
{
if (!m_promise)
initialize();
m_promise->setExpectedResultCount(maximumProgress);
m_promise->setProgressValue(currentProgress);
if (currentProgress >= maximumProgress)
finish();
}
Promise *promise()
{
return m_promise.get();
}
private:
void initialize()
{
m_promise = std::make_unique<Promise>();
m_callback(*m_promise);
}
void finish()
{
m_promise->reportFinished();
m_promise.reset();
}
private:
Callback m_callback;
std::unique_ptr<Promise> m_promise;
};
} // namespace ClangPchManager

View File

@@ -0,0 +1,39 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
namespace ClangPchManager {
class ProgressManagerInterface
{
public:
virtual void setProgress(int currentProgress, int maximumProgress) = 0;
protected:
~ProgressManagerInterface() = default;
};
} // namespace ClangPchManager

View File

@@ -34,11 +34,13 @@
#include "symbolquery.h" #include "symbolquery.h"
#include <clangpchmanager/clangpchmanagerplugin.h> #include <clangpchmanager/clangpchmanagerplugin.h>
#include <clangpchmanager/progressmanager.h>
#include <clangsupport/refactoringdatabaseinitializer.h> #include <clangsupport/refactoringdatabaseinitializer.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
@@ -46,7 +48,6 @@
#include <filepathcaching.h> #include <filepathcaching.h>
#include <sqlitedatabase.h> #include <sqlitedatabase.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <QDir> #include <QDir>
@@ -79,13 +80,16 @@ public:
Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}, 1000ms}; Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}, 1000ms};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
ClangBackEnd::FilePathCaching filePathCache{database}; ClangBackEnd::FilePathCaching filePathCache{database};
RefactoringClient refactoringClient; ClangPchManager::ProgressManager progressManager{
[] (QFutureInterface<void> &promise) {
auto title = QCoreApplication::translate("ClangRefactoringProgressManager", "C++ Indexing");
Core::ProgressManager::addTask(promise.future(), title, "clang indexing", nullptr);}};
RefactoringClient refactoringClient{progressManager};
QtCreatorEditorManager editorManager{filePathCache}; QtCreatorEditorManager editorManager{filePathCache};
ClangBackEnd::RefactoringConnectionClient connectionClient{&refactoringClient}; ClangBackEnd::RefactoringConnectionClient connectionClient{&refactoringClient};
QuerySqliteReadStatementFactory statementFactory{database}; QuerySqliteReadStatementFactory statementFactory{database};
SymbolQuery<QuerySqliteReadStatementFactory> symbolQuery{statementFactory}; SymbolQuery<QuerySqliteReadStatementFactory> symbolQuery{statementFactory};
RefactoringEngine engine{connectionClient.serverProxy(), refactoringClient, filePathCache, symbolQuery}; RefactoringEngine engine{connectionClient.serverProxy(), refactoringClient, filePathCache, symbolQuery};
QtCreatorSearch qtCreatorSearch; QtCreatorSearch qtCreatorSearch;
QtCreatorClangQueryFindFilter qtCreatorfindFilter{connectionClient.serverProxy(), QtCreatorClangQueryFindFilter qtCreatorfindFilter{connectionClient.serverProxy(),
qtCreatorSearch, qtCreatorSearch,

View File

@@ -70,6 +70,11 @@ void RefactoringClient::setLocalRenamingCallback(
m_localRenamingCallback = std::move(localRenamingCallback); m_localRenamingCallback = std::move(localRenamingCallback);
} }
void RefactoringClient::progress(ClangBackEnd::ProgressMessage &&message)
{
m_progressManager.setProgress(message.progress, message.total);
}
void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngine) void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngine)
{ {
m_refactoringEngine = refactoringEngine; m_refactoringEngine = refactoringEngine;

View File

@@ -30,6 +30,7 @@
#include "searchhandle.h" #include "searchhandle.h"
#include <refactoringclientinterface.h> #include <refactoringclientinterface.h>
#include <clangpchmanager/progressmanager.h>
#include <functional> #include <functional>
@@ -48,6 +49,10 @@ class ClangQueryHighlighter;
class RefactoringClient final : public ClangBackEnd::RefactoringClientInterface class RefactoringClient final : public ClangBackEnd::RefactoringClientInterface
{ {
public: public:
RefactoringClient(ClangPchManager::ProgressManagerInterface &progressManager)
: m_progressManager(progressManager)
{}
void alive() override; void alive() override;
void sourceLocationsForRenamingMessage( void sourceLocationsForRenamingMessage(
ClangBackEnd::SourceLocationsForRenamingMessage &&message) override; ClangBackEnd::SourceLocationsForRenamingMessage &&message) override;
@@ -58,6 +63,8 @@ public:
void setLocalRenamingCallback( void setLocalRenamingCallback(
CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback) override; CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback) override;
void progress(ClangBackEnd::ProgressMessage &&message) override;
void setRefactoringEngine(ClangRefactoring::RefactoringEngine *refactoringEngine); void setRefactoringEngine(ClangRefactoring::RefactoringEngine *refactoringEngine);
void setSearchHandle(ClangRefactoring::SearchHandle *searchHandleInterface); void setSearchHandle(ClangRefactoring::SearchHandle *searchHandleInterface);
ClangRefactoring::SearchHandle *searchHandle() const; ClangRefactoring::SearchHandle *searchHandle() const;
@@ -72,6 +79,7 @@ public:
void setRefactoringConnectionClient(ClangBackEnd::RefactoringConnectionClient *connectionClient); void setRefactoringConnectionClient(ClangBackEnd::RefactoringConnectionClient *connectionClient);
unittest_public: unittest_public:
void addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRange); void addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRange);
@@ -88,6 +96,7 @@ private:
RefactoringEngine *m_refactoringEngine = nullptr; RefactoringEngine *m_refactoringEngine = nullptr;
ClangQueryExampleHighlighter *m_clangQueryExampleHighlighter = nullptr; ClangQueryExampleHighlighter *m_clangQueryExampleHighlighter = nullptr;
ClangQueryHighlighter *m_clangQueryHighlighter = nullptr; ClangQueryHighlighter *m_clangQueryHighlighter = nullptr;
ClangPchManager::ProgressManagerInterface &m_progressManager;
uint m_expectedResultCount = 0; uint m_expectedResultCount = 0;
uint m_resultCounter = 0; uint m_resultCounter = 0;
}; };

View File

@@ -32,6 +32,7 @@
#include <pchmanagerclientproxy.h> #include <pchmanagerclientproxy.h>
#include <precompiledheaderstorage.h> #include <precompiledheaderstorage.h>
#include <processormanager.h> #include <processormanager.h>
#include <progresscounter.h>
#include <projectparts.h> #include <projectparts.h>
#include <projectpartqueue.h> #include <projectpartqueue.h>
#include <filepathcaching.h> #include <filepathcaching.h>
@@ -174,8 +175,9 @@ struct Data // because we have a cycle dependency
GeneratedFiles generatedFiles; GeneratedFiles generatedFiles;
PchCreatorManager pchCreatorManager{generatedFiles, environment, database, clangPchManagerServer, includeWatcher}; PchCreatorManager pchCreatorManager{generatedFiles, environment, database, clangPchManagerServer, includeWatcher};
PrecompiledHeaderStorage<> preCompiledHeaderStorage{database}; PrecompiledHeaderStorage<> preCompiledHeaderStorage{database};
TaskScheduler taskScheduler{pchCreatorManager, projectPartQueue, std::thread::hardware_concurrency()}; ClangBackEnd::ProgressCounter progressCounter{[&] (int progress, int total) { clangPchManagerServer.setProgress(progress, total); }};
ClangBackEnd::ProjectPartQueue projectPartQueue{taskScheduler, preCompiledHeaderStorage, database}; TaskScheduler taskScheduler{pchCreatorManager, projectPartQueue, progressCounter, std::thread::hardware_concurrency()};
ClangBackEnd::ProjectPartQueue projectPartQueue{taskScheduler, preCompiledHeaderStorage, database, progressCounter};
PchManagerServer clangPchManagerServer{includeWatcher, projectPartQueue, projectParts, generatedFiles}; PchManagerServer clangPchManagerServer{includeWatcher, projectPartQueue, projectParts, generatedFiles};
}; };

View File

@@ -27,6 +27,7 @@
#include <pchmanagerclientinterface.h> #include <pchmanagerclientinterface.h>
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmessage.h>
#include <projectpartqueue.h> #include <projectpartqueue.h>
#include <removegeneratedfilesmessage.h> #include <removegeneratedfilesmessage.h>
#include <removeprojectpartsmessage.h> #include <removeprojectpartsmessage.h>
@@ -90,4 +91,9 @@ void PchManagerServer::pathsChanged(const FilePathIds &/*filePathIds*/)
{ {
} }
void PchManagerServer::setProgress(int progress, int total)
{
client()->progress({ProgressType::PrecompiledHeader, progress, total});
}
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -59,6 +59,8 @@ public:
void pathsWithIdsChanged(const Utils::SmallStringVector &ids) override; void pathsWithIdsChanged(const Utils::SmallStringVector &ids) override;
void pathsChanged(const FilePathIds &filePathIds) override; void pathsChanged(const FilePathIds &filePathIds) override;
void setProgress(int progress, int total);
private: private:
ClangPathWatcherInterface &m_fileSystemWatcher; ClangPathWatcherInterface &m_fileSystemWatcher;
ProjectPartQueueInterface &m_projectPartQueue; ProjectPartQueueInterface &m_projectPartQueue;

View File

@@ -27,6 +27,7 @@
#include <pchcreatorinterface.h> #include <pchcreatorinterface.h>
#include <precompiledheaderstorageinterface.h> #include <precompiledheaderstorageinterface.h>
#include <progresscounter.h>
#include <sqlitetransaction.h> #include <sqlitetransaction.h>
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -37,6 +38,8 @@ void ProjectPartQueue::addProjectParts(V2::ProjectPartContainers &&projectParts)
return first.projectPartId < second.projectPartId; return first.projectPartId < second.projectPartId;
}; };
const std::size_t oldSize = m_projectParts.size();
V2::ProjectPartContainers mergedProjectParts; V2::ProjectPartContainers mergedProjectParts;
mergedProjectParts.reserve(m_projectParts.size() + projectParts.size()); mergedProjectParts.reserve(m_projectParts.size() + projectParts.size());
std::set_union(std::make_move_iterator(projectParts.begin()), std::set_union(std::make_move_iterator(projectParts.begin()),
@@ -47,6 +50,10 @@ void ProjectPartQueue::addProjectParts(V2::ProjectPartContainers &&projectParts)
compare); compare);
m_projectParts = std::move(mergedProjectParts); m_projectParts = std::move(mergedProjectParts);
m_progressCounter.addTotal(int(m_projectParts.size() - oldSize));
processEntries();
} }
class CompareDifference class CompareDifference
@@ -65,6 +72,8 @@ public:
void ProjectPartQueue::removeProjectParts(const Utils::SmallStringVector &projectsPartIds) void ProjectPartQueue::removeProjectParts(const Utils::SmallStringVector &projectsPartIds)
{ {
const std::size_t oldSize = m_projectParts.size();
V2::ProjectPartContainers notToBeRemovedProjectParts; V2::ProjectPartContainers notToBeRemovedProjectParts;
notToBeRemovedProjectParts.reserve(m_projectParts.size()); notToBeRemovedProjectParts.reserve(m_projectParts.size());
std::set_difference(std::make_move_iterator(m_projectParts.begin()), std::set_difference(std::make_move_iterator(m_projectParts.begin()),
@@ -75,6 +84,8 @@ void ProjectPartQueue::removeProjectParts(const Utils::SmallStringVector &projec
CompareDifference{}); CompareDifference{});
m_projectParts = std::move(notToBeRemovedProjectParts); m_projectParts = std::move(notToBeRemovedProjectParts);
m_progressCounter.removeTotal(int(oldSize - m_projectParts.size()));
} }
void ProjectPartQueue::processEntries() void ProjectPartQueue::processEntries()

View File

@@ -35,6 +35,7 @@ class TransactionInterface;
namespace ClangBackEnd { namespace ClangBackEnd {
class PrecompiledHeaderStorageInterface; class PrecompiledHeaderStorageInterface;
class ProgressCounter;
class PchTaskSchedulerInterface; class PchTaskSchedulerInterface;
class PchCreatorInterface; class PchCreatorInterface;
@@ -45,10 +46,12 @@ public:
ProjectPartQueue(TaskSchedulerInterface<Task> &taskScheduler, ProjectPartQueue(TaskSchedulerInterface<Task> &taskScheduler,
PrecompiledHeaderStorageInterface &precompiledHeaderStorage, PrecompiledHeaderStorageInterface &precompiledHeaderStorage,
Sqlite::TransactionInterface &transactionsInterface) Sqlite::TransactionInterface &transactionsInterface,
ProgressCounter &progressCounter)
: m_taskScheduler(taskScheduler), : m_taskScheduler(taskScheduler),
m_precompiledHeaderStorage(precompiledHeaderStorage), m_precompiledHeaderStorage(precompiledHeaderStorage),
m_transactionsInterface(transactionsInterface) m_transactionsInterface(transactionsInterface),
m_progressCounter(progressCounter)
{} {}
void addProjectParts(V2::ProjectPartContainers &&projectParts); void addProjectParts(V2::ProjectPartContainers &&projectParts);
@@ -65,6 +68,7 @@ private:
TaskSchedulerInterface<Task> &m_taskScheduler; TaskSchedulerInterface<Task> &m_taskScheduler;
PrecompiledHeaderStorageInterface &m_precompiledHeaderStorage; PrecompiledHeaderStorageInterface &m_precompiledHeaderStorage;
Sqlite::TransactionInterface &m_transactionsInterface; Sqlite::TransactionInterface &m_transactionsInterface;
ProgressCounter &m_progressCounter;
}; };
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -28,6 +28,7 @@
#include "taskschedulerinterface.h" #include "taskschedulerinterface.h"
#include "symbolindexertask.h" #include "symbolindexertask.h"
#include "queueinterface.h" #include "queueinterface.h"
#include "progresscounter.h"
#include <processormanagerinterface.h> #include <processormanagerinterface.h>
#include <symbolindexertaskqueueinterface.h> #include <symbolindexertaskqueueinterface.h>
@@ -65,10 +66,12 @@ public:
TaskScheduler(ProcessorManager &symbolsCollectorManager, TaskScheduler(ProcessorManager &symbolsCollectorManager,
QueueInterface &queue, QueueInterface &queue,
ProgressCounter &progressCounter,
uint hardwareConcurrency, uint hardwareConcurrency,
std::launch launchPolicy = std::launch::async) std::launch launchPolicy = std::launch::async)
: m_processorManager(symbolsCollectorManager), : m_processorManager(symbolsCollectorManager),
m_queue(queue), m_queue(queue),
m_progressCounter(progressCounter),
m_hardwareConcurrency(hardwareConcurrency), m_hardwareConcurrency(hardwareConcurrency),
m_launchPolicy(launchPolicy) m_launchPolicy(launchPolicy)
{} {}
@@ -133,6 +136,8 @@ private:
processor.clear(); processor.clear();
}); });
m_progressCounter.addProgress(std::distance(split, m_futures.end()));
m_futures.erase(split, m_futures.end()); m_futures.erase(split, m_futures.end());
} }
@@ -181,6 +186,7 @@ private:
std::vector<Future> m_futures; std::vector<Future> m_futures;
ProcessorManager &m_processorManager; ProcessorManager &m_processorManager;
QueueInterface &m_queue; QueueInterface &m_queue;
ProgressCounter &m_progressCounter;
uint m_hardwareConcurrency; uint m_hardwareConcurrency;
std::launch m_launchPolicy; std::launch m_launchPolicy;
bool m_isDisabled = false; bool m_isDisabled = false;

View File

@@ -83,6 +83,20 @@ public:
} }
}; };
struct Data // because we have a cycle dependency
{
Data(const QString &databasePath)
: database{Utils::PathString{databasePath}, 100000ms}
{}
Sqlite::Database database;
RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
FilePathCaching filePathCache{database};
GeneratedFiles generatedFiles;
SymbolIndexing symbolIndexing{database, filePathCache, generatedFiles, [&] (int progress, int total) { clangCodeModelServer.setProgress(progress, total); }};
RefactoringServer clangCodeModelServer{symbolIndexing, filePathCache, generatedFiles};
};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
try { try {
@@ -99,14 +113,10 @@ int main(int argc, char *argv[])
const QString connectionName = arguments[0]; const QString connectionName = arguments[0];
const QString databasePath = arguments[1]; const QString databasePath = arguments[1];
Sqlite::Database database{Utils::PathString{databasePath}, 100000ms}; Data data{databasePath};
RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
FilePathCaching filePathCache{database};
GeneratedFiles generatedFiles;
SymbolIndexing symbolIndexing{database, filePathCache, generatedFiles};
RefactoringServer clangCodeModelServer{symbolIndexing, filePathCache, generatedFiles};
ConnectionServer<RefactoringServer, RefactoringClientProxy> connectionServer; ConnectionServer<RefactoringServer, RefactoringClientProxy> connectionServer;
connectionServer.setServer(&clangCodeModelServer); connectionServer.setServer(&data.clangCodeModelServer);
connectionServer.start(connectionName); connectionServer.start(connectionName);
return application.exec(); return application.exec();

View File

@@ -158,6 +158,11 @@ void RefactoringServer::setGathererProcessingSlotCount(uint count)
m_gatherer.setProcessingSlotCount(count); m_gatherer.setProcessingSlotCount(count);
} }
void RefactoringServer::setProgress(int progress, int total)
{
client()->progress({ProgressType::Indexing, progress, total});
}
void RefactoringServer::gatherSourceRangesForQueryMessages( void RefactoringServer::gatherSourceRangesForQueryMessages(
std::vector<V2::FileContainer> &&sources, std::vector<V2::FileContainer> &&sources,
std::vector<V2::FileContainer> &&unsaved, std::vector<V2::FileContainer> &&unsaved,

View File

@@ -79,6 +79,8 @@ public:
void setGathererProcessingSlotCount(uint count); void setGathererProcessingSlotCount(uint count);
void setProgress(int progress, int total);
private: private:
void gatherSourceRangesForQueryMessages(std::vector<V2::FileContainer> &&sources, void gatherSourceRangesForQueryMessages(std::vector<V2::FileContainer> &&sources,
std::vector<V2::FileContainer> &&unsaved, std::vector<V2::FileContainer> &&unsaved,

View File

@@ -29,6 +29,7 @@
#include "symbolindexertask.h" #include "symbolindexertask.h"
#include <filepathid.h> #include <filepathid.h>
#include <progresscounter.h>
#include <taskschedulerinterface.h> #include <taskschedulerinterface.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -51,8 +52,10 @@ class SymbolIndexerTaskQueue final : public SymbolIndexerTaskQueueInterface
public: public:
using Task = SymbolIndexerTask::Callable; using Task = SymbolIndexerTask::Callable;
SymbolIndexerTaskQueue(TaskSchedulerInterface<Task> &symbolIndexerTaskScheduler) SymbolIndexerTaskQueue(TaskSchedulerInterface<Task> &symbolIndexerTaskScheduler,
: m_symbolIndexerScheduler(symbolIndexerTaskScheduler) ProgressCounter &progressCounter)
: m_symbolIndexerScheduler(symbolIndexerTaskScheduler),
m_progressCounter(progressCounter)
{} {}
void addOrUpdateTasks(std::vector<SymbolIndexerTask> &&tasks) void addOrUpdateTasks(std::vector<SymbolIndexerTask> &&tasks)
@@ -63,7 +66,11 @@ public:
return std::move(first); return std::move(first);
}; };
const std::size_t oldSize = m_tasks.size();
m_tasks = Utils::setUnionMerge<std::vector<SymbolIndexerTask>>(tasks, m_tasks, merge); m_tasks = Utils::setUnionMerge<std::vector<SymbolIndexerTask>>(tasks, m_tasks, merge);
m_progressCounter.addTotal(int(m_tasks.size() - oldSize));
} }
void removeTasks(const std::vector<int> &projectPartIds) void removeTasks(const std::vector<int> &projectPartIds)
{ {
@@ -71,9 +78,13 @@ public:
return std::binary_search(projectPartIds.begin(), projectPartIds.end(), task.projectPartId); return std::binary_search(projectPartIds.begin(), projectPartIds.end(), task.projectPartId);
}; };
const std::size_t oldSize = m_tasks.size();
auto newEnd = std::remove_if(m_tasks.begin(), m_tasks.end(), shouldBeRemoved); auto newEnd = std::remove_if(m_tasks.begin(), m_tasks.end(), shouldBeRemoved);
m_tasks.erase(newEnd, m_tasks.end()); m_tasks.erase(newEnd, m_tasks.end());
m_progressCounter.removeTotal(int(oldSize -m_tasks.size()));
} }
const std::vector<SymbolIndexerTask> &tasks() const const std::vector<SymbolIndexerTask> &tasks() const
@@ -96,6 +107,7 @@ private:
std::vector<Utils::SmallString> m_projectPartIds; std::vector<Utils::SmallString> m_projectPartIds;
std::vector<SymbolIndexerTask> m_tasks; std::vector<SymbolIndexerTask> m_tasks;
TaskSchedulerInterface<Task> &m_symbolIndexerScheduler; TaskSchedulerInterface<Task> &m_symbolIndexerScheduler;
ProgressCounter &m_progressCounter;
}; };
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -49,6 +49,7 @@
namespace ClangBackEnd { namespace ClangBackEnd {
class SymbolsCollectorManager; class SymbolsCollectorManager;
class RefactoringServer;
class SymbolsCollectorManager final : public ClangBackEnd::ProcessorManager<SymbolsCollector> class SymbolsCollectorManager final : public ClangBackEnd::ProcessorManager<SymbolsCollector>
{ {
@@ -77,11 +78,13 @@ public:
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>; using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
SymbolIndexing(Sqlite::Database &database, SymbolIndexing(Sqlite::Database &database,
FilePathCachingInterface &filePathCache, FilePathCachingInterface &filePathCache,
const GeneratedFiles &generatedFiles) const GeneratedFiles &generatedFiles,
ProgressCounter::SetProgressCallback &&setProgressCallback)
: m_filePathCache(filePathCache), : m_filePathCache(filePathCache),
m_statementFactory(database), m_statementFactory(database),
m_collectorManger(generatedFiles, database), m_collectorManger(generatedFiles, database),
m_indexerScheduler(m_collectorManger, m_indexerQueue, std::thread::hardware_concurrency()) m_progressCounter(std::move(setProgressCallback)),
m_indexerScheduler(m_collectorManger, m_indexerQueue, m_progressCounter, std::thread::hardware_concurrency())
{ {
} }
@@ -114,8 +117,9 @@ private:
ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache}; ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache};
FileStatusCache m_fileStatusCache{m_filePathCache}; FileStatusCache m_fileStatusCache{m_filePathCache};
SymbolsCollectorManager m_collectorManger; SymbolsCollectorManager m_collectorManger;
ProgressCounter m_progressCounter;
SymbolIndexerTaskScheduler m_indexerScheduler; SymbolIndexerTaskScheduler m_indexerScheduler;
SymbolIndexerTaskQueue m_indexerQueue{m_indexerScheduler}; SymbolIndexerTaskQueue m_indexerQueue{m_indexerScheduler, m_progressCounter};
SymbolIndexer m_indexer{m_indexerQueue, SymbolIndexer m_indexer{m_indexerQueue,
m_symbolStorage, m_symbolStorage,
m_sourceWatcher, m_sourceWatcher,

View File

@@ -25,6 +25,7 @@
#include "googletest.h" #include "googletest.h"
#include "mockprogressmanager.h"
#include "mockrefactoringserver.h" #include "mockrefactoringserver.h"
#include "mocksearch.h" #include "mocksearch.h"
#include "mocksearchhandle.h" #include "mocksearchhandle.h"
@@ -61,7 +62,8 @@ protected:
protected: protected:
NiceMock<MockRefactoringServer> mockRefactoringServer; NiceMock<MockRefactoringServer> mockRefactoringServer;
NiceMock<MockSearch> mockSearch; NiceMock<MockSearch> mockSearch;
ClangRefactoring::RefactoringClient refactoringClient; NiceMock<MockProgressManager> mockProgressManager;
ClangRefactoring::RefactoringClient refactoringClient{mockProgressManager};
ClangRefactoring::ClangQueryProjectsFindFilter findFilter{mockRefactoringServer, mockSearch, refactoringClient}; ClangRefactoring::ClangQueryProjectsFindFilter findFilter{mockRefactoringServer, mockSearch, refactoringClient};
QString findDeclQueryText{"functionDecl()"}; QString findDeclQueryText{"functionDecl()"};
QString curentDocumentFilePath{"/path/to/file.cpp"}; QString curentDocumentFilePath{"/path/to/file.cpp"};

View File

@@ -44,10 +44,12 @@ using testing::HasSubstr;
using testing::InSequence; using testing::InSequence;
using testing::Invoke; using testing::Invoke;
using testing::IsEmpty; using testing::IsEmpty;
using testing::IsNull;
using testing::Matcher; using testing::Matcher;
using testing::Mock; using testing::Mock;
using testing::MockFunction; using testing::MockFunction;
using testing::NiceMock; using testing::NiceMock;
using testing::NotNull;
using testing::Not; using testing::Not;
using testing::Pair; using testing::Pair;
using testing::PrintToString; using testing::PrintToString;

View File

@@ -1000,6 +1000,24 @@ std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task)
return out << "(" << task.filePathId << ", " << task.projectPartId << ")"; return out << "(" << task.filePathId << ", " << task.projectPartId << ")";
} }
const char* progressTypeToString(ClangBackEnd::ProgressType type)
{
switch (type) {
case ProgressType::Invalid: return "Invalid";
case ProgressType::PrecompiledHeader: return "PrecompiledHeader";
case ProgressType::Indexing: return "Indexing";
}
return nullptr;
}
std::ostream &operator<<(std::ostream &out, const ProgressMessage &message)
{
return out << "(" << progressTypeToString(message.progressType) << ", "
<< message.progress << ", "
<< message.total << ")";
}
void PrintTo(const FilePath &filePath, ::std::ostream *os) void PrintTo(const FilePath &filePath, ::std::ostream *os)
{ {
*os << filePath; *os << filePath;

View File

@@ -169,6 +169,7 @@ class RemoveGeneratedFilesMessage;
class SuspendResumeJobsEntry; class SuspendResumeJobsEntry;
class ReferencesResult; class ReferencesResult;
class SymbolIndexerTask; class SymbolIndexerTask;
class ProgressMessage;
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
@@ -248,6 +249,7 @@ std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &m
std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry); std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry);
std::ostream &operator<<(std::ostream &os, const ReferencesResult &value); std::ostream &operator<<(std::ostream &os, const ReferencesResult &value);
std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task); std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task);
std::ostream &operator<<(std::ostream &out, const ProgressMessage &message);
void PrintTo(const FilePath &filePath, ::std::ostream *os); void PrintTo(const FilePath &filePath, ::std::ostream *os);
void PrintTo(const FilePathView &filePathView, ::std::ostream *os); void PrintTo(const FilePathView &filePathView, ::std::ostream *os);

View File

@@ -0,0 +1,42 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "googletest.h"
class MockQFutureInterface
{
public:
MOCK_METHOD1(setExpectedResultCount,
void (int));
MOCK_METHOD1(setProgressValue,
void (int));
MOCK_CONST_METHOD0(isRunning,
bool ());
MOCK_METHOD0(reportFinished,
void ());
};

View File

@@ -36,9 +36,16 @@ public:
void()); void());
MOCK_METHOD1(precompiledHeadersUpdated, MOCK_METHOD1(precompiledHeadersUpdated,
void(const ClangBackEnd::PrecompiledHeadersUpdatedMessage &message)); void(const ClangBackEnd::PrecompiledHeadersUpdatedMessage &message));
MOCK_METHOD1(progress,
void(const ClangBackEnd::ProgressMessage &message));
void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override
{ {
precompiledHeadersUpdated(message); precompiledHeadersUpdated(message);
} }
void progress(ClangBackEnd::ProgressMessage &&message) override
{
progress(message);
}
}; };

View File

@@ -42,6 +42,8 @@ public:
void (const ClangBackEnd::UpdateGeneratedFilesMessage&)); void (const ClangBackEnd::UpdateGeneratedFilesMessage&));
MOCK_METHOD1(removeGeneratedFiles, MOCK_METHOD1(removeGeneratedFiles,
void (const ClangBackEnd::RemoveGeneratedFilesMessage&)); void (const ClangBackEnd::RemoveGeneratedFilesMessage&));
MOCK_METHOD2(setProgress,
void(int, int));
void updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage &&message) override void updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage &&message) override
{ {

View File

@@ -0,0 +1,37 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "googletest.h"
#include <progressmanagerinterface.h>
class MockProgressManager : public ClangPchManager::ProgressManagerInterface
{
public:
MOCK_METHOD2(setProgress,
void (int, int));
};

View File

@@ -40,6 +40,8 @@ public:
void (const ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage&)); void (const ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage&));
MOCK_METHOD1(sourceRangesForQueryMessage, MOCK_METHOD1(sourceRangesForQueryMessage,
void (const ClangBackEnd::SourceRangesForQueryMessage&)); void (const ClangBackEnd::SourceRangesForQueryMessage&));
MOCK_METHOD1(progress,
void (const ClangBackEnd::ProgressMessage&));
void sourceLocationsForRenamingMessage(ClangBackEnd::SourceLocationsForRenamingMessage &&message) override void sourceLocationsForRenamingMessage(ClangBackEnd::SourceLocationsForRenamingMessage &&message) override
{ {
@@ -56,7 +58,13 @@ public:
sourceRangesForQueryMessage(message); sourceRangesForQueryMessage(message);
} }
void setLocalRenamingCallback(RenameCallback &&) void setLocalRenamingCallback(RenameCallback &&) override
{ {
} }
void progress(ClangBackEnd::ProgressMessage &&message) override
{
progress(message);
}
}; };

View File

@@ -59,6 +59,9 @@ public:
MOCK_METHOD0(cancel, MOCK_METHOD0(cancel,
void()); void());
MOCK_METHOD2(setProgress,
void(int, int));
void requestSourceLocationsForRenamingMessage(ClangBackEnd::RequestSourceLocationsForRenamingMessage &&message) override void requestSourceLocationsForRenamingMessage(ClangBackEnd::RequestSourceLocationsForRenamingMessage &&message) override
{ {
requestSourceLocationsForRenamingMessage(message); requestSourceLocationsForRenamingMessage(message);

View File

@@ -36,6 +36,7 @@
#include <generatedfiles.h> #include <generatedfiles.h>
#include <pchcreator.h> #include <pchcreator.h>
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmessage.h>
#include <sqlitedatabase.h> #include <sqlitedatabase.h>

View File

@@ -28,6 +28,7 @@
#include "mockpchmanagernotifier.h" #include "mockpchmanagernotifier.h"
#include "mockpchmanagerserver.h" #include "mockpchmanagerserver.h"
#include "mockprecompiledheaderstorage.h" #include "mockprecompiledheaderstorage.h"
#include "mockprogressmanager.h"
#include <pchmanagerclient.h> #include <pchmanagerclient.h>
#include <pchmanagerprojectupdater.h> #include <pchmanagerprojectupdater.h>
@@ -35,6 +36,7 @@
#include <filepathcaching.h> #include <filepathcaching.h>
#include <refactoringdatabaseinitializer.h> #include <refactoringdatabaseinitializer.h>
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmessage.h>
#include <removegeneratedfilesmessage.h> #include <removegeneratedfilesmessage.h>
#include <removeprojectpartsmessage.h> #include <removeprojectpartsmessage.h>
#include <updategeneratedfilesmessage.h> #include <updategeneratedfilesmessage.h>
@@ -51,8 +53,9 @@ using testing::Not;
class PchManagerClient : public ::testing::Test class PchManagerClient : public ::testing::Test
{ {
protected: protected:
NiceMock<MockProgressManager> mockProgressManager;
NiceMock<MockPchManagerServer> mockPchManagerServer; NiceMock<MockPchManagerServer> mockPchManagerServer;
ClangPchManager::PchManagerClient client; ClangPchManager::PchManagerClient client{mockProgressManager};
NiceMock<MockPchManagerNotifier> mockPchManagerNotifier{client}; NiceMock<MockPchManagerNotifier> mockPchManagerNotifier{client};
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database}; ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
@@ -155,4 +158,11 @@ TEST_F(PchManagerClient, ProjectPartPchForProjectPartIdIsUpdated)
42); 42);
} }
TEST_F(PchManagerClient, SetProgress)
{
EXPECT_CALL(mockProgressManager, setProgress(10, 20));
client.progress({ClangBackEnd::ProgressType::PrecompiledHeader, 10, 20});
}
} }

View File

@@ -32,6 +32,7 @@
#include <pchmanagerclientproxy.h> #include <pchmanagerclientproxy.h>
#include <pchmanagerserverproxy.h> #include <pchmanagerserverproxy.h>
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmessage.h>
#include <removegeneratedfilesmessage.h> #include <removegeneratedfilesmessage.h>
#include <removeprojectpartsmessage.h> #include <removeprojectpartsmessage.h>
#include <updategeneratedfilesmessage.h> #include <updategeneratedfilesmessage.h>
@@ -152,6 +153,17 @@ TEST_F(PchManagerClientServerInProcess, SendPrecompiledHeaderUpdatedMessage)
scheduleClientMessages(); scheduleClientMessages();
} }
TEST_F(PchManagerClientServerInProcess, SendProgressMessage)
{
ClangBackEnd::ProgressMessage message{ClangBackEnd::ProgressType::PrecompiledHeader, 10, 50};
EXPECT_CALL(mockPchManagerClient, progress(message));
clientProxy.progress(message.clone());
scheduleClientMessages();
}
PchManagerClientServerInProcess::PchManagerClientServerInProcess() PchManagerClientServerInProcess::PchManagerClientServerInProcess()
: serverProxy(&mockPchManagerClient, &buffer), : serverProxy(&mockPchManagerClient, &buffer),
clientProxy(&mockPchManagerServer, &buffer) clientProxy(&mockPchManagerServer, &buffer)

View File

@@ -34,6 +34,7 @@
#include <filepathcaching.h> #include <filepathcaching.h>
#include <pchmanagerserver.h> #include <pchmanagerserver.h>
#include <precompiledheadersupdatedmessage.h> #include <precompiledheadersupdatedmessage.h>
#include <progressmessage.h>
#include <refactoringdatabaseinitializer.h> #include <refactoringdatabaseinitializer.h>
#include <removegeneratedfilesmessage.h> #include <removegeneratedfilesmessage.h>
#include <removeprojectpartsmessage.h> #include <removeprojectpartsmessage.h>
@@ -157,4 +158,12 @@ TEST_F(PchManagerServer, UpdateProjectPartQueueByPathIds)
server.pathsWithIdsChanged({projectPartId1}); server.pathsWithIdsChanged({projectPartId1});
} }
TEST_F(PchManagerServer, SetProgress)
{
EXPECT_CALL(mockPchManagerClient, progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progress, 20),
Field(&ClangBackEnd::ProgressMessage::total, 30))));
server.setProgress(20, 30);
}
} }

View File

@@ -0,0 +1,125 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "googletest.h"
#include <progresscounter.h>
namespace {
class ProgressCounter : public testing::Test
{
protected:
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter counter{mockSetProgressCallback.AsStdFunction()};
};
TEST_F(ProgressCounter, TotalAfterInitializing)
{
ASSERT_THAT(counter.total(), 0);
}
TEST_F(ProgressCounter, ProgressAfterInitializing)
{
ASSERT_THAT(counter.progress(), 0);
}
TEST_F(ProgressCounter, AddTotal)
{
counter.addTotal(5);
counter.addProgress(3);
EXPECT_CALL(mockSetProgressCallback, Call(3, 12));
counter.addTotal(7);
}
TEST_F(ProgressCounter, RemoveTotal)
{
counter.addTotal(11);
counter.addProgress(2);
EXPECT_CALL(mockSetProgressCallback, Call(2, 4));
counter.removeTotal(7);
}
TEST_F(ProgressCounter, AddProgress)
{
counter.addTotal(11);
counter.addProgress(3);
EXPECT_CALL(mockSetProgressCallback, Call(7, 11));
counter.addProgress(4);
}
TEST_F(ProgressCounter, AddTotalAfterFinishingProgress)
{
counter.addTotal(11);
counter.addProgress(3);
counter.addProgress(8);
EXPECT_CALL(mockSetProgressCallback, Call(0, 9));
counter.addTotal(9);
}
TEST_F(ProgressCounter, AddProgressAfterFinishingProgress)
{
counter.addTotal(11);
counter.addProgress(3);
counter.addProgress(8);
counter.addTotal(9);
EXPECT_CALL(mockSetProgressCallback, Call(4, 9));
counter.addProgress(4);
}
TEST_F(ProgressCounter, AddTotalAfterFinishingProgressByRemoving)
{
counter.addTotal(11);
counter.addProgress(3);
counter.removeTotal(8);
EXPECT_CALL(mockSetProgressCallback, Call(0, 9));
counter.addTotal(9);
}
TEST_F(ProgressCounter, AddProgressAfterFinishingProgressByRemoving)
{
counter.addTotal(11);
counter.addProgress(3);
counter.removeTotal(8);
counter.addTotal(9);
EXPECT_CALL(mockSetProgressCallback, Call(4, 9));
counter.addProgress(4);
}
}

View File

@@ -31,16 +31,19 @@
#include "mocksqlitetransactionbackend.h" #include "mocksqlitetransactionbackend.h"
#include <projectpartqueue.h> #include <projectpartqueue.h>
#include <progresscounter.h>
namespace { namespace {
class ProjectPartQueue : public testing::Test class ProjectPartQueue : public testing::Test
{ {
protected: protected:
MockTaskScheduler<ClangBackEnd::ProjectPartQueue::Task> mockTaskScheduler; NiceMock<MockTaskScheduler<ClangBackEnd::ProjectPartQueue::Task>> mockTaskScheduler;
MockPrecompiledHeaderStorage mockPrecompiledHeaderStorage; MockPrecompiledHeaderStorage mockPrecompiledHeaderStorage;
MockSqliteTransactionBackend mockSqliteTransactionBackend; MockSqliteTransactionBackend mockSqliteTransactionBackend;
ClangBackEnd::ProjectPartQueue queue{mockTaskScheduler, mockPrecompiledHeaderStorage, mockSqliteTransactionBackend}; NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
ClangBackEnd::ProjectPartQueue queue{mockTaskScheduler, mockPrecompiledHeaderStorage, mockSqliteTransactionBackend, progressCounter};
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1", ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
{"--yi"}, {"--yi"},
{{"YI","1"}}, {{"YI","1"}},
@@ -76,6 +79,25 @@ TEST_F(ProjectPartQueue, AddProjectPart)
ASSERT_THAT(queue.projectParts(), ElementsAre(projectPart1, projectPart2)); ASSERT_THAT(queue.projectParts(), ElementsAre(projectPart1, projectPart2));
} }
TEST_F(ProjectPartQueue, AddProjectPartCallsProcessEntries)
{
InSequence s;
EXPECT_CALL(mockTaskScheduler, freeSlots()).WillRepeatedly(Return(2));
EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(2)));
queue.addProjectParts({projectPart1, projectPart2});
}
TEST_F(ProjectPartQueue, AddProjectPartCallsProgressCounter)
{
queue.addProjectParts({projectPart1, projectPart2});
EXPECT_CALL(mockSetProgressCallback, Call(0, 3));
queue.addProjectParts({projectPart2b, projectPart3});
}
TEST_F(ProjectPartQueue, IgnoreIdenticalProjectPart) TEST_F(ProjectPartQueue, IgnoreIdenticalProjectPart)
{ {
queue.addProjectParts({projectPart1, projectPart2}); queue.addProjectParts({projectPart1, projectPart2});
@@ -103,15 +125,13 @@ TEST_F(ProjectPartQueue, RemoveProjectPart)
ASSERT_THAT(queue.projectParts(), ElementsAre(projectPart1, projectPart3)); ASSERT_THAT(queue.projectParts(), ElementsAre(projectPart1, projectPart3));
} }
TEST_F(ProjectPartQueue, ProcessTasksCallsFreeSlotsAndAddTasksInScheduler) TEST_F(ProjectPartQueue, RemoveProjectPartCallsProgressCounter)
{ {
InSequence s; queue.addProjectParts({projectPart1, projectPart2, projectPart3});
queue.addProjectParts({projectPart1, projectPart2});
EXPECT_CALL(mockTaskScheduler, freeSlots()).WillRepeatedly(Return(2)); EXPECT_CALL(mockSetProgressCallback, Call(0, 2));
EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(2)));
queue.processEntries(); queue.removeProjectParts({projectPart2.projectPartId});
} }
TEST_F(ProjectPartQueue, CreateTasksSizeEqualsInputSize) TEST_F(ProjectPartQueue, CreateTasksSizeEqualsInputSize)

View File

@@ -29,6 +29,7 @@
#include "mockpchmanagernotifier.h" #include "mockpchmanagernotifier.h"
#include "mockpchmanagerserver.h" #include "mockpchmanagerserver.h"
#include "mockprecompiledheaderstorage.h" #include "mockprecompiledheaderstorage.h"
#include "mockprogressmanager.h"
#include <pchmanagerprojectupdater.h> #include <pchmanagerprojectupdater.h>
@@ -118,7 +119,8 @@ protected:
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database}; ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
ClangBackEnd::FilePathCaching filePathCache{database}; ClangBackEnd::FilePathCaching filePathCache{database};
ClangPchManager::PchManagerClient pchManagerClient; NiceMock<MockProgressManager> mockProgressManager;
ClangPchManager::PchManagerClient pchManagerClient{mockProgressManager};
MockPchManagerNotifier mockPchManagerNotifier{pchManagerClient}; MockPchManagerNotifier mockPchManagerNotifier{pchManagerClient};
NiceMock<MockPchManagerServer> mockPchManagerServer; NiceMock<MockPchManagerServer> mockPchManagerServer;
ClangPchManager::ProjectUpdater updater{mockPchManagerServer, filePathCache}; ClangPchManager::ProjectUpdater updater{mockPchManagerServer, filePathCache};

View File

@@ -26,6 +26,7 @@
#include "googletest.h" #include "googletest.h"
#include "mocksearchhandle.h" #include "mocksearchhandle.h"
#include "mockfilepathcaching.h" #include "mockfilepathcaching.h"
#include "mockprogressmanager.h"
#include "mocksymbolquery.h" #include "mocksymbolquery.h"
#include <clangqueryprojectsfindfilter.h> #include <clangqueryprojectsfindfilter.h>
@@ -72,7 +73,8 @@ protected:
MockFunction<void(const QString &, MockFunction<void(const QString &,
const ClangBackEnd::SourceLocationsContainer &, const ClangBackEnd::SourceLocationsContainer &,
int)> mockLocalRenaming; int)> mockLocalRenaming;
ClangRefactoring::RefactoringClient client; NiceMock<MockProgressManager> mockProgressManager;
ClangRefactoring::RefactoringClient client{mockProgressManager};
ClangBackEnd::RefactoringServerProxy serverProxy{&client, &ioDevice}; ClangBackEnd::RefactoringServerProxy serverProxy{&client, &ioDevice};
RefactoringEngine engine{serverProxy, client, mockFilePathCaching, mockSymbolQuery}; RefactoringEngine engine{serverProxy, client, mockFilePathCaching, mockSymbolQuery};
QString fileContent{QStringLiteral("int x;\nint y;")}; QString fileContent{QStringLiteral("int x;\nint y;")};
@@ -220,6 +222,13 @@ TEST_F(RefactoringClient, XXX)
client.addSearchResult(sourceRange); client.addSearchResult(sourceRange);
} }
TEST_F(RefactoringClient, SetProgress)
{
EXPECT_CALL(mockProgressManager, setProgress(10, 20));
client.progress({ClangBackEnd::ProgressType::Indexing, 10, 20});
}
void RefactoringClient::SetUp() void RefactoringClient::SetUp()
{ {
using Filter = ClangRefactoring::ClangQueryProjectsFindFilter; using Filter = ClangRefactoring::ClangQueryProjectsFindFilter;

View File

@@ -140,6 +140,17 @@ TEST_F(RefactoringClientServerInProcess, SourceRangesForQueryMessage)
scheduleClientMessages(); scheduleClientMessages();
} }
TEST_F(RefactoringClientServerInProcess, SendProgressMessage)
{
ClangBackEnd::ProgressMessage message{ClangBackEnd::ProgressType::PrecompiledHeader, 10, 50};
EXPECT_CALL(mockRefactoringClient, progress(message));
clientProxy.progress(message.clone());
scheduleClientMessages();
}
TEST_F(RefactoringClientServerInProcess, RequestSourceRangesAndDiagnosticsForQueryMessage) TEST_F(RefactoringClientServerInProcess, RequestSourceRangesAndDiagnosticsForQueryMessage)
{ {
RequestSourceRangesForQueryMessage message{"functionDecl()", RequestSourceRangesForQueryMessage message{"functionDecl()",

View File

@@ -26,6 +26,7 @@
#include "googletest.h" #include "googletest.h"
#include "mockcppmodelmanager.h" #include "mockcppmodelmanager.h"
#include "mockprogressmanager.h"
#include "mockrefactoringserver.h" #include "mockrefactoringserver.h"
#include <sqlitedatabase.h> #include <sqlitedatabase.h>
@@ -86,7 +87,8 @@ protected:
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database}; ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
ClangBackEnd::FilePathCaching filePathCache{database}; ClangBackEnd::FilePathCaching filePathCache{database};
NiceMock<MockRefactoringServer> mockRefactoringServer; NiceMock<MockRefactoringServer> mockRefactoringServer;
ClangPchManager::PchManagerClient pchManagerClient; NiceMock<MockProgressManager> mockProgressManager;
ClangPchManager::PchManagerClient pchManagerClient{mockProgressManager};
MockCppModelManager mockCppModelManager; MockCppModelManager mockCppModelManager;
ClangRefactoring::RefactoringProjectUpdater updater{mockRefactoringServer, pchManagerClient, mockCppModelManager, filePathCache}; ClangRefactoring::RefactoringProjectUpdater updater{mockRefactoringServer, pchManagerClient, mockCppModelManager, filePathCache};
Utils::SmallString projectPartId; Utils::SmallString projectPartId;

View File

@@ -338,6 +338,13 @@ TEST_F(RefactoringServer, UpdateProjectPartsCallsSymbolIndexingUpdateProjectPart
refactoringServer.updateProjectParts({Utils::clone(projectParts)}); refactoringServer.updateProjectParts({Utils::clone(projectParts)});
} }
TEST_F(RefactoringServer, SetProgress)
{
EXPECT_CALL(mockRefactoringClient, progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progress, 20),
Field(&ClangBackEnd::ProgressMessage::total, 30))));
refactoringServer.setProgress(20, 30);
}
void RefactoringServer::SetUp() void RefactoringServer::SetUp()
{ {

View File

@@ -200,8 +200,10 @@ protected:
ClangBackEnd::FileStatusCache fileStatusCache{filePathCache}; ClangBackEnd::FileStatusCache fileStatusCache{filePathCache};
ClangBackEnd::GeneratedFiles generatedFiles; ClangBackEnd::GeneratedFiles generatedFiles;
Manager collectorManger{generatedFiles}; Manager collectorManger{generatedFiles};
Scheduler indexerScheduler{collectorManger, indexerQueue, 1}; NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
SymbolIndexerTaskQueue indexerQueue{indexerScheduler}; ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
Scheduler indexerScheduler{collectorManger, indexerQueue, progressCounter, 1};
SymbolIndexerTaskQueue indexerQueue{indexerScheduler, progressCounter};
ClangBackEnd::SymbolIndexer indexer{indexerQueue, ClangBackEnd::SymbolIndexer indexer{indexerQueue,
mockStorage, mockStorage,
mockPathWatcher, mockPathWatcher,

View File

@@ -50,8 +50,10 @@ MATCHER_P2(IsTask, filePathId, projectPartId,
class SymbolIndexerTaskQueue : public testing::Test class SymbolIndexerTaskQueue : public testing::Test
{ {
protected: protected:
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
NiceMock<MockTaskScheduler<Callable>> mockTaskScheduler; NiceMock<MockTaskScheduler<Callable>> mockTaskScheduler;
ClangBackEnd::SymbolIndexerTaskQueue queue{mockTaskScheduler}; ClangBackEnd::SymbolIndexerTaskQueue queue{mockTaskScheduler, progressCounter};
}; };
TEST_F(SymbolIndexerTaskQueue, AddTasks) TEST_F(SymbolIndexerTaskQueue, AddTasks)
@@ -71,6 +73,20 @@ TEST_F(SymbolIndexerTaskQueue, AddTasks)
IsTask(FilePathId{1, 5}, 1))); IsTask(FilePathId{1, 5}, 1)));
} }
TEST_F(SymbolIndexerTaskQueue, AddTasksCallsProgressCounter)
{
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
EXPECT_CALL(mockSetProgressCallback, Call(0, 4));
queue.addOrUpdateTasks({{{1, 2}, 1, Callable{}},
{{1, 3}, 1, Callable{}}});
}
TEST_F(SymbolIndexerTaskQueue, ReplaceTask) TEST_F(SymbolIndexerTaskQueue, ReplaceTask)
{ {
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
@@ -126,6 +142,24 @@ TEST_F(SymbolIndexerTaskQueue, RemoveTaskByProjectParts)
IsTask(FilePathId{1, 5}, 1))); IsTask(FilePathId{1, 5}, 1)));
} }
TEST_F(SymbolIndexerTaskQueue, RemoveTasksCallsProgressCounter)
{
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 2, Callable{}},
{{1, 3}, 2, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 3, Callable{}},
{{1, 3}, 3, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 4, Callable{}},
{{1, 3}, 4, Callable{}}});
EXPECT_CALL(mockSetProgressCallback, Call(0, 5));
queue.removeTasks({2, 3});
}
TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksInScheduler) TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksInScheduler)
{ {
InSequence s; InSequence s;

View File

@@ -82,7 +82,8 @@ protected:
RefactoringDatabaseInitializer<Sqlite::Database> initializer{database}; RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
FilePathCaching filePathCache{database}; FilePathCaching filePathCache{database};
ClangBackEnd::GeneratedFiles generatedFiles; ClangBackEnd::GeneratedFiles generatedFiles;
ClangBackEnd::SymbolIndexing indexing{database, filePathCache, generatedFiles}; NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::SymbolIndexing indexing{database, filePathCache, generatedFiles, mockSetProgressCallback.AsStdFunction()};
StatementFactory queryFactory{database}; StatementFactory queryFactory{database};
Query query{queryFactory}; Query query{queryFactory};
PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp"; PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp";

View File

@@ -49,6 +49,7 @@ protected:
void SetUp() void SetUp()
{ {
ON_CALL(mockProcessorManager, unusedProcessor()).WillByDefault(ReturnRef(mockSymbolsCollector)); ON_CALL(mockProcessorManager, unusedProcessor()).WillByDefault(ReturnRef(mockSymbolsCollector));
progressCounter.addTotal(100);
} }
void TearDown() void TearDown()
{ {
@@ -63,11 +64,15 @@ protected:
NiceMockProcessorManager mockProcessorManager; NiceMockProcessorManager mockProcessorManager;
NiceMock<MockSymbolsCollector> mockSymbolsCollector; NiceMock<MockSymbolsCollector> mockSymbolsCollector;
NiceMock<MockSymbolIndexerTaskQueue> mockSymbolIndexerTaskQueue; NiceMock<MockSymbolIndexerTaskQueue> mockSymbolIndexerTaskQueue;
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
Scheduler scheduler{mockProcessorManager, Scheduler scheduler{mockProcessorManager,
mockSymbolIndexerTaskQueue, mockSymbolIndexerTaskQueue,
progressCounter,
4}; 4};
Scheduler deferredScheduler{mockProcessorManager, Scheduler deferredScheduler{mockProcessorManager,
mockSymbolIndexerTaskQueue, mockSymbolIndexerTaskQueue,
progressCounter,
4, 4,
std::launch::deferred}; std::launch::deferred};
}; };
@@ -140,6 +145,17 @@ TEST_F(TaskScheduler, FreeSlotsCallsCleanupMethodsAfterTheWorkIsDone)
scheduler.freeSlots(); scheduler.freeSlots();
} }
TEST_F(TaskScheduler, FreeSlotsCallsProgressMethodsAfterTheWorkIsDone)
{
scheduler.addTasks({nocall, nocall});
scheduler.syncTasks();
InSequence s;
EXPECT_CALL(mockSetProgressCallback, Call(2, 100));
scheduler.freeSlots();
}
TEST_F(TaskScheduler, AddTaskCallSymbolsCollectorManagerUnusedSymbolsCollector) TEST_F(TaskScheduler, AddTaskCallSymbolsCollectorManagerUnusedSymbolsCollector)
{ {
EXPECT_CALL(mockProcessorManager, unusedProcessor()).Times(2); EXPECT_CALL(mockProcessorManager, unusedProcessor()).Times(2);

View File

@@ -103,7 +103,8 @@ SOURCES += \
projectpartqueue-test.cpp \ projectpartqueue-test.cpp \
processormanager-test.cpp \ processormanager-test.cpp \
taskscheduler-test.cpp \ taskscheduler-test.cpp \
compileroptionsbuilder-test.cpp compileroptionsbuilder-test.cpp \
progresscounter-test.cpp
!isEmpty(LIBCLANG_LIBS) { !isEmpty(LIBCLANG_LIBS) {
SOURCES += \ SOURCES += \
@@ -245,7 +246,9 @@ HEADERS += \
mockprojectpartqueue.h \ mockprojectpartqueue.h \
mockprocessor.h \ mockprocessor.h \
mockprocessormanager.h \ mockprocessormanager.h \
mocktaskscheduler.h mocktaskscheduler.h \
mockprogressmanager.h \
mockfutureinterface.h
!isEmpty(LIBCLANG_LIBS) { !isEmpty(LIBCLANG_LIBS) {
HEADERS += \ HEADERS += \