Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.h =================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.h +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h @@ -82,6 +82,7 @@ /// 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 Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp @@ -72,6 +72,9 @@ } // 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 @@ }); } -// 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 @@ } } +// 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 CompileCommandsDir, Index: clang-tools-extra/trunk/clangd/Protocol.h =================================================================== --- clang-tools-extra/trunk/clangd/Protocol.h +++ clang-tools-extra/trunk/clangd/Protocol.h @@ -322,6 +322,16 @@ 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 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 @@ /// The initial trace setting. If omitted trace is disabled ('off'). llvm::Optional trace; + + // We use this predefined struct because it is easier to use + // than the protocol specified type of 'any'. + llvm::Optional initializationOptions; }; bool fromJSON(const llvm::json::Value &, InitializeParams &); @@ -419,13 +433,6 @@ }; 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 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'. Index: clang-tools-extra/trunk/clangd/Protocol.cpp =================================================================== --- clang-tools-extra/trunk/clangd/Protocol.cpp +++ clang-tools-extra/trunk/clangd/Protocol.cpp @@ -263,7 +263,7 @@ 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; }