jkorous created this revision.
jkorous added reviewers: arphaman, sammccall, ilya-biryukov, simark.
Herald added subscribers: cfe-commits, dexonsmith, MaskRay, ioeric, mgorny.
Based on our internal discussions we decided to change our direction with XPC
support for clangd. We did some extra measurements and found out that JSON
serialized over XPC is good enough for our use-case. We also took into
consideration that we'd have to deal with support for multiple workspaces in
near future.
Probably the simplest solution is to keep XPC completely out of clangd binary
and use one clangd instance per workspace. This design means it's the least
intrusive change, it's rather simple (compared to adding support for multiple
workspaces to clangd itself) and robust (compared to threads-based
implementation). Long-term it's hopefully also going to be less
maintenance-demanding since it's dependent only on LSP and not it's
implementation.
The patch is nearly finished - I just wanted to get some feedback on the design
early on (before finishing doxygen annotations, documentation, etc.).
Our approach to testing for the future is to reuse existing clangd lit tests
and just send messages through our XPC code. For the time being there's just a
single minimal testcase.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D50452
Files:
CMakeLists.txt
Features.inc.in
clangd/CMakeLists.txt
clangd/xpc/initialize.test
lit.cfg
lit.site.cfg.in
xpc/CMakeLists.txt
xpc/README.txt
xpc/cmake/Info.plist.in
xpc/cmake/XPCServiceInfo.plist.in
xpc/cmake/modules/CreateClangdXPCFramework.cmake
xpc/framework/CMakeLists.txt
xpc/framework/ClangdXPC.cpp
xpc/test-client/CMakeLists.txt
xpc/test-client/ClangdXPCTestClient.cpp
xpc/tool/CMakeLists.txt
xpc/tool/ClangdSubprocess.cpp
xpc/tool/ClangdSubprocess.h
xpc/tool/ClangdWorkspaceInstances.cpp
xpc/tool/ClangdWorkspaceInstances.h
xpc/tool/ClangdXpcAdapter.cpp
xpc/tool/log.h
Index: clangd/CMakeLists.txt
===
--- clangd/CMakeLists.txt
+++ clangd/CMakeLists.txt
@@ -51,4 +51,4 @@
clangToolingInclusions
LLVMSupport
LLVMTestingSupport
- )
+ )
\ No newline at end of file
Index: lit.site.cfg.in
===
--- lit.site.cfg.in
+++ lit.site.cfg.in
@@ -11,6 +11,7 @@
config.python_executable = "@PYTHON_EXECUTABLE@"
config.target_triple = "@TARGET_TRIPLE@"
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
+config.clangd_xpc_support = @CLANGD_BUILD_XPC@
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Index: lit.cfg
===
--- lit.cfg
+++ lit.cfg
@@ -117,6 +117,10 @@
if platform.system() not in ['Windows']:
config.available_features.add('ansi-escape-sequences')
+# XPC support for Clangd.
+if config.clangd_xpc_support:
+config.available_features.add('clangd-xpc-support')
+
if config.clang_staticanalyzer:
config.available_features.add('static-analyzer')
check_clang_tidy = os.path.join(
Index: clangd/xpc/initialize.test
===
--- /dev/null
+++ clangd/xpc/initialize.test
@@ -0,0 +1,10 @@
+# RUN: clangd-xpc-test-client < %s | FileCheck %s
+# REQUIRES: clangd-xpc-support
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootUri":"test:///workspace","capabilities":{},"trace":"off"}}
+# CHECK-DAG: {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"codeActionProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",">",":"]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix"]},"hoverProvider":true,"renameProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":2,"workspaceSymbolProvider":true}}}
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK-DAG: {"id":3,"jsonrpc":"2.0","result":null}
+
+{"jsonrpc":"2.0","method":"exit"}
Index: xpc/tool/log.h
===
--- /dev/null
+++ xpc/tool/log.h
@@ -0,0 +1,49 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XPC_LOG_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XPC_LOG_H
+
+#include
+#include
+
+#include
+
+class Logger {
+private:
+ enum class log_type { log, info, debug };
+ log_type type;
+ std::string buffer_data;
+ std::stringstream buffer;
+ Logger(log_type type) : type(type), buffer_data(), buffer(buffer_data) {}
+
+public:
+ template Logger <<(const T ) {
+buffer << in;
+return *this;
+ }
+ friend Logger