[clang-tools-extra] 4d700fb - [clangd] Pass raw client capabilities to modules. NFC
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 15 11:57:24 PST 2021
Author: Sam McCall
Date: 2021-02-15T20:57:14+01:00
New Revision: 4d700fb0603e6fbdd6f597443b29414f7e133912
URL: https://github.com/llvm/llvm-project/commit/4d700fb0603e6fbdd6f597443b29414f7e133912
DIFF: https://github.com/llvm/llvm-project/commit/4d700fb0603e6fbdd6f597443b29414f7e133912.diff
LOG: [clangd] Pass raw client capabilities to modules. NFC
Added:
Modified:
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/Module.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index c30890f14787..8bc49b5a5817 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 3f5d5f0b29b3..a99b78d51c44 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 <memory>
@@ -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 74e6b8c72a1c..525da502b692 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 922e701d77ef..f918183716d2 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<TraceLevel> trace;
diff --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
index 240188de0da0..d8674d601bc8 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);
More information about the cfe-commits
mailing list