rwols created this revision. This changes the onShutdown handler to do essentially nothing (for now), and instead exits the runloop when we receive the exit notification from the client.
Some clients may wait on the reply from the shutdown request before sending an exit notification. If we exit the runloop already in the shutdown request, a client might block forever. This also gives us the opportunity to do any global cleanups and/or serializations of PCH preambles to disk, but I've left that out for now. See the LSP protocol documentation for details. https://reviews.llvm.org/D38939 Files: clangd/ClangdLSPServer.cpp clangd/ClangdLSPServer.h clangd/Protocol.h clangd/ProtocolHandlers.cpp clangd/ProtocolHandlers.h test/clangd/authority-less-uri.test test/clangd/completion-priorities.test test/clangd/completion-qualifiers.test test/clangd/completion-snippet.test test/clangd/completion.test test/clangd/definitions.test test/clangd/diagnostics-preamble.test test/clangd/diagnostics.test test/clangd/did-change-watch-files.test test/clangd/extra-flags.test test/clangd/fixits.test test/clangd/formatting.test test/clangd/initialize-params-invalid.test test/clangd/initialize-params.test test/clangd/input-mirror.test test/clangd/signature-help.test test/clangd/unsupported-method.test
Index: test/clangd/unsupported-method.test =================================================================== --- test/clangd/unsupported-method.test +++ test/clangd/unsupported-method.test @@ -17,3 +17,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":2,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":2,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/signature-help.test =================================================================== --- test/clangd/signature-help.test +++ test/clangd/signature-help.test @@ -40,3 +40,7 @@ Content-Length: 49 {"jsonrpc":"2.0","id":100000,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":100000,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/input-mirror.test =================================================================== --- test/clangd/input-mirror.test +++ test/clangd/input-mirror.test @@ -152,3 +152,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":3,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/initialize-params.test =================================================================== --- test/clangd/initialize-params.test +++ test/clangd/initialize-params.test @@ -20,3 +20,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":3,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/initialize-params-invalid.test =================================================================== --- test/clangd/initialize-params-invalid.test +++ test/clangd/initialize-params-invalid.test @@ -20,3 +20,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":3,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/formatting.test =================================================================== --- test/clangd/formatting.test +++ test/clangd/formatting.test @@ -65,3 +65,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":6,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":6,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/fixits.test =================================================================== --- test/clangd/fixits.test +++ test/clangd/fixits.test @@ -26,3 +26,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":3,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/extra-flags.test =================================================================== --- test/clangd/extra-flags.test +++ test/clangd/extra-flags.test @@ -18,5 +18,9 @@ Content-Length: 44 {"jsonrpc":"2.0","id":5,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":5,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/did-change-watch-files.test =================================================================== --- test/clangd/did-change-watch-files.test +++ test/clangd/did-change-watch-files.test @@ -59,3 +59,6 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/diagnostics.test =================================================================== --- test/clangd/diagnostics.test +++ test/clangd/diagnostics.test @@ -15,3 +15,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":5,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":5,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/diagnostics-preamble.test =================================================================== --- test/clangd/diagnostics-preamble.test +++ test/clangd/diagnostics-preamble.test @@ -13,3 +13,7 @@ Content-Length: 58 {"jsonrpc":"2.0","id":2,"method":"shutdown","params":null} +# CHECK: {"jsonrpc":"2.0","id":2,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/definitions.test =================================================================== --- test/clangd/definitions.test +++ test/clangd/definitions.test @@ -166,3 +166,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":3,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/completion.test =================================================================== --- test/clangd/completion.test +++ test/clangd/completion.test @@ -52,3 +52,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":4,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":4,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/completion-snippet.test =================================================================== --- test/clangd/completion-snippet.test +++ test/clangd/completion-snippet.test @@ -52,3 +52,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":4,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":4,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/completion-qualifiers.test =================================================================== --- test/clangd/completion-qualifiers.test +++ test/clangd/completion-qualifiers.test @@ -16,3 +16,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":4,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":4,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/completion-priorities.test =================================================================== --- test/clangd/completion-priorities.test +++ test/clangd/completion-priorities.test @@ -34,3 +34,7 @@ Content-Length: 58 {"jsonrpc":"2.0","id":4,"method":"shutdown","params":null} +# CHECK: {"jsonrpc":"2.0","id":4,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: test/clangd/authority-less-uri.test =================================================================== --- test/clangd/authority-less-uri.test +++ test/clangd/authority-less-uri.test @@ -30,3 +30,7 @@ Content-Length: 44 {"jsonrpc":"2.0","id":3,"method":"shutdown"} +# CHECK: {"jsonrpc":"2.0","id":3,"result":null} +Content-Length: 33 + +{"jsonrpc":"2.0":"method":"exit"} Index: clangd/ProtocolHandlers.h =================================================================== --- clangd/ProtocolHandlers.h +++ clangd/ProtocolHandlers.h @@ -34,6 +34,7 @@ virtual void onInitialize(Ctx C, InitializeParams &Params) = 0; virtual void onShutdown(Ctx C, ShutdownParams &Params) = 0; + virtual void onExit(Ctx C, ExitParams& Params) = 0; virtual void onDocumentDidOpen(Ctx C, DidOpenTextDocumentParams &Params) = 0; virtual void onDocumentDidChange(Ctx C, DidChangeTextDocumentParams &Params) = 0; Index: clangd/ProtocolHandlers.cpp =================================================================== --- clangd/ProtocolHandlers.cpp +++ clangd/ProtocolHandlers.cpp @@ -52,6 +52,7 @@ Register("initialize", &ProtocolCallbacks::onInitialize); Register("shutdown", &ProtocolCallbacks::onShutdown); + Register("exit", &ProtocolCallbacks::onExit); Register("textDocument/didOpen", &ProtocolCallbacks::onDocumentDidOpen); Register("textDocument/didClose", &ProtocolCallbacks::onDocumentDidClose); Register("textDocument/didChange", &ProtocolCallbacks::onDocumentDidChange); Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -173,6 +173,7 @@ } }; using ShutdownParams = NoParams; +using ExitParams = NoParams; struct InitializeParams { /// The process Id of the parent process that started Index: clangd/ClangdLSPServer.h =================================================================== --- clangd/ClangdLSPServer.h +++ clangd/ClangdLSPServer.h @@ -50,6 +50,7 @@ // Implement ProtocolCallbacks. void onInitialize(Ctx C, InitializeParams &Params) override; void onShutdown(Ctx C, ShutdownParams &Params) override; + void onExit(Ctx C, ExitParams& Params) override; void onDocumentDidOpen(Ctx C, DidOpenTextDocumentParams &Params) override; void onDocumentDidChange(Ctx C, DidChangeTextDocumentParams &Params) override; void onDocumentDidClose(Ctx C, DidCloseTextDocumentParams &Params) override; Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -56,9 +56,13 @@ } void ClangdLSPServer::onShutdown(Ctx C, ShutdownParams &Params) { - IsDone = true; + // Before we reply, we could serialize the preambles to disk. For now, let's + // just say we're ready to exit. + C.reply("null"); } +void ClangdLSPServer::onExit(Ctx C, ExitParams &Params) { IsDone = true; } + void ClangdLSPServer::onDocumentDidOpen(Ctx C, DidOpenTextDocumentParams &Params) { if (Params.metadata && !Params.metadata->extraFlags.empty())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits