From 26fac469d2c27f65c17ff3d0d89b6e7eef18f212 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Wed, 10 Oct 2018 07:46:15 +0000 Subject: [PATCH] [clangd] Make FSProvider const-correct. NFC llvm-svn: 344118 --- clang-tools-extra/clangd/ClangdServer.cpp | 4 ++-- clang-tools-extra/clangd/ClangdServer.h | 7 ++++--- clang-tools-extra/clangd/FSProvider.h | 4 ++-- clang-tools-extra/unittests/clangd/ClangdTests.cpp | 6 +++--- clang-tools-extra/unittests/clangd/TestFS.h | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index f0b94cb95e5d..bdba66e0aa94 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -97,8 +97,8 @@ ClangdServer::Options ClangdServer::optsForTest() { 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), diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index c66ed868ac03..9f17e73c0f6d 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -109,7 +109,8 @@ public: /// \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. @@ -227,9 +228,9 @@ private: 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 InternalVersion; diff --git a/clang-tools-extra/clangd/FSProvider.h b/clang-tools-extra/clangd/FSProvider.h index 70dfb441a00c..a11d38101008 100644 --- a/clang-tools-extra/clangd/FSProvider.h +++ b/clang-tools-extra/clangd/FSProvider.h @@ -25,13 +25,13 @@ public: /// 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 getFileSystem() = 0; + virtual IntrusiveRefCntPtr getFileSystem() const = 0; }; class RealFileSystemProvider : public FileSystemProvider { public: // FIXME: returns the single real FS instance, which is not threadsafe. - IntrusiveRefCntPtr getFileSystem() override { + IntrusiveRefCntPtr getFileSystem() const override { return vfs::getRealFileSystem(); } }; diff --git a/clang-tools-extra/unittests/clangd/ClangdTests.cpp b/clang-tools-extra/unittests/clangd/ClangdTests.cpp index b9003a863565..87741dfb0944 100644 --- a/clang-tools-extra/unittests/clangd/ClangdTests.cpp +++ b/clang-tools-extra/unittests/clangd/ClangdTests.cpp @@ -264,11 +264,11 @@ int b = a; TEST_F(ClangdVFSTest, PropagatesContexts) { static Key Secret; struct FSProvider : public FileSystemProvider { - IntrusiveRefCntPtr getFileSystem() override { + IntrusiveRefCntPtr getFileSystem() const override { Got = Context::current().getExisting(Secret); return buildTestFS({}); } - int Got; + mutable int Got; } FS; struct DiagConsumer : public DiagnosticsConsumer { void onDiagnosticsReady(PathRef File, @@ -973,7 +973,7 @@ TEST(ClangdTests, PreambleVFSStatCache) { ListenStatsFSProvider(llvm::StringMap &CountStats) : CountStats(CountStats) {} - IntrusiveRefCntPtr getFileSystem() override { + IntrusiveRefCntPtr getFileSystem() const override { class ListenStatVFS : public vfs::ProxyFileSystem { public: ListenStatVFS(IntrusiveRefCntPtr FS, diff --git a/clang-tools-extra/unittests/clangd/TestFS.h b/clang-tools-extra/unittests/clangd/TestFS.h index a0efb755d006..39c0bb22b0e6 100644 --- a/clang-tools-extra/unittests/clangd/TestFS.h +++ b/clang-tools-extra/unittests/clangd/TestFS.h @@ -29,7 +29,7 @@ buildTestFS(llvm::StringMap const &Files, // A VFS provider that returns TestFSes containing a provided set of files. class MockFSProvider : public FileSystemProvider { public: - IntrusiveRefCntPtr getFileSystem() override { + IntrusiveRefCntPtr getFileSystem() const override { return buildTestFS(Files); }