mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Show error message when regex parsing fails.
This commit is contained in:
parent
c66c927c1f
commit
639bf8a431
@ -4,6 +4,7 @@
|
||||
#include "file_consumer.h"
|
||||
#include "match.h"
|
||||
#include "include_completion.h"
|
||||
#include "ipc_manager.h"
|
||||
#include "indexer.h"
|
||||
#include "query.h"
|
||||
#include "language_server_api.h"
|
||||
@ -107,54 +108,6 @@ struct CodeCompleteCache {
|
||||
|
||||
|
||||
|
||||
struct IpcManager {
|
||||
static IpcManager* instance_;
|
||||
static IpcManager* instance() {
|
||||
return instance_;
|
||||
}
|
||||
static void CreateInstance(MultiQueueWaiter* waiter) {
|
||||
instance_ = new IpcManager(waiter);
|
||||
}
|
||||
|
||||
std::unique_ptr<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>> threaded_queue_for_client_;
|
||||
std::unique_ptr<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>> threaded_queue_for_server_;
|
||||
|
||||
enum class Destination {
|
||||
Client, Server
|
||||
};
|
||||
|
||||
ThreadedQueue<std::unique_ptr<BaseIpcMessage>>* GetThreadedQueue(Destination destination) {
|
||||
return destination == Destination::Client ? threaded_queue_for_client_.get() : threaded_queue_for_server_.get();
|
||||
}
|
||||
|
||||
void SendOutMessageToClient(IpcId id, lsBaseOutMessage& response) {
|
||||
std::ostringstream sstream;
|
||||
response.Write(sstream);
|
||||
|
||||
auto out = MakeUnique<Ipc_Cout>();
|
||||
out->content = sstream.str();
|
||||
out->original_ipc_id = id;
|
||||
GetThreadedQueue(Destination::Client)->Enqueue(std::move(out));
|
||||
}
|
||||
|
||||
void SendMessage(Destination destination, std::unique_ptr<BaseIpcMessage> message) {
|
||||
GetThreadedQueue(destination)->Enqueue(std::move(message));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<BaseIpcMessage>> GetMessages(Destination destination) {
|
||||
return GetThreadedQueue(destination)->DequeueAll();
|
||||
}
|
||||
|
||||
private:
|
||||
IpcManager(MultiQueueWaiter* waiter) {
|
||||
threaded_queue_for_client_ = MakeUnique<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>>(waiter);
|
||||
threaded_queue_for_server_ = MakeUnique<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>>(waiter);
|
||||
}
|
||||
};
|
||||
|
||||
IpcManager* IpcManager::instance_ = nullptr;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
40
src/ipc_manager.cc
Normal file
40
src/ipc_manager.cc
Normal file
@ -0,0 +1,40 @@
|
||||
#include "ipc_manager.h"
|
||||
|
||||
IpcManager* IpcManager::instance_ = nullptr;
|
||||
|
||||
// static
|
||||
IpcManager* IpcManager::instance() {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
// static
|
||||
void IpcManager::CreateInstance(MultiQueueWaiter* waiter) {
|
||||
instance_ = new IpcManager(waiter);
|
||||
}
|
||||
|
||||
ThreadedQueue<std::unique_ptr<BaseIpcMessage>>* IpcManager::GetThreadedQueue(Destination destination) {
|
||||
return destination == Destination::Client ? threaded_queue_for_client_.get() : threaded_queue_for_server_.get();
|
||||
}
|
||||
|
||||
void IpcManager::SendOutMessageToClient(IpcId id, lsBaseOutMessage& response) {
|
||||
std::ostringstream sstream;
|
||||
response.Write(sstream);
|
||||
|
||||
auto out = MakeUnique<Ipc_Cout>();
|
||||
out->content = sstream.str();
|
||||
out->original_ipc_id = id;
|
||||
GetThreadedQueue(Destination::Client)->Enqueue(std::move(out));
|
||||
}
|
||||
|
||||
void IpcManager::SendMessage(Destination destination, std::unique_ptr<BaseIpcMessage> message) {
|
||||
GetThreadedQueue(destination)->Enqueue(std::move(message));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<BaseIpcMessage>> IpcManager::GetMessages(Destination destination) {
|
||||
return GetThreadedQueue(destination)->DequeueAll();
|
||||
}
|
||||
|
||||
IpcManager::IpcManager(MultiQueueWaiter* waiter) {
|
||||
threaded_queue_for_client_ = MakeUnique<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>>(waiter);
|
||||
threaded_queue_for_server_ = MakeUnique<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>>(waiter);
|
||||
}
|
31
src/ipc_manager.h
Normal file
31
src/ipc_manager.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "ipc.h"
|
||||
#include "language_server_api.h"
|
||||
#include "threaded_queue.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct IpcManager {
|
||||
static IpcManager* instance_;
|
||||
static IpcManager* instance();
|
||||
static void CreateInstance(MultiQueueWaiter* waiter);
|
||||
|
||||
std::unique_ptr<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>> threaded_queue_for_client_;
|
||||
std::unique_ptr<ThreadedQueue<std::unique_ptr<BaseIpcMessage>>> threaded_queue_for_server_;
|
||||
|
||||
enum class Destination {
|
||||
Client, Server
|
||||
};
|
||||
|
||||
ThreadedQueue<std::unique_ptr<BaseIpcMessage>>* GetThreadedQueue(Destination destination);
|
||||
|
||||
void SendOutMessageToClient(IpcId id, lsBaseOutMessage& response);
|
||||
|
||||
void SendMessage(Destination destination, std::unique_ptr<BaseIpcMessage> message);
|
||||
|
||||
std::vector<std::unique_ptr<BaseIpcMessage>> GetMessages(Destination destination);
|
||||
|
||||
private:
|
||||
IpcManager(MultiQueueWaiter* waiter);
|
||||
};
|
10
src/match.cc
10
src/match.cc
@ -1,5 +1,8 @@
|
||||
#include "match.h"
|
||||
|
||||
#include "ipc_manager.h"
|
||||
#include "language_server_api.h"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <iostream>
|
||||
|
||||
@ -27,8 +30,11 @@ optional<Matcher> Matcher::Create(const std::string& search) {
|
||||
return m;
|
||||
}
|
||||
catch (std::exception e) {
|
||||
// TODO/FIXME: show a warning message, we need to access IpcManager so we can print it safely to stdout.
|
||||
std::cerr << "Building matcher for " << search << " failed; " << e.what() << std::endl;
|
||||
Out_ShowLogMessage out;
|
||||
out.display_type = Out_ShowLogMessage::DisplayType::Show;
|
||||
out.params.type = lsMessageType::Error;
|
||||
out.params.message = "cquery: Parsing EMCAScript regex \"" + search + "\" failed; " + e.what();
|
||||
IpcManager::instance()->SendOutMessageToClient(IpcId::Cout, out);
|
||||
return nullopt;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user