[clang-tools-extra] r338518 - [clangd] Receive compilationDatabasePath in 'initialize' request
Simon Marchi via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 1 04:28:50 PDT 2018
Author: simark
Date: Wed Aug 1 04:28:49 2018
New Revision: 338518
URL: http://llvm.org/viewvc/llvm-project?rev=338518&view=rev
Log:
[clangd] Receive compilationDatabasePath in 'initialize' request
Summary:
That way, as soon as the "initialize" is received by the server, it can start
parsing/indexing with a valid compilation database and not have to wait for a
an initial 'didChangeConfiguration' that might or might not happen.
Then, when the user changes configuration, a didChangeConfiguration can be sent.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle at ericsson.com>
Reviewers: malaperle
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D49833
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=338518&r1=338517&r2=338518&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Aug 1 04:28:49 2018
@@ -72,6 +72,9 @@ SymbolKindBitset defaultSymbolKinds() {
} // namespace
void ClangdLSPServer::onInitialize(InitializeParams &Params) {
+ if (Params.initializationOptions)
+ applyConfiguration(*Params.initializationOptions);
+
if (Params.rootUri && *Params.rootUri)
Server.setRootPath(Params.rootUri->file());
else if (Params.rootPath && !Params.rootPath->empty())
@@ -398,11 +401,8 @@ void ClangdLSPServer::onHover(TextDocume
});
}
-// FIXME: This function needs to be properly tested.
-void ClangdLSPServer::onChangeConfiguration(
- DidChangeConfigurationParams &Params) {
- ClangdConfigurationParamsChange &Settings = Params.settings;
-
+void ClangdLSPServer::applyConfiguration(
+ const ClangdConfigurationParamsChange &Settings) {
// Compilation database change.
if (Settings.compilationDatabasePath.hasValue()) {
NonCachedCDB.setCompileCommandsDir(
@@ -413,6 +413,12 @@ void ClangdLSPServer::onChangeConfigurat
}
}
+// FIXME: This function needs to be properly tested.
+void ClangdLSPServer::onChangeConfiguration(
+ DidChangeConfigurationParams &Params) {
+ applyConfiguration(Params.settings);
+}
+
ClangdLSPServer::ClangdLSPServer(JSONOutput &Out,
const clangd::CodeCompleteOptions &CCOpts,
llvm::Optional<Path> CompileCommandsDir,
Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=338518&r1=338517&r2=338518&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Aug 1 04:28:49 2018
@@ -82,6 +82,7 @@ private:
/// may be very expensive. This method is normally called when the
/// compilation database is changed.
void reparseOpenedFiles();
+ void applyConfiguration(const ClangdConfigurationParamsChange &Settings);
JSONOutput &Out;
/// Used to indicate that the 'shutdown' request was received from the
Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=338518&r1=338517&r2=338518&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Wed Aug 1 04:28:49 2018
@@ -263,7 +263,7 @@ bool fromJSON(const json::Value &Params,
O.map("rootPath", R.rootPath);
O.map("capabilities", R.capabilities);
O.map("trace", R.trace);
- // initializationOptions, capabilities unused
+ O.map("initializationOptions", R.initializationOptions);
return true;
}
Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=338518&r1=338517&r2=338518&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Wed Aug 1 04:28:49 2018
@@ -322,6 +322,16 @@ struct ClientCapabilities {
bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
+/// Clangd extension to set clangd-specific "initializationOptions" in the
+/// "initialize" request and for the "workspace/didChangeConfiguration"
+/// notification since the data received is described as 'any' type in LSP.
+struct ClangdConfigurationParamsChange {
+ llvm::Optional<std::string> compilationDatabasePath;
+};
+bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
+
+struct ClangdInitializationOptions : public ClangdConfigurationParamsChange {};
+
struct InitializeParams {
/// The process Id of the parent process that started
/// the server. Is null if the process has not been started by another
@@ -348,6 +358,10 @@ struct InitializeParams {
/// The initial trace setting. If omitted trace is disabled ('off').
llvm::Optional<TraceLevel> trace;
+
+ // We use this predefined struct because it is easier to use
+ // than the protocol specified type of 'any'.
+ llvm::Optional<ClangdInitializationOptions> initializationOptions;
};
bool fromJSON(const llvm::json::Value &, InitializeParams &);
@@ -419,13 +433,6 @@ struct DidChangeWatchedFilesParams {
};
bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &);
-/// Clangd extension to manage a workspace/didChangeConfiguration notification
-/// since the data received is described as 'any' type in LSP.
-struct ClangdConfigurationParamsChange {
- llvm::Optional<std::string> compilationDatabasePath;
-};
-bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
-
struct DidChangeConfigurationParams {
// We use this predefined struct because it is easier to use
// than the protocol specified type of 'any'.
More information about the cfe-commits
mailing list