Skip to content

Commit 8801678

Browse files
author
Simon Marchi
committedAug 1, 2018
[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 llvm-svn: 338518
1 parent 1ffd6b2 commit 8801678

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed
 

‎clang-tools-extra/clangd/ClangdLSPServer.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ SymbolKindBitset defaultSymbolKinds() {
7272
} // namespace
7373

7474
void ClangdLSPServer::onInitialize(InitializeParams &Params) {
75+
if (Params.initializationOptions)
76+
applyConfiguration(*Params.initializationOptions);
77+
7578
if (Params.rootUri && *Params.rootUri)
7679
Server.setRootPath(Params.rootUri->file());
7780
else if (Params.rootPath && !Params.rootPath->empty())
@@ -398,11 +401,8 @@ void ClangdLSPServer::onHover(TextDocumentPositionParams &Params) {
398401
});
399402
}
400403

401-
// FIXME: This function needs to be properly tested.
402-
void ClangdLSPServer::onChangeConfiguration(
403-
DidChangeConfigurationParams &Params) {
404-
ClangdConfigurationParamsChange &Settings = Params.settings;
405-
404+
void ClangdLSPServer::applyConfiguration(
405+
const ClangdConfigurationParamsChange &Settings) {
406406
// Compilation database change.
407407
if (Settings.compilationDatabasePath.hasValue()) {
408408
NonCachedCDB.setCompileCommandsDir(
@@ -413,6 +413,12 @@ void ClangdLSPServer::onChangeConfiguration(
413413
}
414414
}
415415

416+
// FIXME: This function needs to be properly tested.
417+
void ClangdLSPServer::onChangeConfiguration(
418+
DidChangeConfigurationParams &Params) {
419+
applyConfiguration(Params.settings);
420+
}
421+
416422
ClangdLSPServer::ClangdLSPServer(JSONOutput &Out,
417423
const clangd::CodeCompleteOptions &CCOpts,
418424
llvm::Optional<Path> CompileCommandsDir,

‎clang-tools-extra/clangd/ClangdLSPServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class ClangdLSPServer : private DiagnosticsConsumer, private ProtocolCallbacks {
8282
/// may be very expensive. This method is normally called when the
8383
/// compilation database is changed.
8484
void reparseOpenedFiles();
85+
void applyConfiguration(const ClangdConfigurationParamsChange &Settings);
8586

8687
JSONOutput &Out;
8788
/// Used to indicate that the 'shutdown' request was received from the

‎clang-tools-extra/clangd/Protocol.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ bool fromJSON(const json::Value &Params, InitializeParams &R) {
263263
O.map("rootPath", R.rootPath);
264264
O.map("capabilities", R.capabilities);
265265
O.map("trace", R.trace);
266-
// initializationOptions, capabilities unused
266+
O.map("initializationOptions", R.initializationOptions);
267267
return true;
268268
}
269269

‎clang-tools-extra/clangd/Protocol.h

+14-7
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ struct ClientCapabilities {
322322

323323
bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
324324

325+
/// Clangd extension to set clangd-specific "initializationOptions" in the
326+
/// "initialize" request and for the "workspace/didChangeConfiguration"
327+
/// notification since the data received is described as 'any' type in LSP.
328+
struct ClangdConfigurationParamsChange {
329+
llvm::Optional<std::string> compilationDatabasePath;
330+
};
331+
bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
332+
333+
struct ClangdInitializationOptions : public ClangdConfigurationParamsChange {};
334+
325335
struct InitializeParams {
326336
/// The process Id of the parent process that started
327337
/// the server. Is null if the process has not been started by another
@@ -348,6 +358,10 @@ struct InitializeParams {
348358

349359
/// The initial trace setting. If omitted trace is disabled ('off').
350360
llvm::Optional<TraceLevel> trace;
361+
362+
// We use this predefined struct because it is easier to use
363+
// than the protocol specified type of 'any'.
364+
llvm::Optional<ClangdInitializationOptions> initializationOptions;
351365
};
352366
bool fromJSON(const llvm::json::Value &, InitializeParams &);
353367

@@ -419,13 +433,6 @@ struct DidChangeWatchedFilesParams {
419433
};
420434
bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &);
421435

422-
/// Clangd extension to manage a workspace/didChangeConfiguration notification
423-
/// since the data received is described as 'any' type in LSP.
424-
struct ClangdConfigurationParamsChange {
425-
llvm::Optional<std::string> compilationDatabasePath;
426-
};
427-
bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
428-
429436
struct DidChangeConfigurationParams {
430437
// We use this predefined struct because it is easier to use
431438
// than the protocol specified type of 'any'.

0 commit comments

Comments
 (0)
Please sign in to comment.