summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.cpp38
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.h2
-rw-r--r--clang-tools-extra/clangd/Protocol.cpp22
-rw-r--r--clang-tools-extra/clangd/Protocol.h32
4 files changed, 45 insertions, 49 deletions
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 6769d38ea95..f08d7b0ac75 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -303,15 +303,14 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
if (Server)
return Reply(make_error<LSPError>("server already initialized",
ErrorCode::InvalidRequest));
- if (Params.initializationOptions)
- CompileCommandsDir = Params.initializationOptions->compilationDatabasePath;
+ if (const auto &Dir = Params.initializationOptions.compilationDatabasePath)
+ CompileCommandsDir = Dir;
CDB.emplace(UseInMemoryCDB
? CompilationDB::makeInMemory()
: CompilationDB::makeDirectoryBased(CompileCommandsDir));
Server.emplace(CDB->getCDB(), FSProvider,
static_cast<DiagnosticsConsumer &>(*this), ClangdServerOpts);
- if (Params.initializationOptions)
- applyConfiguration(Params.initializationOptions->ParamsChange);
+ applyConfiguration(Params.initializationOptions.ConfigSettings);
CCOpts.EnableSnippets = Params.capabilities.CompletionSnippets;
DiagOpts.EmbedFixesInDiagnostics = Params.capabilities.DiagnosticFixes;
@@ -654,25 +653,22 @@ void ClangdLSPServer::onHover(const TextDocumentPositionParams &Params,
}
void ClangdLSPServer::applyConfiguration(
- const ClangdConfigurationParamsChange &Params) {
+ const ConfigurationSettings &Settings) {
// Per-file update to the compilation database.
- if (Params.compilationDatabaseChanges) {
- const auto &CompileCommandUpdates = *Params.compilationDatabaseChanges;
- bool ShouldReparseOpenFiles = false;
- for (auto &Entry : CompileCommandUpdates) {
- /// The opened files need to be reparsed only when some existing
- /// entries are changed.
- PathRef File = Entry.first;
- if (!CDB->setCompilationCommandForFile(
- File, tooling::CompileCommand(
- std::move(Entry.second.workingDirectory), File,
- std::move(Entry.second.compilationCommand),
- /*Output=*/"")))
- ShouldReparseOpenFiles = true;
- }
- if (ShouldReparseOpenFiles)
- reparseOpenedFiles();
+ bool ShouldReparseOpenFiles = false;
+ for (auto &Entry : Settings.compilationDatabaseChanges) {
+ /// The opened files need to be reparsed only when some existing
+ /// entries are changed.
+ PathRef File = Entry.first;
+ if (!CDB->setCompilationCommandForFile(
+ File, tooling::CompileCommand(
+ std::move(Entry.second.workingDirectory), File,
+ std::move(Entry.second.compilationCommand),
+ /*Output=*/"")))
+ ShouldReparseOpenFiles = true;
}
+ if (ShouldReparseOpenFiles)
+ reparseOpenedFiles();
}
// FIXME: This function needs to be properly tested.
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h
index c207ebcc3a2..089c218dc2a 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -93,7 +93,7 @@ private:
/// may be very expensive. This method is normally called when the
/// compilation database is changed.
void reparseOpenedFiles();
- void applyConfiguration(const ClangdConfigurationParamsChange &Settings);
+ void applyConfiguration(const ConfigurationSettings &Settings);
/// Used to indicate that the 'shutdown' request was received from the
/// Language Server client.
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index d4892682db9..1bb5961a5b4 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -663,20 +663,22 @@ bool fromJSON(const json::Value &Params, ClangdCompileCommand &CDbUpdate) {
O.map("compilationCommand", CDbUpdate.compilationCommand);
}
-bool fromJSON(const json::Value &Params,
- ClangdConfigurationParamsChange &CCPC) {
+bool fromJSON(const json::Value &Params, ConfigurationSettings &S) {
json::ObjectMapper O(Params);
- return O &&
- O.map("compilationDatabaseChanges", CCPC.compilationDatabaseChanges);
+ if (!O)
+ return true; // 'any' type in LSP.
+ O.map("compilationDatabaseChanges", S.compilationDatabaseChanges);
+ return true;
}
-bool fromJSON(const json::Value &Params, ClangdInitializationOptions &Opts) {
- if (!fromJSON(Params, Opts.ParamsChange)) {
- return false;
- }
-
+bool fromJSON(const json::Value &Params, InitializationOptions &Opts) {
json::ObjectMapper O(Params);
- return O && O.map("compilationDatabasePath", Opts.compilationDatabasePath);
+ if (!O)
+ return true; // 'any' type in LSP.
+
+ fromJSON(Params, Opts.ConfigSettings);
+ O.map("compilationDatabasePath", Opts.compilationDatabasePath);
+ return true;
}
bool fromJSON(const json::Value &Params, ReferenceParams &R) {
diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h
index 079873e61cf..30352494c71 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -355,25 +355,26 @@ struct ClangdCompileCommand {
};
bool fromJSON(const llvm::json::Value &, ClangdCompileCommand &);
-/// 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 {
- // The changes that happened to the compilation database.
+/// Clangd extension: parameters configurable at any time, via the
+/// `workspace/didChangeConfiguration` notification.
+/// LSP defines this type as `any`.
+struct ConfigurationSettings {
+ // Changes to the in-memory compilation database.
// The key of the map is a file name.
- llvm::Optional<std::map<std::string, ClangdCompileCommand>>
- compilationDatabaseChanges;
+ std::map<std::string, ClangdCompileCommand> compilationDatabaseChanges;
};
-bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
+bool fromJSON(const llvm::json::Value &, ConfigurationSettings &);
-struct ClangdInitializationOptions {
+/// Clangd extension: parameters configurable at `initialize` time.
+/// LSP defines this type as `any`.
+struct InitializationOptions {
// What we can change throught the didChangeConfiguration request, we can
// also set through the initialize request (initializationOptions field).
- ClangdConfigurationParamsChange ParamsChange;
+ ConfigurationSettings ConfigSettings;
llvm::Optional<std::string> compilationDatabasePath;
};
-bool fromJSON(const llvm::json::Value &, ClangdInitializationOptions &);
+bool fromJSON(const llvm::json::Value &, InitializationOptions &);
struct InitializeParams {
/// The process Id of the parent process that started
@@ -402,9 +403,8 @@ 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;
+ /// User-provided initialization options.
+ InitializationOptions initializationOptions;
};
bool fromJSON(const llvm::json::Value &, InitializeParams &);
@@ -477,9 +477,7 @@ struct DidChangeWatchedFilesParams {
bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &);
struct DidChangeConfigurationParams {
- // We use this predefined struct because it is easier to use
- // than the protocol specified type of 'any'.
- ClangdConfigurationParamsChange settings;
+ ConfigurationSettings settings;
};
bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &);
OpenPOWER on IntegriCloud