diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2018-08-01 11:28:49 +0000 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-08-01 11:28:49 +0000 |
commit | 6d1efe2002cc62f71e357f562c5588f04a95c915 (patch) | |
tree | 50f4ca29e0e30763ceea576b32e5d152e7e69999 | |
parent | 187ca5ee2304b14b3bc71bca4efb334d02ef599b (diff) |
[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@ericsson.com>
Reviewers: malaperle
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D49833
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@338518 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | clangd/ClangdLSPServer.cpp | 16 | ||||
-rw-r--r-- | clangd/ClangdLSPServer.h | 1 | ||||
-rw-r--r-- | clangd/Protocol.cpp | 2 | ||||
-rw-r--r-- | clangd/Protocol.h | 21 |
4 files changed, 27 insertions, 13 deletions
diff --git a/clangd/ClangdLSPServer.cpp b/clangd/ClangdLSPServer.cpp index b8c2a79b..7374c6d3 100644 --- a/clangd/ClangdLSPServer.cpp +++ b/clangd/ClangdLSPServer.cpp @@ -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(TextDocumentPositionParams &Params) { }); } -// 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::onChangeConfiguration( } } +// 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, diff --git a/clangd/ClangdLSPServer.h b/clangd/ClangdLSPServer.h index e3b67709..644e7628 100644 --- a/clangd/ClangdLSPServer.h +++ b/clangd/ClangdLSPServer.h @@ -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 diff --git a/clangd/Protocol.cpp b/clangd/Protocol.cpp index c9ff74f9..5ecd7195 100644 --- a/clangd/Protocol.cpp +++ b/clangd/Protocol.cpp @@ -263,7 +263,7 @@ bool fromJSON(const json::Value &Params, InitializeParams &R) { 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; } diff --git a/clangd/Protocol.h b/clangd/Protocol.h index e5c29669..7f33976d 100644 --- a/clangd/Protocol.h +++ b/clangd/Protocol.h @@ -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'. |