clang-tools
8.0.0
|
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for opened files. More...
#include <TUScheduler.h>
Classes | |
class | ASTCache |
An LRU cache of idle ASTs. More... | |
struct | FileData |
Public Types | |
enum | PreambleConsistency { Consistent, Stale } |
Controls whether preamble reads wait for the preamble to be up-to-date. More... | |
Public Member Functions | |
TUScheduler (unsigned AsyncThreadsCount, bool StorePreamblesInMemory, std::unique_ptr< ParsingCallbacks > ASTCallbacks, std::chrono::steady_clock::duration UpdateDebounce, ASTRetentionPolicy RetentionPolicy) | |
~TUScheduler () | |
std::vector< std::pair< Path, std::size_t > > | getUsedBytesPerFile () const |
Returns estimated memory usage for each of the currently open files. More... | |
std::vector< Path > | getFilesWithCachedAST () const |
Returns a list of files with ASTs currently stored in memory. More... | |
void | update (PathRef File, ParseInputs Inputs, WantDiagnostics WD) |
Schedule an update for File . More... | |
void | remove (PathRef File) |
Remove File from the list of tracked files and schedule removal of its resources. More... | |
void | run (llvm::StringRef Name, llvm::unique_function< void()> Action) |
Schedule an async task with no dependencies. More... | |
void | runWithAST (llvm::StringRef Name, PathRef File, Callback< InputsAndAST > Action) |
Schedule an async read of the AST. More... | |
void | runWithPreamble (llvm::StringRef Name, PathRef File, PreambleConsistency Consistency, Callback< InputsAndPreamble > Action) |
Schedule an async read of the preamble. More... | |
bool | blockUntilIdle (Deadline D) const |
Wait until there are no scheduled or running tasks. More... | |
Static Public Member Functions | |
static llvm::Optional< llvm::StringRef > | getFileBeingProcessedInContext () |
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for opened files.
TUScheduler is not thread-safe, only one thread should be providing updates and scheduling tasks. Callbacks are run on a threadpool and it's appropriate to do slow work in them. Each task has a name, used for tracing (should be UpperCamelCase). FIXME(sammccall): pull out a scheduler options struct.
Definition at line 122 of file TUScheduler.h.
Controls whether preamble reads wait for the preamble to be up-to-date.
Definition at line 166 of file TUScheduler.h.
clang::clangd::TUScheduler::TUScheduler | ( | unsigned | AsyncThreadsCount, |
bool | StorePreamblesInMemory, | ||
std::unique_ptr< ParsingCallbacks > | ASTCallbacks, | ||
std::chrono::steady_clock::duration | UpdateDebounce, | ||
ASTRetentionPolicy | RetentionPolicy | ||
) |
Definition at line 786 of file TUScheduler.cpp.
clang::clangd::TUScheduler::~TUScheduler | ( | ) |
Definition at line 804 of file TUScheduler.cpp.
bool clang::clangd::TUScheduler::blockUntilIdle | ( | Deadline | D | ) | const |
Wait until there are no scheduled or running tasks.
Mostly useful for synchronizing tests.
Definition at line 815 of file TUScheduler.cpp.
References clang::clangd::File.
Referenced by clang::clangd::ClangdServer::blockUntilIdleForTest().
|
static |
Definition at line 69 of file TUScheduler.cpp.
References clang::clangd::Context::current(), clang::clangd::File, and clang::clangd::None.
std::vector< Path > clang::clangd::TUScheduler::getFilesWithCachedAST | ( | ) | const |
Returns a list of files with ASTs currently stored in memory.
This method is not very reliable and is only used for test. E.g., the results will not contain files that currently run something over their AST.
Definition at line 945 of file TUScheduler.cpp.
References Result.
std::vector< std::pair< Path, std::size_t > > clang::clangd::TUScheduler::getUsedBytesPerFile | ( | ) | const |
Returns estimated memory usage for each of the currently open files.
The order of results is unspecified.
Definition at line 936 of file TUScheduler.cpp.
References Result.
Referenced by clang::clangd::ClangdServer::getUsedBytesPerFile().
void clang::clangd::TUScheduler::remove | ( | PathRef | File | ) |
Remove File
from the list of tracked files and schedule removal of its resources.
Pending diagnostics for closed files may not be delivered, even if requested with WantDiags::Auto or WantDiags::Yes.
Definition at line 842 of file TUScheduler.cpp.
References clang::clangd::elog().
Referenced by clang::clangd::ClangdServer::removeDocument().
void clang::clangd::TUScheduler::run | ( | llvm::StringRef | Name, |
llvm::unique_function< void()> | Action | ||
) |
Schedule an async task with no dependencies.
Definition at line 849 of file TUScheduler.cpp.
References Action.
void clang::clangd::TUScheduler::runWithAST | ( | llvm::StringRef | Name, |
PathRef | File, | ||
Callback< InputsAndAST > | Action | ||
) |
Schedule an async read of the AST.
Action
will be called when AST is ready. The AST passed to Action
refers to the version of File
tracked at the time of the call, even if new updates are received before Action
is executed. If an error occurs during processing, it is forwarded to the Action
callback. If the context is cancelled before the AST is ready, the callback will receive a CancelledError.
Definition at line 856 of file TUScheduler.cpp.
References Action, and clang::clangd::InvalidParams.
Referenced by clang::clangd::ClangdServer::documentSymbols(), clang::clangd::ClangdServer::dumpAST(), clang::clangd::ClangdServer::findDefinitions(), clang::clangd::ClangdServer::findDocumentHighlights(), clang::clangd::ClangdServer::findHover(), and clang::clangd::ClangdServer::symbolInfo().
void clang::clangd::TUScheduler::runWithPreamble | ( | llvm::StringRef | Name, |
PathRef | File, | ||
PreambleConsistency | Consistency, | ||
Callback< InputsAndPreamble > | Action | ||
) |
Schedule an async read of the preamble.
If there's no preamble yet (because the file was just opened), we'll wait for it to build. The result may be null if it fails to build or is empty. If an error occurs, it is forwarded to the Action
callback. Context cancellation is ignored and should be handled by the Action. (In practice, the Action is almost always executed immediately).
Definition at line 869 of file TUScheduler.cpp.
References Action, and clang::clangd::InvalidParams.
Referenced by clang::clangd::ClangdServer::signatureHelp().
void clang::clangd::TUScheduler::update | ( | PathRef | File, |
ParseInputs | Inputs, | ||
WantDiagnostics | WD | ||
) |
Schedule an update for File
.
Adds File
to a list of tracked files if File
was not part of it before. If diagnostics are requested (Yes), and the context is cancelled before they are prepared, they may be skipped if eventual-consistency permits it (i.e. WantDiagnostics is downgraded to Auto).
Definition at line 825 of file TUScheduler.cpp.
References clang::clangd::File.
Referenced by clang::clangd::ClangdServer::addDocument().