return Opts;
}
-ClangdServer::ClangdServer(GlobalCompilationDatabase &CDB,
- FileSystemProvider &FSProvider,
+ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
+ const FileSystemProvider &FSProvider,
DiagnosticsConsumer &DiagConsumer,
const Options &Opts)
: CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
/// \p DiagConsumer. Note that a callback to \p DiagConsumer happens on a
/// worker thread. Therefore, instances of \p DiagConsumer must properly
/// synchronize access to shared state.
- ClangdServer(GlobalCompilationDatabase &CDB, FileSystemProvider &FSProvider,
+ ClangdServer(const GlobalCompilationDatabase &CDB,
+ const FileSystemProvider &FSProvider,
DiagnosticsConsumer &DiagConsumer, const Options &Opts);
/// Set the root path of the workspace.
tooling::CompileCommand getCompileCommand(PathRef File);
- GlobalCompilationDatabase &CDB;
+ const GlobalCompilationDatabase &CDB;
DiagnosticsConsumer &DiagConsumer;
- FileSystemProvider &FSProvider;
+ const FileSystemProvider &FSProvider;
/// Used to synchronize diagnostic responses for added and removed files.
llvm::StringMap<DocVersion> InternalVersion;
/// Context::current() will be the context passed to the clang entrypoint,
/// such as addDocument(), and will also be propagated to result callbacks.
/// Embedders may use this to isolate filesystem accesses.
- virtual IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() = 0;
+ virtual IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() const = 0;
};
class RealFileSystemProvider : public FileSystemProvider {
public:
// FIXME: returns the single real FS instance, which is not threadsafe.
- IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() override {
+ IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() const override {
return vfs::getRealFileSystem();
}
};
TEST_F(ClangdVFSTest, PropagatesContexts) {
static Key<int> Secret;
struct FSProvider : public FileSystemProvider {
- IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() override {
+ IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() const override {
Got = Context::current().getExisting(Secret);
return buildTestFS({});
}
- int Got;
+ mutable int Got;
} FS;
struct DiagConsumer : public DiagnosticsConsumer {
void onDiagnosticsReady(PathRef File,
ListenStatsFSProvider(llvm::StringMap<unsigned> &CountStats)
: CountStats(CountStats) {}
- IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() override {
+ IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() const override {
class ListenStatVFS : public vfs::ProxyFileSystem {
public:
ListenStatVFS(IntrusiveRefCntPtr<vfs::FileSystem> FS,
// A VFS provider that returns TestFSes containing a provided set of files.
class MockFSProvider : public FileSystemProvider {
public:
- IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() override {
+ IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() const override {
return buildTestFS(Files);
}