ccls/src/ipc.h

102 lines
2.5 KiB
C
Raw Normal View History

2017-03-25 23:58:11 +00:00
#pragma once
#include "serializer.h"
2017-09-22 01:14:57 +00:00
#include "utils.h"
2017-03-25 23:58:11 +00:00
#include <string>
2018-01-19 08:47:52 +00:00
using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
2017-03-25 23:58:11 +00:00
enum class IpcId : int {
// Language server specific requests.
CancelRequest = 0,
Initialize,
Initialized,
2017-05-03 06:45:10 +00:00
Exit,
Shutdown,
CodeLensResolve,
TextDocumentDidOpen,
TextDocumentDidChange,
TextDocumentDidClose,
TextDocumentDidSave,
2017-05-10 06:13:13 +00:00
TextDocumentPublishDiagnostics,
TextDocumentRename,
TextDocumentCompletion,
TextDocumentSignatureHelp,
TextDocumentDefinition,
TextDocumentDocumentHighlight,
TextDocumentHover,
TextDocumentFormatting,
2017-12-31 22:52:06 +00:00
TextDocumentRangeFormatting,
TextDocumentOnTypeFormatting,
2017-04-10 05:34:06 +00:00
TextDocumentReferences,
2017-03-25 23:58:11 +00:00
TextDocumentDocumentSymbol,
2017-05-21 04:30:59 +00:00
TextDocumentDocumentLink,
TextDocumentCodeAction,
2017-03-25 23:58:11 +00:00
TextDocumentCodeLens,
WorkspaceDidChangeConfiguration,
WorkspaceDidChangeWatchedFiles,
2017-03-25 23:58:11 +00:00
WorkspaceSymbol,
// Custom notifications
// Comes from the client. Does various things, like update semantic
// highlighting.
CqueryTextDocumentDidView,
CqueryPublishInactiveRegions,
CqueryPublishSemanticHighlighting,
// Custom messages
2018-02-15 06:41:07 +00:00
CqueryFileInfo,
CqueryFreshenIndex,
// Messages used in tree views.
CqueryCallHierarchy,
CqueryInheritanceHierarchy,
CqueryMemberHierarchy,
// cquery cross reference extension.
2017-09-22 01:14:57 +00:00
CqueryVars, // Show all variables of a type.
CqueryCallers, // Show all callers of a function.
CqueryBase, // Show base types/method.
CqueryDerived, // Show all derived types/methods.
2018-02-11 09:13:32 +00:00
CqueryRandom, // Show random definition.
2018-02-28 07:07:53 +00:00
// Messages for testing.
CqueryIndexFile, // Index the given file contents.
CqueryWait, // Wait until all cquery threads are idle.
2017-03-25 23:58:11 +00:00
// Internal implementation detail.
Unknown,
2017-03-25 23:58:11 +00:00
};
MAKE_ENUM_HASHABLE(IpcId)
2018-01-30 00:35:01 +00:00
MAKE_REFLECT_TYPE_PROXY(IpcId)
2017-03-25 23:58:11 +00:00
const char* IpcIdToString(IpcId id);
struct BaseIpcMessage {
const IpcId method_id;
BaseIpcMessage(IpcId method_id);
2017-06-09 06:20:29 +00:00
virtual ~BaseIpcMessage();
2017-09-22 01:32:55 +00:00
2018-01-19 18:00:06 +00:00
virtual lsRequestId GetRequestId();
2017-09-22 01:32:55 +00:00
template <typename T>
T* As() {
assert(method_id == T::kIpcId);
return static_cast<T*>(this);
}
2017-03-25 23:58:11 +00:00
};
2018-01-19 08:47:52 +00:00
template <typename T>
struct RequestMessage : public BaseIpcMessage {
// number | string, actually no null
lsRequestId id;
RequestMessage() : BaseIpcMessage(T::kIpcId) {}
2018-01-19 18:00:06 +00:00
2018-01-30 00:27:43 +00:00
lsRequestId GetRequestId() override { return id; }
2018-01-19 08:47:52 +00:00
};
// NotificationMessage does not have |id|.
template <typename T>
struct NotificationMessage : public BaseIpcMessage {
NotificationMessage() : BaseIpcMessage(T::kIpcId) {}
};