9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TUSCHEDULER_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TUSCHEDULER_H
16#include "clang-include-cleaner/Record.h"
21#include "llvm/ADT/StringMap.h"
22#include "llvm/ADT/StringRef.h"
75 using clock = std::chrono::steady_clock;
78 clock::duration
Min = {};
80 clock::duration
Max = {};
86 clock::duration
compute(llvm::ArrayRef<clock::duration> History)
const;
167 std::shared_ptr<const include_cleaner::PragmaIncludes>) {}
170 using PublishFn = llvm::function_ref<void(llvm::function_ref<
void()>)>;
196 std::vector<Diag> Diags,
PublishFn Publish) {}
242 std::unique_ptr<ParsingCallbacks> ASTCallbacks =
nullptr);
253 llvm::StringMap<FileStats>
fileStats()
const;
276 void run(llvm::StringRef
Name, llvm::StringRef
Path,
277 llvm::unique_function<
void()>
Action);
284 llvm::unique_function<
void()>
Action);
347 class HeaderIncluderCache;
360 void runWithSemaphore(llvm::StringRef
Name, llvm::StringRef
Path,
365 std::unique_ptr<ParsingCallbacks> Callbacks;
368 llvm::StringMap<std::unique_ptr<FileData>> Files;
369 std::unique_ptr<ASTCache> IdleASTs;
370 std::unique_ptr<HeaderIncluderCache> HeaderIncluders;
373 std::optional<AsyncTaskRunner> PreambleTasks;
374 std::optional<AsyncTaskRunner> WorkerThreads;
377 std::string LastActiveFile;
llvm::SmallString< 256U > Name
std::string Filename
Filename as a string.
A context is an immutable container for per-request data that must be propagated through layers that ...
A point in time we can wait for.
Provides compilation arguments used for parsing C and C++ files.
Stores and provides access to parsed AST.
virtual void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish)
Called on the AST built for the file itself.
virtual void onPreambleAST(PathRef Path, llvm::StringRef Version, CapturedASTCtx Ctx, std::shared_ptr< const include_cleaner::PragmaIncludes >)
Called on the AST that was built for emitting the preamble.
virtual void onPreamblePublished(PathRef File)
Preamble for the TU have changed.
virtual void onFileUpdated(PathRef File, const TUStatus &Status)
Called whenever the TU status is updated.
virtual ~ParsingCallbacks()=default
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...
virtual void onFailedAST(PathRef Path, llvm::StringRef Version, std::vector< Diag > Diags, PublishFn Publish)
Called whenever the AST fails to build.
PreambleThrottler controls which preambles can build at any given time.
llvm::unique_function< void()> Callback
virtual ~PreambleThrottler()=default
virtual RequestID acquire(llvm::StringRef Filename, Callback)=0
Attempt to acquire resources to build a file's preamble.
virtual void release(RequestID)=0
Abandons the request/releases any resources that have been acquired.
Limits the number of threads that can acquire the lock at the same time.
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for open...
void runWithPreamble(llvm::StringRef Name, PathRef File, PreambleConsistency Consistency, Callback< InputsAndPreamble > Action)
Schedule an async read of the preamble.
void remove(PathRef File)
Remove File from the list of tracked files and schedule removal of its resources.
static std::optional< llvm::StringRef > getFileBeingProcessedInContext()
std::vector< Path > getFilesWithCachedAST() const
Returns a list of files with ASTs currently stored in memory.
llvm::StringMap< FileStats > fileStats() const
Returns resources used for each of the currently open files.
void profile(MemoryTree &MT) const
bool blockUntilIdle(Deadline D) const
Wait until there are no scheduled or running tasks.
bool update(PathRef File, ParseInputs Inputs, WantDiagnostics WD)
Schedule an update for File.
PreambleConsistency
Controls whether preamble reads wait for the preamble to be up-to-date.
@ StaleOrAbsent
Besides accepting stale preamble, this also allow preamble to be absent (not ready or failed to build...
@ Stale
The preamble may be generated from an older version of the file.
void runQuick(llvm::StringRef Name, llvm::StringRef Path, llvm::unique_function< void()> Action)
Similar to run, except the task is expected to be quick.
ASTActionInvalidation
Defines how a runWithAST action is implicitly cancelled by other actions.
@ NoInvalidation
The request will run unless explicitly cancelled.
@ InvalidateOnUpdate
The request will be implicitly cancelled by a subsequent update().
void runWithAST(llvm::StringRef Name, PathRef File, Callback< InputsAndAST > Action, ASTActionInvalidation=NoInvalidation)
Schedule an async read of the AST.
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
std::string Path
A typedef to represent a file path.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
@ Auto
Diagnostics must not be generated for this snapshot.
@ No
Diagnostics must be generated for this snapshot.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::string Name
The name of the action currently running, e.g.
ASTAction(Kind K, llvm::StringRef Name)
Configuration of the AST retention policy.
unsigned MaxRetainedASTs
Maximum number of ASTs to be retained in memory when there are no pending requests for them.
Signals derived from a valid AST of a file.
The captured AST context.
Clangd may wait after an update to see if another one comes along.
clock::duration compute(llvm::ArrayRef< clock::duration > History) const
Compute the time to debounce based on this policy and recent build times.
float RebuildRatio
Target debounce, as a fraction of file rebuild time.
clock::duration Min
The minimum time that we always debounce for.
clock::duration Max
The maximum time we may debounce for.
static DebouncePolicy fixed(clock::duration)
A policy that always returns the same duration, useful for tests.
std::chrono::steady_clock clock
Clangd extension: indicates the current state of the file in clangd, sent from server via the textDoc...
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...
The parsed preamble and associated data.
std::size_t UsedBytesPreamble
ASTRetentionPolicy RetentionPolicy
Determines when to keep idle ASTs in memory for future use.
DebouncePolicy UpdateDebounce
Time to wait after an update to see if another one comes along.
std::function< Context(PathRef)> ContextProvider
Used to create a context that wraps each single operation.
bool StorePreamblesInMemory
Cache (large) preamble data in RAM rather than temporary files on disk.
unsigned AsyncThreadsCount
Number of concurrent actions.
bool ReuseAST
Indicates whether we reused the prebuilt AST.
bool BuildFailed
Indicates whether clang failed to build the TU.
FileStatus render(PathRef File) const
Serialize this to an LSP file status item.
PreambleAction PreambleActivity
BuildDetails Details
Stores status of the last build for the translation unit.