10#include "llvm/ADT/ScopeExit.h"
21 std::numeric_limits<uint64_t>::max();
26 :
Path(
Path), ValidTime(std::chrono::steady_clock::time_point::min()),
28 assert(llvm::sys::path::is_absolute(
Path));
32 const ThreadsafeFS &TFS, std::chrono::steady_clock::time_point FreshTime,
33 llvm::function_ref<
void(std::optional<llvm::StringRef>)> Parse,
34 llvm::function_ref<
void()>
Read)
const {
36 std::lock_guard<std::mutex> Lock(Mu);
38 auto Return = llvm::make_scope_exit(
Read);
41 if (ValidTime > FreshTime)
46 auto BumpValidTime = llvm::make_scope_exit(
47 [&] { ValidTime = std::chrono::steady_clock::now(); });
50 assert(llvm::sys::path::is_absolute(
Path));
51 auto FS = TFS.view(std::nullopt);
52 auto Stat = FS->status(
Path);
53 if (!Stat || !Stat->isRegularFile()) {
61 if (Size == Stat->getSize() &&
62 ModifiedTime == Stat->getLastModificationTime())
66 Size = Stat->getSize();
67 ModifiedTime = Stat->getLastModificationTime();
69 if (
auto Buf = FS->getBufferForFile(
Path)) {
70 Parse(Buf->get()->getBuffer());
73 if (Buf->get()->getBufferSize() != Size)
void read(const ThreadsafeFS &TFS, std::chrono::steady_clock::time_point FreshTime, llvm::function_ref< void(std::optional< llvm::StringRef >)> Parse, llvm::function_ref< void()> Read) const
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
std::string Path
A typedef to represent a file path.
static constexpr uint64_t CacheDiskMismatch
static constexpr uint64_t FileNotFound
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//