From c4a9590398a278bc13c0487d2a9babc369d21633 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 25 Mar 2017 13:40:04 -0700 Subject: [PATCH] fixes --- src/command_line.cc | 6 ++--- src/indexer.h | 29 +++------------------ src/language_server_api.h | 53 +++++++++++++++------------------------ 3 files changed, 26 insertions(+), 62 deletions(-) diff --git a/src/command_line.cc b/src/command_line.cc index 0d390440..871a5fe0 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -165,7 +165,7 @@ struct IpcMessage_Cout : public BaseIpcMessage { std::string content; IpcMessage_Cout() {} - IpcMessage_Cout(OutMessage& message) { + IpcMessage_Cout(lsOutMessage& message) { std::ostringstream out; message.Send(out); content = out.str(); @@ -176,7 +176,7 @@ void Reflect(TVisitor& visitor, IpcMessage_Cout& value) { Reflect(visitor, value.content); } -void SendOutMessageToClient(IpcMessageQueue* queue, OutMessage& response) { +void SendOutMessageToClient(IpcMessageQueue* queue, lsOutMessage& response) { IpcMessage_Cout out(response); queue->SendMessage(&queue->for_client, IpcMessage_Cout::kMethod, out); } @@ -186,7 +186,7 @@ void SendOutMessageToClient(IpcMessageQueue* queue, OutMessage& response) { template void RegisterId(IpcMessageQueue* t) { t->RegisterId(T::kMethod, - [](Writer& visitor, lsBaseMessage& message) { + [](Writer& visitor, InMessage& message) { T& m = static_cast(message); Reflect(visitor, m); }, [](Reader& visitor) { diff --git a/src/indexer.h b/src/indexer.h index 4e7686fb..e6c86b65 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -338,14 +338,7 @@ struct IndexedTypeDef { } }; -namespace std { -template <> -struct hash { - size_t operator()(const IndexedTypeDef& k) const { - return hash()(k.def.usr); - } -}; -} +MAKE_HASHABLE(IndexedTypeDef, t.def.usr); template -struct hash { - size_t operator()(const IndexedFuncDef& k) const { - return hash()(k.def.usr); - } -}; -} +MAKE_HASHABLE(IndexedFuncDef, t.def.usr); template -struct hash { - size_t operator()(const IndexedVarDef& k) const { - return hash()(k.def.usr); - } -}; -} +MAKE_HASHABLE(IndexedVarDef, t.def.usr); struct IdCache { std::unordered_map file_path_to_file_id; diff --git a/src/language_server_api.h b/src/language_server_api.h index f5ec50a8..55ba5fac 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -187,9 +187,7 @@ MessageRegistry* MessageRegistry::instance() { return instance_; } -struct lsBaseMessage {}; - -struct InMessage : public lsBaseMessage { +struct InMessage { const lsMethodId method_id; InMessage(lsMethodId method_id) : method_id(method_id) {} }; @@ -202,7 +200,7 @@ struct InNotificationMessage : public InMessage { InNotificationMessage(lsMethodId method) : InMessage(method) {} }; -struct OutMessage : public lsBaseMessage { +struct lsOutMessage { // Write out the body of the message. The writer expects object key/value // pairs. virtual void WriteMessageBody(Writer& writer) = 0; @@ -224,7 +222,7 @@ struct OutMessage : public lsBaseMessage { } }; -struct OutRequestMessage : public OutMessage { +struct OutRequestMessage : public lsOutMessage { RequestId id; virtual std::string Method() = 0; @@ -281,7 +279,7 @@ struct lsResponseError { } }; -struct OutResponseMessage : public OutMessage { +struct OutResponseMessage : public lsOutMessage { RequestId id; virtual optional Error() { @@ -307,7 +305,7 @@ struct OutResponseMessage : public OutMessage { } }; -struct OutNotificationMessage : public OutMessage { +struct OutNotificationMessage : public lsOutMessage { virtual std::string Method() = 0; virtual void SerializeParams(Writer& writer) = 0; @@ -1004,15 +1002,15 @@ void Reflect(Reader& reader, lsInitializeParams::lsTrace& value) { void Reflect(Writer& writer, lsInitializeParams::lsTrace& value) { switch (value) { - case lsInitializeParams::lsTrace::Off: - writer.String("off"); - break; - case lsInitializeParams::lsTrace::Messages: - writer.String("messages"); - break; - case lsInitializeParams::lsTrace::Verbose: - writer.String("verbose"); - break; + case lsInitializeParams::lsTrace::Off: + writer.String("off"); + break; + case lsInitializeParams::lsTrace::Messages: + writer.String("messages"); + break; + case lsInitializeParams::lsTrace::Verbose: + writer.String("verbose"); + break; } } @@ -1028,20 +1026,6 @@ void Reflect(TVisitor& visitor, lsInitializeParams& value) { } -#if false -/** - * Known error codes for an `InitializeError`; - */ -export namespace lsInitializeError { - /** - * If the protocol version provided by the client can't be handled by the server. - * @deprecated This initialize error got replaced by client capabilities. There is - * no version handshake in version 3.0x - */ - export const unknownProtocolVersion : number = 1; -} -#endif - struct lsInitializeError { // Indicates whether the client should retry to send the // initilize request after showing the message provided @@ -1071,8 +1055,11 @@ enum class lsTextDocumentSyncKind { Incremental = 2 }; -void Reflect(Writer& writer, lsTextDocumentSyncKind& value) { - writer.Int(static_cast(value)); +template +void Reflect(TVisitor& visitor, lsTextDocumentSyncKind& value) { + int value0 = static_cast(value); + Reflect(visitor, value0); + value = static_cast(value0); } // Completion options. @@ -1302,7 +1289,7 @@ struct Out_InitializeResponse : public OutResponseMessage { struct In_InitializedNotification : public InNotificationMessage { const static lsMethodId kMethod = lsMethodId::Initialized; - + RequestId id; In_InitializedNotification() : InNotificationMessage(kMethod) {}