summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKadir Cetinkaya <kadircet@google.com>2019-10-15 14:20:52 +0000
committerKadir Cetinkaya <kadircet@google.com>2019-10-15 14:20:52 +0000
commit9d66247e9b78ceb821fba12a1d2ff66839911163 (patch)
treea1d1fb78709187599c9b09c91f538bb2a5cb154a
parentab5025654448ad0c93af18727f9b0698f451bd94 (diff)
downloadbcm5719-llvm-9d66247e9b78ceb821fba12a1d2ff66839911163.tar.gz
bcm5719-llvm-9d66247e9b78ceb821fba12a1d2ff66839911163.zip
[clangd] Propagate main context into ClangdServer
Summary: Currently clangd initializes the ClangdServer lazily during onInitialize request, and it results in propagation of caller's context rather than the main context created ClangdLSPServer. This patch changes the logic to store main context that created ClangdLSPServer and pass it onto to ClangdServer and other objects like CDBs. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68978 llvm-svn: 374892
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.cpp25
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.h6
2 files changed, 22 insertions, 9 deletions
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 4dc3412538a..3f825a6febd 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "ClangdLSPServer.h"
+#include "Context.h"
#include "Diagnostics.h"
#include "DraftStore.h"
#include "FormattedString.h"
@@ -465,10 +466,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
break;
}
}
- llvm::Optional<WithContextValue> WithOffsetEncoding;
- if (NegotiatedOffsetEncoding)
- WithOffsetEncoding.emplace(kCurrentOffsetEncoding,
- *NegotiatedOffsetEncoding);
ClangdServerOpts.SemanticHighlighting =
Params.capabilities.SemanticHighlighting;
@@ -490,8 +487,18 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
}
CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
ClangdServerOpts.ResourceDir);
- Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this),
- ClangdServerOpts);
+ {
+ // Switch caller's context with LSPServer's background context. Since we
+ // rather want to propagate information from LSPServer's context into the
+ // Server, CDB, etc.
+ WithContext MainContext(BackgroundContext.clone());
+ llvm::Optional<WithContextValue> WithOffsetEncoding;
+ if (NegotiatedOffsetEncoding)
+ WithOffsetEncoding.emplace(kCurrentOffsetEncoding,
+ *NegotiatedOffsetEncoding);
+ Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this),
+ ClangdServerOpts);
+ }
applyConfiguration(Params.initializationOptions.ConfigSettings);
CCOpts.EnableSnippets = Params.capabilities.CompletionSnippets;
@@ -1184,9 +1191,9 @@ ClangdLSPServer::ClangdLSPServer(
llvm::Optional<Path> CompileCommandsDir, bool UseDirBasedCDB,
llvm::Optional<OffsetEncoding> ForcedOffsetEncoding,
const ClangdServer::Options &Opts)
- : Transp(Transp), MsgHandler(new MessageHandler(*this)),
- FSProvider(FSProvider), CCOpts(CCOpts),
- SupportedSymbolKinds(defaultSymbolKinds()),
+ : BackgroundContext(Context::current().clone()), Transp(Transp),
+ MsgHandler(new MessageHandler(*this)), FSProvider(FSProvider),
+ CCOpts(CCOpts), SupportedSymbolKinds(defaultSymbolKinds()),
SupportedCompletionItemKinds(defaultCompletionItemKinds()),
UseDirBasedCDB(UseDirBasedCDB),
CompileCommandsDir(std::move(CompileCommandsDir)), ClangdServerOpts(Opts),
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h
index 5664efd388f..850da9813fa 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -10,6 +10,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDLSPSERVER_H
#include "ClangdServer.h"
+#include "Context.h"
#include "DraftStore.h"
#include "Features.inc"
#include "FindSymbols.h"
@@ -131,6 +132,11 @@ private:
void publishDiagnostics(const URIForFile &File,
std::vector<clangd::Diagnostic> Diagnostics);
+ // Since initialization of CDBs and ClangdServer is done lazily, the following
+ // context captures the one used while creating ClangdLSPServer and passes it
+ // to above mentioned object instances to make sure they share the same state.
+ Context BackgroundContext;
+
/// Used to indicate that the 'shutdown' request was received from the
/// Language Server client.
bool ShutdownRequestReceived = false;
OpenPOWER on IntegriCloud