[clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction.
authorSam McCall <sam.mccall@gmail.com>
Tue, 16 Oct 2018 16:48:06 +0000 (16:48 +0000)
committerSam McCall <sam.mccall@gmail.com>
Tue, 16 Oct 2018 16:48:06 +0000 (16:48 +0000)
commit818ec5e965d49dd385d16f8a23432375a672363d
treef1f6a115279d3c2f374cdc85e61b449b92cc6c6d
parent20841d41e762293b319b1a69b9f3cf72052fd9ee
[clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction.

Summary:
This paves the way for alternative transports (mac XPC, maybe messagepack?),
and also generally improves layering: testing ClangdLSPServer becomes less of
a pipe dream, we split up the JSONOutput monolith, etc.

This isn't a final state, much of what remains in JSONRPCDispatcher can go away,
handlers can call reply() on the transport directly, JSONOutput can be renamed
to StreamLogger and removed, etc. But this patch is sprawling already.

The main observable change (see tests) is that hitting EOF on input is now an
error: the client should send the 'exit' notification.
This is defensible: the protocol doesn't spell this case out. Reproducing the
current behavior for all combinations of shutdown/exit/EOF clutters interfaces.
We can iterate on this if desired.

Reviewers: jkorous, ioeric, hokein

Subscribers: mgorny, ilya-biryukov, MaskRay, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D53286

llvm-svn: 344620
23 files changed:
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/clangd/JSONRPCDispatcher.h
clang-tools-extra/clangd/JSONTransport.cpp [new file with mode: 0644]
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/ProtocolHandlers.cpp
clang-tools-extra/clangd/Transport.h [new file with mode: 0644]
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/test/clangd/compile-commands-path-in-initialize.test
clang-tools-extra/test/clangd/completion-snippets.test
clang-tools-extra/test/clangd/completion.test
clang-tools-extra/test/clangd/crash-non-added-files.test
clang-tools-extra/test/clangd/execute-command.test
clang-tools-extra/test/clangd/input-mirror.test
clang-tools-extra/test/clangd/signature-help.test
clang-tools-extra/test/clangd/textdocument-didchange-fail.test
clang-tools-extra/test/clangd/trace.test
clang-tools-extra/test/clangd/xrefs.test
clang-tools-extra/unittests/clangd/CMakeLists.txt
clang-tools-extra/unittests/clangd/JSONTransportTests.cpp [new file with mode: 0644]