#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTFS_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTFS_H
#include "GlobalCompilationDatabase.h"
#include "support/Path.h"
#include "support/ThreadsafeFS.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <optional>
namespace clang {
namespace clangd {
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
buildTestFS(llvm::StringMap<std::string> const &Files,
llvm::StringMap<time_t> const &Timestamps = {});
class MockFS : public ThreadsafeFS {
public:
IntrusiveRefCntPtr<llvm::vfs::FileSystem> viewImpl() const override {
auto MemFS = buildTestFS(Files, Timestamps);
if (!OverlayRealFileSystemForModules)
return MemFS;
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem =
new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem());
OverlayFileSystem->pushOverlay(MemFS);
return OverlayFileSystem;
}
llvm::StringMap<std::string> Files;
llvm::StringMap<time_t> Timestamps;
bool OverlayRealFileSystemForModules = false;
};
class MockCompilationDatabase : public GlobalCompilationDatabase {
public:
MockCompilationDatabase(StringRef Directory = StringRef(),
StringRef RelPathPrefix = StringRef());
std::optional<tooling::CompileCommand>
getCompileCommand(PathRef File) const override;
std::optional<ProjectInfo> getProjectInfo(PathRef File) const override;
std::vector<std::string> ExtraClangFlags;
protected:
StringRef Directory;
StringRef RelPathPrefix;
};
const char *testRoot();
std::string testPath(PathRef File,
llvm::sys::path::Style = llvm::sys::path::Style::native);
extern volatile int UnittestSchemeAnchorSource;
}
}
#endif