diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index c30890f147873..8bc49b5a5817c 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -582,7 +582,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params, bindMethods(Binder); if (Opts.Modules) for (auto &Mod : *Opts.Modules) - Mod.initializeLSP(Binder, Params.capabilities, ServerCaps); + Mod.initializeLSP(Binder, Params.rawCapabilities, ServerCaps); } // Per LSP, renameProvider can be either boolean or RenameOptions. diff --git a/clang-tools-extra/clangd/Module.h b/clang-tools-extra/clangd/Module.h index 3f5d5f0b29b3e..a99b78d51c444 100644 --- a/clang-tools-extra/clangd/Module.h +++ b/clang-tools-extra/clangd/Module.h @@ -2,7 +2,6 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H #include "LSPBinder.h" -#include "Protocol.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/JSON.h" #include @@ -37,9 +36,8 @@ class Module { /// /// This is only called if the module is running in ClangdLSPServer! /// Modules with a public interface should satisfy it without LSP bindings. - // FIXME: ClientCaps should be a raw json::Object here. virtual void initializeLSP(LSPBinder &Bind, - const ClientCapabilities &ClientCaps, + const llvm::json::Object &ClientCaps, llvm::json::Object &ServerCaps) {} }; diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index 74e6b8c72a1c1..525da502b692b 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -430,6 +430,8 @@ bool fromJSON(const llvm::json::Value &Params, InitializeParams &R, O.map("rootUri", R.rootUri); O.map("rootPath", R.rootPath); O.map("capabilities", R.capabilities); + if (auto *RawCaps = Params.getAsObject()->getObject("capabilities")) + R.rawCapabilities = *RawCaps; O.map("trace", R.trace); O.map("initializationOptions", R.initializationOptions); return true; diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index 922e701d77ef5..f918183716d28 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -540,6 +540,8 @@ struct InitializeParams { /// The capabilities provided by the client (editor or tool) ClientCapabilities capabilities; + /// The same data as capabilities, but not parsed (to expose to modules). + llvm::json::Object rawCapabilities; /// The initial trace setting. If omitted trace is disabled ('off'). llvm::Optional trace; diff --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp index 240188de0da0f..d8674d601bc88 100644 --- a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp @@ -223,7 +223,7 @@ TEST_F(LSPTest, CDBConfigIntegration) { TEST_F(LSPTest, ModulesTest) { class MathModule : public Module { - void initializeLSP(LSPBinder &Bind, const ClientCapabilities &ClientCaps, + void initializeLSP(LSPBinder &Bind, const llvm::json::Object &ClientCaps, llvm::json::Object &ServerCaps) override { Bind.notification("add", this, &MathModule::add); Bind.method("get", this, &MathModule::get);