[clangd] Avoid possible crash: apply configuration after binding methods

The configuration may kick off indexing, which may involve sending LSP
messages.
The crash is fiddly to reproduce in a hermetic test (we need background
indexing on without disk storage, and to handle server->client messages
in LSPClient...)

Fixes https://github.com/clangd/clangd/issues/926
This commit is contained in:
Sam McCall 2021-11-20 01:10:30 +01:00
parent de11de308b
commit f764a1a5bd
1 changed files with 4 additions and 1 deletions

View File

@ -493,7 +493,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
Server.emplace(*CDB, TFS, Opts,
static_cast<ClangdServer::Callbacks *>(this));
}
applyConfiguration(Params.initializationOptions.ConfigSettings);
Opts.CodeComplete.EnableSnippets = Params.capabilities.CompletionSnippets;
Opts.CodeComplete.IncludeFixIts = Params.capabilities.CompletionFixes;
@ -627,6 +626,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
if (Opts.Encoding)
Result["offsetEncoding"] = *Opts.Encoding;
Reply(std::move(Result));
// Apply settings after we're fully initialized.
// This can start background indexing and in turn trigger LSP notifications.
applyConfiguration(Params.initializationOptions.ConfigSettings);
}
void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}