diff --git a/CMakeLists.txt b/CMakeLists.txt index 0244908c..beca46ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ add_executable(cquery "") ### Compile options # CMake default compile flags: -# MSVC + Clang(Windows): +# MSVC + Clang(Windows): # debug: /MDd /Zi /Ob0 /Od /RTC1 # release: /MD /O2 /Ob2 /DNDEBUG # GCC + Clang(Linux): @@ -32,15 +32,15 @@ set_property(TARGET cquery PROPERTY CXX_EXTENSIONS OFF) if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) # Common MSVC/Clang(Windows) options - target_compile_options(cquery PRIVATE - /nologo - /EHsc + target_compile_options(cquery PRIVATE + /nologo + /EHsc /W3 # roughly -Wall /wd4996 # disable loguru unsafe warnings - /wd4722 # ignores warning C4722 + /wd4722 # ignores warning C4722 # (destructor never returns) in loguru - /wd4267 # ignores warning C4267 - # (conversion from 'size_t' to 'type'), + /wd4267 # ignores warning C4267 + # (conversion from 'size_t' to 'type'), # roughly -Wno-sign-compare /wd4800 $<$:/FS> @@ -48,8 +48,8 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) else() # Common GCC/Clang(Linux) options target_compile_options(cquery PRIVATE - -Wall - -Wno-sign-compare + -Wall + -Wno-sign-compare ) if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) @@ -57,14 +57,14 @@ else() endif() if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) - target_compile_options(cquery PRIVATE + target_compile_options(cquery PRIVATE $<$:-fno-limit-debug-info>) endif() if(CLANG_CXX) # -Wno-comment: include/clang/Format/Format.h error: multi-line comment # -fno-rtti: # Without -fno-rtti, some Clang C++ functions may report - # `undefined references to typeinfo` + # `undefined references to typeinfo` target_compile_options(cquery PRIVATE -Wno-comment -fno-rtti) endif() @@ -148,21 +148,21 @@ install(TARGETS cquery RUNTIME DESTINATION bin) if(NOT SYSTEM_CLANG AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows) if(${CMAKE_SYSTEM_NAME} MATCHES Linux|FreeBSD) - set_property(TARGET cquery APPEND PROPERTY + set_property(TARGET cquery APPEND PROPERTY INSTALL_RPATH $ORIGIN/../lib) elseif(${CMAKE_SYSTEM_NAME} STREQUAL Darwin) - set_property(TARGET cquery APPEND PROPERTY - INSTALL_RPATH @loader_path/../lib) + set_property(TARGET cquery APPEND PROPERTY + INSTALL_RPATH @loader_path/../lib) endif() - file(GLOB LIBCLANG_PLUS_SYMLINKS + file(GLOB LIBCLANG_PLUS_SYMLINKS ${DOWNLOADED_CLANG_DIR}/lib/libclang.[so,dylib]*) install(FILES ${LIBCLANG_PLUS_SYMLINKS} DESTINATION lib) endif() ### Sources -target_sources(cquery PRIVATE third_party/siphash.cc) +target_sources(cquery PRIVATE third_party/siphash.cc) target_sources(cquery PRIVATE src/cache_manager.cc @@ -183,7 +183,7 @@ target_sources(cquery PRIVATE src/import_manager.cc src/import_pipeline.cc src/include_complete.cc - src/ipc.cc + src/method.cc src/lex_utils.cc src/lsp_diagnostic.cc src/lsp.cc diff --git a/src/command_line.cc b/src/command_line.cc index 6229ad33..14bd2c35 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -137,7 +137,7 @@ bool QueryDbMainLoop(Config* config, CodeCompleteCache* non_global_code_complete_cache, CodeCompleteCache* signature_cache) { auto* queue = QueueManager::instance(); - std::vector> messages = + std::vector> messages = queue->for_querydb.DequeueAll(); bool did_work = messages.size(); for (auto& message : messages) { @@ -281,7 +281,7 @@ void LaunchStdinLoop(Config* config, WorkThread::StartThread("stdin", [request_times]() { auto* queue = QueueManager::instance(); while (true) { - std::unique_ptr message; + std::unique_ptr message; optional err = MessageRegistry::instance()->ReadMessageFromStdin(&message); diff --git a/src/lsp.cc b/src/lsp.cc index 38fdee6f..07daebe6 100644 --- a/src/lsp.cc +++ b/src/lsp.cc @@ -123,7 +123,7 @@ optional ReadCharFromStdinBlocking() { } optional MessageRegistry::ReadMessageFromStdin( - std::unique_ptr* message) { + std::unique_ptr* message) { optional content = ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking); if (!content) { @@ -141,7 +141,7 @@ optional MessageRegistry::ReadMessageFromStdin( optional MessageRegistry::Parse( Reader& visitor, - std::unique_ptr* message) { + std::unique_ptr* message) { if (!visitor.HasMember("jsonrpc") || std::string(visitor["jsonrpc"]->GetString()) != "2.0") { LOG_S(FATAL) << "Bad or missing jsonrpc version"; diff --git a/src/lsp.h b/src/lsp.h index e0d70cb5..88e06358 100644 --- a/src/lsp.h +++ b/src/lsp.h @@ -1,7 +1,7 @@ #pragma once #include "config.h" -#include "ipc.h" +#include "method.h" #include "serializer.h" #include "utils.h" @@ -32,13 +32,13 @@ struct MessageRegistry { static MessageRegistry* instance(); using Allocator = - std::function*)>; + std::function*)>; std::unordered_map allocators; optional ReadMessageFromStdin( - std::unique_ptr* message); + std::unique_ptr* message); optional Parse(Reader& visitor, - std::unique_ptr* message); + std::unique_ptr* message); }; template @@ -47,7 +47,7 @@ struct MessageRegistryRegister { T dummy; std::string method_name = dummy.GetMethodType(); MessageRegistry::instance()->allocators[method_name] = - [](Reader& visitor, std::unique_ptr* message) { + [](Reader& visitor, std::unique_ptr* message) { *message = std::make_unique(); // Reflect may throw and *message will be partially deserialized. Reflect(visitor, static_cast(**message)); diff --git a/src/message_handler.h b/src/message_handler.h index a68990f4..e838bfb1 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -1,7 +1,7 @@ #pragma once -#include "ipc.h" #include "lsp.h" +#include "method.h" #include "query.h" #include @@ -87,7 +87,7 @@ struct MessageHandler { CodeCompleteCache* signature_cache = nullptr; virtual MethodType GetMethodType() const = 0; - virtual void Run(std::unique_ptr message) = 0; + virtual void Run(std::unique_ptr message) = 0; static std::vector* message_handlers; @@ -100,7 +100,7 @@ struct BaseMessageHandler : MessageHandler { virtual void Run(TMessage* message) = 0; // MessageHandler: - void Run(std::unique_ptr message) override { + void Run(std::unique_ptr message) override { Run(static_cast(message.get())); } }; diff --git a/src/messages/cquery_base.cc b/src/messages/cquery_base.cc index 05963f85..c3831433 100644 --- a/src/messages/cquery_base.cc +++ b/src/messages/cquery_base.cc @@ -6,7 +6,7 @@ namespace { MethodType kMethodType = "$cquery/base"; -struct In_CqueryBase : public RequestMessage { +struct In_CqueryBase : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; diff --git a/src/messages/cquery_call_hierarchy.cc b/src/messages/cquery_call_hierarchy.cc index 7143680b..9f6e576f 100644 --- a/src/messages/cquery_call_hierarchy.cc +++ b/src/messages/cquery_call_hierarchy.cc @@ -20,7 +20,7 @@ bool operator&(CallType lhs, CallType rhs) { return uint8_t(lhs) & uint8_t(rhs); } -struct In_CqueryCallHierarchy : public RequestMessage { +struct In_CqueryCallHierarchy : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { diff --git a/src/messages/cquery_callers.cc b/src/messages/cquery_callers.cc index 4214253f..701aefbe 100644 --- a/src/messages/cquery_callers.cc +++ b/src/messages/cquery_callers.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "$cquery/callers"; -struct In_CqueryCallers : public RequestMessage { +struct In_CqueryCallers : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; diff --git a/src/messages/cquery_derived.cc b/src/messages/cquery_derived.cc index e43da912..9700e88f 100644 --- a/src/messages/cquery_derived.cc +++ b/src/messages/cquery_derived.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "$cquery/derived"; -struct In_CqueryDerived : public RequestMessage { +struct In_CqueryDerived : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; diff --git a/src/messages/cquery_did_view.cc b/src/messages/cquery_did_view.cc index d01f6d95..73da37da 100644 --- a/src/messages/cquery_did_view.cc +++ b/src/messages/cquery_did_view.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "$cquery/textDocumentDidView"; -struct In_CqueryTextDocumentDidView : public NotificationMessage { +struct In_CqueryTextDocumentDidView : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { lsDocumentUri textDocumentUri; diff --git a/src/messages/cquery_file_info.cc b/src/messages/cquery_file_info.cc index 22db960c..a72612d6 100644 --- a/src/messages/cquery_file_info.cc +++ b/src/messages/cquery_file_info.cc @@ -10,7 +10,7 @@ struct lsDocumentSymbolParams { }; MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument); -struct In_CqueryFileInfo : public RequestMessage { +struct In_CqueryFileInfo : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsDocumentSymbolParams params; }; diff --git a/src/messages/cquery_freshen_index.cc b/src/messages/cquery_freshen_index.cc index 0b7cc073..e52b5236 100644 --- a/src/messages/cquery_freshen_index.cc +++ b/src/messages/cquery_freshen_index.cc @@ -15,7 +15,7 @@ namespace { MethodType kMethodType = "$cquery/freshenIndex"; -struct In_CqueryFreshenIndex : public NotificationMessage { +struct In_CqueryFreshenIndex : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { bool dependencies = true; diff --git a/src/messages/cquery_index_file.cc b/src/messages/cquery_index_file.cc index 0d188ea6..9e106558 100644 --- a/src/messages/cquery_index_file.cc +++ b/src/messages/cquery_index_file.cc @@ -8,7 +8,7 @@ namespace { MethodType kMethodType = "$cquery/indexFile"; -struct In_CqueryIndexFile : public NotificationMessage { +struct In_CqueryIndexFile : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { std::string path; diff --git a/src/messages/cquery_inheritance_hierarchy.cc b/src/messages/cquery_inheritance_hierarchy.cc index 3c024619..17a0b1ba 100644 --- a/src/messages/cquery_inheritance_hierarchy.cc +++ b/src/messages/cquery_inheritance_hierarchy.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "$cquery/inheritanceHierarchy"; -struct In_CqueryInheritanceHierarchy : public RequestMessage { +struct In_CqueryInheritanceHierarchy : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { // If id+kind are specified, expand a node; otherwise textDocument+position diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/cquery_member_hierarchy.cc index b4f03763..e98e53d5 100644 --- a/src/messages/cquery_member_hierarchy.cc +++ b/src/messages/cquery_member_hierarchy.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "$cquery/memberHierarchy"; -struct In_CqueryMemberHierarchy : public RequestMessage { +struct In_CqueryMemberHierarchy : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { diff --git a/src/messages/cquery_random.cc b/src/messages/cquery_random.cc index bf7c4668..7bbf0761 100644 --- a/src/messages/cquery_random.cc +++ b/src/messages/cquery_random.cc @@ -9,7 +9,7 @@ namespace { MethodType kMethodType = "$cquery/random"; -struct In_CqueryRandom : public RequestMessage { +struct In_CqueryRandom : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } }; MAKE_REFLECT_STRUCT(In_CqueryRandom, id); diff --git a/src/messages/cquery_vars.cc b/src/messages/cquery_vars.cc index 812ec6f0..8ac9816f 100644 --- a/src/messages/cquery_vars.cc +++ b/src/messages/cquery_vars.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "$cquery/vars"; -struct In_CqueryVars : public RequestMessage { +struct In_CqueryVars : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; diff --git a/src/messages/cquery_wait.cc b/src/messages/cquery_wait.cc index c9109729..3a05df75 100644 --- a/src/messages/cquery_wait.cc +++ b/src/messages/cquery_wait.cc @@ -8,7 +8,7 @@ namespace { MethodType kMethodType = "$cquery/wait"; -struct In_CqueryWait : public NotificationMessage { +struct In_CqueryWait : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } }; MAKE_REFLECT_EMPTY_STRUCT(In_CqueryWait); @@ -17,7 +17,7 @@ REGISTER_IN_MESSAGE(In_CqueryWait); struct Handler_CqueryWait : MessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(std::unique_ptr request) override { + void Run(std::unique_ptr request) override { // TODO: use status message system here, then run querydb as normal? Maybe // this cannot be a normal message, ie, it needs to be re-entrant. diff --git a/src/messages/exit.cc b/src/messages/exit.cc index d90d80ed..2722dca5 100644 --- a/src/messages/exit.cc +++ b/src/messages/exit.cc @@ -3,7 +3,7 @@ #include namespace { -struct In_Exit : public NotificationMessage { +struct In_Exit : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType_Exit; } }; MAKE_REFLECT_EMPTY_STRUCT(In_Exit); @@ -12,7 +12,7 @@ REGISTER_IN_MESSAGE(In_Exit); struct Handler_Exit : MessageHandler { MethodType GetMethodType() const override { return kMethodType_Exit; } - void Run(std::unique_ptr request) override { + void Run(std::unique_ptr request) override { LOG_S(INFO) << "Exiting; got exit message"; exit(0); } diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index ffbc6115..2edd6ff0 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -462,7 +462,7 @@ struct lsInitializeError { }; MAKE_REFLECT_STRUCT(lsInitializeError, retry); -struct In_InitializeRequest : public RequestMessage { +struct In_InitializeRequest : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsInitializeParams params; diff --git a/src/messages/shutdown.cc b/src/messages/shutdown.cc index f93f4320..5967e239 100644 --- a/src/messages/shutdown.cc +++ b/src/messages/shutdown.cc @@ -4,7 +4,7 @@ namespace { MethodType kMethodType = "shutdown"; -struct In_Shutdown : public RequestMessage { +struct In_Shutdown : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } }; MAKE_REFLECT_STRUCT(In_Shutdown, id); diff --git a/src/messages/text_document_code_action.cc b/src/messages/text_document_code_action.cc index 487fbca3..e3913a2f 100644 --- a/src/messages/text_document_code_action.cc +++ b/src/messages/text_document_code_action.cc @@ -257,7 +257,7 @@ optional BuildAutoImplementForFunction(QueryDatabase* db, return nullopt; } -struct In_TextDocumentCodeAction : public RequestMessage { +struct In_TextDocumentCodeAction : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } // Contains additional diagnostic information about the context in which diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index f735f1bb..903abf11 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -13,7 +13,7 @@ struct lsDocumentCodeLensParams { MAKE_REFLECT_STRUCT(lsDocumentCodeLensParams, textDocument); using TCodeLens = lsCodeLens; -struct In_TextDocumentCodeLens : public RequestMessage { +struct In_TextDocumentCodeLens : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsDocumentCodeLensParams params; }; diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index 43dc6c8c..d6db3107 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -48,7 +48,7 @@ struct lsCompletionParams : lsTextDocumentPositionParams { }; MAKE_REFLECT_STRUCT(lsCompletionParams, textDocument, position, context); -struct In_TextDocumentComplete : public RequestMessage { +struct In_TextDocumentComplete : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsCompletionParams params; }; @@ -219,7 +219,7 @@ void FilterAndSortCompletionResponse( struct Handler_TextDocumentCompletion : MessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(std::unique_ptr message) override { + void Run(std::unique_ptr message) override { auto request = std::shared_ptr( static_cast(message.release())); diff --git a/src/messages/text_document_definition.cc b/src/messages/text_document_definition.cc index 95410f0e..d7fc869a 100644 --- a/src/messages/text_document_definition.cc +++ b/src/messages/text_document_definition.cc @@ -10,7 +10,7 @@ namespace { MethodType kMethodType = "textDocument/definition"; -struct In_TextDocumentDefinition : public RequestMessage { +struct In_TextDocumentDefinition : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; diff --git a/src/messages/text_document_did_change.cc b/src/messages/text_document_did_change.cc index fb16e3c3..cf887adb 100644 --- a/src/messages/text_document_did_change.cc +++ b/src/messages/text_document_did_change.cc @@ -10,7 +10,7 @@ namespace { MethodType kMethodType = "textDocument/didChange"; -struct In_TextDocumentDidChange : public NotificationMessage { +struct In_TextDocumentDidChange : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentDidChangeParams params; }; diff --git a/src/messages/text_document_did_close.cc b/src/messages/text_document_did_close.cc index e76ee52f..6cf1d3fb 100644 --- a/src/messages/text_document_did_close.cc +++ b/src/messages/text_document_did_close.cc @@ -6,7 +6,7 @@ namespace { MethodType kMethodType = "textDocument/didClose"; -struct In_TextDocumentDidClose : public NotificationMessage { +struct In_TextDocumentDidClose : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { lsTextDocumentIdentifier textDocument; diff --git a/src/messages/text_document_did_open.cc b/src/messages/text_document_did_open.cc index 2b2562d8..770c9bcb 100644 --- a/src/messages/text_document_did_open.cc +++ b/src/messages/text_document_did_open.cc @@ -13,7 +13,7 @@ namespace { MethodType kMethodType = "textDocument/didOpen"; // Open, view, change, close file -struct In_TextDocumentDidOpen : public NotificationMessage { +struct In_TextDocumentDidOpen : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { diff --git a/src/messages/text_document_did_save.cc b/src/messages/text_document_did_save.cc index 7eec5dd0..f187f018 100644 --- a/src/messages/text_document_did_save.cc +++ b/src/messages/text_document_did_save.cc @@ -9,7 +9,7 @@ namespace { MethodType kMethodType = "textDocument/didSave"; -struct In_TextDocumentDidSave : public NotificationMessage { +struct In_TextDocumentDidSave : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { diff --git a/src/messages/text_document_document_highlight.cc b/src/messages/text_document_document_highlight.cc index b01bc7a6..42e74cdb 100644 --- a/src/messages/text_document_document_highlight.cc +++ b/src/messages/text_document_document_highlight.cc @@ -6,7 +6,7 @@ namespace { MethodType kMethodType = "textDocument/documentHighlight"; -struct In_TextDocumentDocumentHighlight : public RequestMessage { +struct In_TextDocumentDocumentHighlight : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; diff --git a/src/messages/text_document_document_link.cc b/src/messages/text_document_document_link.cc index fc6994fa..9a05365a 100644 --- a/src/messages/text_document_document_link.cc +++ b/src/messages/text_document_document_link.cc @@ -8,7 +8,7 @@ namespace { MethodType kMethodType = "textDocument/documentLink"; -struct In_TextDocumentDocumentLink : public RequestMessage { +struct In_TextDocumentDocumentLink : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { // The document to provide document links for. diff --git a/src/messages/text_document_document_symbol.cc b/src/messages/text_document_document_symbol.cc index 4a48a2d3..2ec07533 100644 --- a/src/messages/text_document_document_symbol.cc +++ b/src/messages/text_document_document_symbol.cc @@ -10,7 +10,7 @@ struct lsDocumentSymbolParams { }; MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument); -struct In_TextDocumentDocumentSymbol : public RequestMessage { +struct In_TextDocumentDocumentSymbol : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsDocumentSymbolParams params; }; diff --git a/src/messages/text_document_formatting.cc b/src/messages/text_document_formatting.cc index 55c8f487..793c86d6 100644 --- a/src/messages/text_document_formatting.cc +++ b/src/messages/text_document_formatting.cc @@ -8,7 +8,7 @@ namespace { MethodType kMethodType = "textDocument/formatting"; -struct In_TextDocumentFormatting : public RequestMessage { +struct In_TextDocumentFormatting : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { lsTextDocumentIdentifier textDocument; diff --git a/src/messages/text_document_hover.cc b/src/messages/text_document_hover.cc index 2dbf26a1..6a852d8f 100644 --- a/src/messages/text_document_hover.cc +++ b/src/messages/text_document_hover.cc @@ -42,7 +42,7 @@ std::pair GetCommentsAndHover( return {"", ""}; } -struct In_TextDocumentHover : public RequestMessage { +struct In_TextDocumentHover : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; diff --git a/src/messages/text_document_range_formatting.cc b/src/messages/text_document_range_formatting.cc index 29605e50..175dbb2a 100644 --- a/src/messages/text_document_range_formatting.cc +++ b/src/messages/text_document_range_formatting.cc @@ -19,7 +19,7 @@ MAKE_REFLECT_STRUCT(lsTextDocumentRangeFormattingParams, range, options); -struct In_TextDocumentRangeFormatting : public RequestMessage { +struct In_TextDocumentRangeFormatting : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentRangeFormattingParams params; }; diff --git a/src/messages/text_document_references.cc b/src/messages/text_document_references.cc index bd6896d7..19684cdb 100644 --- a/src/messages/text_document_references.cc +++ b/src/messages/text_document_references.cc @@ -7,7 +7,7 @@ namespace { MethodType kMethodType = "textDocument/references"; -struct In_TextDocumentReferences : public RequestMessage { +struct In_TextDocumentReferences : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct lsReferenceContext { // Include the declaration of the current symbol. diff --git a/src/messages/text_document_rename.cc b/src/messages/text_document_rename.cc index b44048ad..b8dcc9d9 100644 --- a/src/messages/text_document_rename.cc +++ b/src/messages/text_document_rename.cc @@ -48,7 +48,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, return edit; } -struct In_TextDocumentRename : public RequestMessage { +struct In_TextDocumentRename : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { // The document to format. diff --git a/src/messages/text_document_signature_help.cc b/src/messages/text_document_signature_help.cc index c4e74029..8f23e5be 100644 --- a/src/messages/text_document_signature_help.cc +++ b/src/messages/text_document_signature_help.cc @@ -9,7 +9,7 @@ namespace { MethodType kMethodType = "textDocument/signatureHelp"; -struct In_TextDocumentSignatureHelp : public RequestMessage { +struct In_TextDocumentSignatureHelp : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; @@ -86,7 +86,7 @@ MAKE_REFLECT_STRUCT(Out_TextDocumentSignatureHelp, jsonrpc, id, result); struct Handler_TextDocumentSignatureHelp : MessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(std::unique_ptr message) override { + void Run(std::unique_ptr message) override { auto request = static_cast(message.get()); lsTextDocumentPositionParams& params = request->params; WorkingFile* file = @@ -103,7 +103,7 @@ struct Handler_TextDocumentSignatureHelp : MessageHandler { return; ClangCompleteManager::OnComplete callback = std::bind( - [this](BaseIpcMessage* message, std::string search, int active_param, + [this](InMessage* message, std::string search, int active_param, const std::vector& results, bool is_cached_result) { auto msg = static_cast(message); diff --git a/src/messages/text_document_type_definition.cc b/src/messages/text_document_type_definition.cc index 9797af8a..4226c558 100644 --- a/src/messages/text_document_type_definition.cc +++ b/src/messages/text_document_type_definition.cc @@ -5,7 +5,7 @@ namespace { MethodType kMethodType = "textDocument/typeDefinition"; -struct In_TextDocumentTypeDefinition : public RequestMessage { +struct In_TextDocumentTypeDefinition : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; diff --git a/src/messages/workspace_did_change_configuration.cc b/src/messages/workspace_did_change_configuration.cc index 8714217a..c2ad85cb 100644 --- a/src/messages/workspace_did_change_configuration.cc +++ b/src/messages/workspace_did_change_configuration.cc @@ -16,7 +16,7 @@ struct lsDidChangeConfigurationParams { }; MAKE_REFLECT_STRUCT(lsDidChangeConfigurationParams, placeholder); -struct In_WorkspaceDidChangeConfiguration : public NotificationMessage { +struct In_WorkspaceDidChangeConfiguration : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } lsDidChangeConfigurationParams params; }; diff --git a/src/messages/workspace_did_change_watched_files.cc b/src/messages/workspace_did_change_watched_files.cc index 88471b94..d44081e7 100644 --- a/src/messages/workspace_did_change_watched_files.cc +++ b/src/messages/workspace_did_change_watched_files.cc @@ -28,7 +28,7 @@ struct lsDidChangeWatchedFilesParams { }; MAKE_REFLECT_STRUCT(lsDidChangeWatchedFilesParams, changes); -struct In_WorkspaceDidChangeWatchedFiles : public NotificationMessage { +struct In_WorkspaceDidChangeWatchedFiles : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } lsDidChangeWatchedFilesParams params; }; diff --git a/src/messages/workspace_execute_command.cc b/src/messages/workspace_execute_command.cc index f1600d89..e8f66f25 100644 --- a/src/messages/workspace_execute_command.cc +++ b/src/messages/workspace_execute_command.cc @@ -6,7 +6,7 @@ namespace { MethodType kMethodType = "workspace/executeCommand"; -struct In_WorkspaceExecuteCommand : public RequestMessage { +struct In_WorkspaceExecuteCommand : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsCommand params; }; diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 68d0abca..b069ec84 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -43,7 +43,7 @@ bool InsertSymbolIntoResult(QueryDatabase* db, return true; } -struct In_WorkspaceSymbol : public RequestMessage { +struct In_WorkspaceSymbol : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { std::string query; diff --git a/src/ipc.cc b/src/method.cc similarity index 68% rename from src/ipc.cc rename to src/method.cc index 81139319..43e136fb 100644 --- a/src/ipc.cc +++ b/src/method.cc @@ -1,4 +1,4 @@ -#include "ipc.h" +#include "method.h" const char* kMethodType_Unknown = "$unknown"; const char* kMethodType_Exit = "exit"; @@ -6,8 +6,12 @@ const char* kMethodType_TextDocumentPublishDiagnostics = "textDocument/publishDi const char* kMethodType_CqueryPublishInactiveRegions = "$cquery/publishInactiveRegions"; const char* kMethodType_CqueryPublishSemanticHighlighting = "$cquery/publishSemanticHighlighting"; -BaseIpcMessage::~BaseIpcMessage() = default; +InMessage::~InMessage() = default; -lsRequestId BaseIpcMessage::GetRequestId() { - return std::monostate(); +lsRequestId RequestInMessage::GetRequestId() const { + return id; } + +lsRequestId NotificationInMessage::GetRequestId() const { + return std::monostate(); +} \ No newline at end of file diff --git a/src/ipc.h b/src/method.h similarity index 63% rename from src/ipc.h rename to src/method.h index 0718d7fe..2a329866 100644 --- a/src/ipc.h +++ b/src/method.h @@ -5,28 +5,29 @@ #include -using lsRequestId = std::variant; - using MethodType = std::string; - extern const char* kMethodType_Unknown; extern const char* kMethodType_Exit; extern const char* kMethodType_TextDocumentPublishDiagnostics; extern const char* kMethodType_CqueryPublishInactiveRegions; extern const char* kMethodType_CqueryPublishSemanticHighlighting; -struct BaseIpcMessage { - virtual ~BaseIpcMessage(); +using lsRequestId = std::variant; + +struct InMessage { + virtual ~InMessage(); virtual MethodType GetMethodType() const = 0; - virtual lsRequestId GetRequestId(); + virtual lsRequestId GetRequestId() const = 0; }; -struct RequestMessage : public BaseIpcMessage { +struct RequestInMessage : public InMessage { // number or string, actually no null lsRequestId id; - lsRequestId GetRequestId() override { return id; } + lsRequestId GetRequestId() const override; }; -// NotificationMessage does not have |id|. -struct NotificationMessage : public BaseIpcMessage {}; +// NotificationInMessage does not have |id|. +struct NotificationInMessage : public InMessage { + lsRequestId GetRequestId() const override; +}; diff --git a/src/project.h b/src/project.h index c3acdf22..2e2a9253 100644 --- a/src/project.h +++ b/src/project.h @@ -1,6 +1,7 @@ #pragma once #include "config.h" +#include "method.h" #include #include @@ -11,8 +12,6 @@ #include #include -// FIXME ipc.h -using lsRequestId = std::variant; class QueueManager; struct WorkingFiles; diff --git a/src/queue_manager.h b/src/queue_manager.h index 34cc3b00..86478a36 100644 --- a/src/queue_manager.h +++ b/src/queue_manager.h @@ -1,6 +1,6 @@ #pragma once -#include "ipc.h" +#include "method.h" #include "performance.h" #include "query.h" #include "threaded_queue.h" @@ -94,7 +94,7 @@ class QueueManager { ThreadedQueue for_stdout; // Runs on querydb thread. - ThreadedQueue> for_querydb; + ThreadedQueue> for_querydb; ThreadedQueue do_id_map; // Runs on indexer threads.