[PATCH] D68978: [clangd] Propagate main context into ClangdServer
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 15 07:20:46 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9d66247e9b78: [clangd] Propagate main context into ClangdServer (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68978/new/
https://reviews.llvm.org/D68978
Files:
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===================================================================
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ 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 @@
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;
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ 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 @@
break;
}
}
- llvm::Optional<WithContextValue> WithOffsetEncoding;
- if (NegotiatedOffsetEncoding)
- WithOffsetEncoding.emplace(kCurrentOffsetEncoding,
- *NegotiatedOffsetEncoding);
ClangdServerOpts.SemanticHighlighting =
Params.capabilities.SemanticHighlighting;
@@ -490,8 +487,18 @@
}
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 @@
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),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68978.225031.patch
Type: text/x-patch
Size: 3509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191015/b49592db/attachment-0001.bin>
More information about the cfe-commits
mailing list