Show progress indicator in status area

This commit is contained in:
Jacob Dufault 2017-10-25 00:12:11 -07:00
parent 39de197e8a
commit 235987bb58
3 changed files with 41 additions and 2 deletions

View File

@ -728,6 +728,18 @@ struct IndexManager {
}
};
// Sends indexing progress to client.
void EmitProgress(QueueManager* queue) {
Out_Progress out;
out.params.indexRequestCount = queue->index_request.Size();
out.params.doIdMapCount = queue->do_id_map.Size();
out.params.loadPreviousIndexCount = queue->load_previous_index.Size();
out.params.onIdMappedCount = queue->on_id_mapped.Size();
out.params.onIndexedCount = queue->on_indexed.Size();
IpcManager::instance()->SendOutMessageToClient(IpcId::Cout, out);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
@ -1131,6 +1143,8 @@ WorkThread::Result IndexMain(Config* config,
WorkingFiles* working_files,
MultiQueueWaiter* waiter,
QueueManager* queue) {
EmitProgress(queue);
// TODO: dispose of index after it is not used for a while.
clang::Index index(1, 0);
@ -1174,6 +1188,8 @@ bool QueryDb_ImportMain(Config* config,
ImportManager* import_manager,
QueueManager* queue,
WorkingFiles* working_files) {
EmitProgress(queue);
bool did_work = false;
while (true) {

View File

@ -1654,6 +1654,25 @@ void Reflect(TVisitor& visitor, Out_ShowLogMessage& value) {
REFLECT_MEMBER_END();
}
struct Out_Progress : public lsOutMessage<Out_Progress> {
struct Params {
int indexRequestCount = 0;
int doIdMapCount = 0;
int loadPreviousIndexCount = 0;
int onIdMappedCount = 0;
int onIndexedCount = 0;
};
std::string method = "$cquery/progress";
Params params;
};
MAKE_REFLECT_STRUCT(Out_Progress::Params,
indexRequestCount,
doIdMapCount,
loadPreviousIndexCount,
onIdMappedCount,
onIndexedCount);
MAKE_REFLECT_STRUCT(Out_Progress, jsonrpc, method, params);
struct Out_CquerySetInactiveRegion
: public lsOutMessage<Out_CquerySetInactiveRegion> {
struct Params {

View File

@ -3,14 +3,12 @@
#include <optional.h>
#include "work_thread.h"
#include <algorithm>
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <queue>
using std::experimental::nullopt;
using std::experimental::optional;
@ -66,6 +64,12 @@ struct ThreadedQueue : public BaseThreadQueue {
explicit ThreadedQueue(MultiQueueWaiter* waiter) : waiter_(waiter) {}
// Returns the number of elements in the queue. This acquires a lock.
size_t Size() const {
std::lock_guard<std::mutex> lock(mutex_);
return priority_.size() + queue_.size();
}
// Add an element to the front of the queue.
void PriorityEnqueue(T&& t) {
std::lock_guard<std::mutex> lock(mutex_);