16#include "llvm/ADT/STLExtras.h"
17#include "llvm/ADT/StringMap.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Path.h"
31 mutable llvm::SmallVector<CompiledFragment, 1> CachedValue;
32 std::string Directory;
39 std::chrono::steady_clock::time_point FreshTime,
bool Trusted,
40 std::vector<CompiledFragment> &
Out)
const {
43 [&](std::optional<llvm::StringRef> Data) {
49 CachedValue.push_back(std::move(
Fragment).compile(DC));
52 [&]() { llvm::copy(CachedValue, std::back_inserter(
Out)); });
60 class AbsFileProvider :
public Provider {
65 std::vector<CompiledFragment>
67 std::vector<CompiledFragment> Result;
73 AbsFileProvider(llvm::StringRef
Path, llvm::StringRef
Directory,
76 assert(llvm::sys::path::is_absolute(
Path));
83std::unique_ptr<Provider>
86 class RelFileProvider :
public Provider {
91 mutable std::mutex Mu;
95 mutable llvm::StringMap<FileConfigCache> Cache;
97 std::vector<CompiledFragment>
99 namespace path = llvm::sys::path;
105 llvm::SmallVector<llvm::StringRef, 8> Ancestors;
108 Ancestors.emplace_back(Ancestor);
111 llvm::SmallVector<FileConfigCache *, 8> Caches;
113 std::lock_guard<std::mutex> Lock(Mu);
114 for (llvm::StringRef Ancestor : Ancestors) {
115 auto It = Cache.find(Ancestor);
117 if (It == Cache.end()) {
118 llvm::SmallString<256> ConfigPath = Ancestor;
119 path::append(ConfigPath, RelPath);
121 llvm::sys::path::native(ConfigPath);
122 It = Cache.try_emplace(Ancestor, ConfigPath.str(), Ancestor).first;
124 Caches.push_back(&It->second);
129 std::vector<CompiledFragment> Result;
136 RelFileProvider(llvm::StringRef RelPath,
const ThreadsafeFS &FS,
139 assert(llvm::sys::path::is_relative(RelPath));
143 return std::make_unique<RelFileProvider>(RelPath, FS,
Trusted);
146std::unique_ptr<Provider>
148 class CombinedProvider :
public Provider {
149 std::vector<const Provider *> Providers;
151 std::vector<CompiledFragment>
153 std::vector<CompiledFragment> Result;
154 for (
const auto &
Provider : Providers) {
156 Result.push_back(std::move(
Fragment));
162 CombinedProvider(std::vector<const Provider *> Providers)
163 : Providers(std::move(Providers)) {}
166 return std::make_unique<CombinedProvider>(std::move(Providers));
174 for (
const auto &
Fragment : getFragments(P, DC))
CompiledFragmentImpl & Out
llvm::StringRef Directory
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
Base class for threadsafe cache of data read from a file on disk.
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.
void get(const ThreadsafeFS &TFS, DiagnosticCallback DC, std::chrono::steady_clock::time_point FreshTime, bool Trusted, std::vector< CompiledFragment > &Out) const
FileConfigCache(llvm::StringRef Path, llvm::StringRef Directory)
A source of configuration fragments.
static std::unique_ptr< Provider > fromYAMLFile(llvm::StringRef AbsPath, llvm::StringRef Directory, const ThreadsafeFS &, bool Trusted=false)
Reads fragments from a single YAML file with a fixed path.
Config getConfig(const Params &, DiagnosticCallback) const
Build a config based on this provider.
static std::unique_ptr< Provider > fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath, const ThreadsafeFS &, bool Trusted=false)
static std::unique_ptr< Provider > combine(std::vector< const Provider * >)
A provider that includes fragments from all the supplied providers.
Records an event whose duration is the lifetime of the Span object.
llvm::function_ref< void(const llvm::SMDiagnostic &)> DiagnosticCallback
Used to report problems in parsing or interpreting a config.
std::string Path
A typedef to represent a file path.
PathRef absoluteParent(PathRef Path)
Variant of parent_path that operates only on absolute paths.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Settings that express user/project preferences and control clangd behavior.
bool Trusted
Whether this fragment is allowed to make critical security/privacy decisions.
std::string Directory
Absolute path to directory the fragment is associated with.
A chunk of configuration obtained from a config file, LSP, or elsewhere.
static std::vector< Fragment > parseYAML(llvm::StringRef YAML, llvm::StringRef BufferName, DiagnosticCallback)
Parses fragments from a YAML file (one from each — delimited document).
Describes the context used to evaluate configuration fragments.
std::chrono::steady_clock::time_point FreshTime
Hint that stale data is OK to improve performance (e.g.
llvm::StringRef Path
Absolute path to a source file we're applying the config to.