Go to the documentation of this file.
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TUSCHEDULER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TUSCHEDULER_H
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
70 using clock = std::chrono::steady_clock;
73 clock::duration
Min = {};
75 clock::duration
Max = {};
81 clock::duration
compute(llvm::ArrayRef<clock::duration> History)
const;
133 std::shared_ptr<clang::Preprocessor>
PP,
138 using PublishFn = llvm::function_ref<void(llvm::function_ref<
void()>)>;
206 std::unique_ptr<ParsingCallbacks> ASTCallbacks =
nullptr);
216 llvm::StringMap<FileStats>
fileStats()
const;
242 void run(llvm::StringRef
Name, llvm::StringRef
Path,
243 llvm::unique_function<
void()>
Action);
317 std::unique_ptr<ParsingCallbacks> Callbacks;
319 llvm::StringMap<std::unique_ptr<FileData>> Files;
320 std::unique_ptr<ASTCache> IdleASTs;
323 llvm::Optional<AsyncTaskRunner> PreambleTasks;
324 llvm::Optional<AsyncTaskRunner> WorkerThreads;
virtual ~ParsingCallbacks()=default
void runWithPreamble(llvm::StringRef Name, PathRef File, PreambleConsistency Consistency, Callback< InputsAndPreamble > Action)
Schedule an async read of the preamble.
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
llvm::function_ref< void(llvm::function_ref< void()>)> PublishFn
The argument function is run under the critical section guarding against races when closing the files...
std::string Path
A typedef to represent a file path.
Configuration of the AST retention policy.
virtual void onFailedAST(PathRef Path, llvm::StringRef Version, std::vector< Diag > Diags, PublishFn Publish)
Called whenever the AST fails to build.
bool blockUntilIdle(Deadline D) const
Wait until there are no scheduled or running tasks.
virtual void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish)
Called on the AST built for the file itself.
Diagnostics must not be generated for this snapshot.
std::chrono::steady_clock clock
void run(llvm::StringRef Name, llvm::StringRef Path, llvm::unique_function< void()> Action)
Schedule an async task with no dependencies.
virtual void onFileUpdated(PathRef File, const TUStatus &Status)
Called whenever the TU status is updated.
std::vector< Path > getFilesWithCachedAST() const
Returns a list of files with ASTs currently stored in memory.
ASTRetentionPolicy RetentionPolicy
Determines when to keep idle ASTs in memory for future use.
virtual void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx, std::shared_ptr< clang::Preprocessor > PP, const CanonicalIncludes &)
Called on the AST that was built for emitting the preamble.
TUScheduler(const GlobalCompilationDatabase &CDB, const Options &Opts, std::unique_ptr< ParsingCallbacks > ASTCallbacks=nullptr)
bool update(PathRef File, ParseInputs Inputs, WantDiagnostics WD)
Schedule an update for File.
std::string Name
The name of the action currently running, e.g.
Provides compilation arguments used for parsing C and C++ files.
llvm::unique_function< void()> Action
std::function< Context(PathRef)> ContextProvider
Used to create a context that wraps each single operation.
The preamble may be generated from an older version of the file.
Limits the number of threads that can acquire the lock at the same time.
Besides accepting stale preamble, this also allow preamble to be absent (not ready or failed to build...
A point in time we can wait for.
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
The parsed preamble and associated data.
Maps a definition location onto an #include file, based on a set of filename rules.
unsigned AsyncThreadsCount
Number of concurrent actions.
static constexpr llvm::StringLiteral Name
void remove(PathRef File)
Remove File from the list of tracked files and schedule removal of its resources.
llvm::StringMap< FileStats > fileStats() const
Returns resources used for each of the currently open files.
FileStatus render(PathRef File) const
Serialize this to an LSP file status item.
clock::duration Min
The minimum time that we always debounce for.
DebouncePolicy UpdateDebounce
Time to wait after an update to see if another one comes along.
BuildDetails Details
Stores status of the last build for the translation unit.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
ASTActionInvalidation
Defines how a runWithAST action is implicitly cancelled by other actions.
void runWithAST(llvm::StringRef Name, PathRef File, Callback< InputsAndAST > Action, ASTActionInvalidation=NoInvalidation)
Schedule an async read of the AST.
Clangd may wait after an update to see if another one comes along.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
The request will run unless explicitly cancelled.
PreambleAction PreambleActivity
llvm::StringMap< std::string > getAllFileContents() const
Returns a snapshot of all file buffer contents, per last update().
Clangd extension: indicates the current state of the file in clangd, sent from server via the textDoc...
float RebuildRatio
Target debounce, as a fraction of file rebuild time.
clock::duration Max
The maximum time we may debounce for.
PreambleConsistency
Controls whether preamble reads wait for the preamble to be up-to-date.
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for open...
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
static DebouncePolicy fixed(clock::duration)
A policy that always returns the same duration, useful for tests.
Stores and provides access to parsed AST.
Diagnostics must be generated for this snapshot.
bool ReuseAST
Indicates whether we reused the prebuilt AST.
bool AsyncPreambleBuilds
Whether to run PreamblePeer asynchronously.
bool BuildFailed
Indicates whether clang failed to build the TU.
ASTAction(Kind K, llvm::StringRef Name)
bool StorePreamblesInMemory
Cache (large) preamble data in RAM rather than temporary files on disk.
unsigned MaxRetainedASTs
Maximum number of ASTs to be retained in memory when there are no pending requests for them.
clock::duration compute(llvm::ArrayRef< clock::duration > History) const
Compute the time to debounce based on this policy and recent build times.
A context is an immutable container for per-request data that must be propagated through layers that ...
static llvm::Optional< llvm::StringRef > getFileBeingProcessedInContext()
The request will be implicitly cancelled by a subsequent update().