clang-tools  7.0.0
Classes | Public Member Functions | List of all members
clang::clangd::TUScheduler Class Reference

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 Member Functions

 TUScheduler (unsigned AsyncThreadsCount, bool StorePreamblesInMemory, PreambleParsedCallback PreambleCallback, 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< PathgetFilesWithCachedAST () const
 Returns a list of files with ASTs currently stored in memory. More...
 
void update (PathRef File, ParseInputs Inputs, WantDiagnostics WD, llvm::unique_function< void(std::vector< Diag >)> OnUpdated)
 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 runWithAST (llvm::StringRef Name, PathRef File, Callback< InputsAndAST > Action)
 Schedule an async read of the AST. More...
 
void runWithPreamble (llvm::StringRef Name, PathRef File, 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...
 

Detailed Description

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 61 of file TUScheduler.h.

Constructor & Destructor Documentation

◆ TUScheduler()

clang::clangd::TUScheduler::TUScheduler ( unsigned  AsyncThreadsCount,
bool  StorePreamblesInMemory,
PreambleParsedCallback  PreambleCallback,
std::chrono::steady_clock::duration  UpdateDebounce,
ASTRetentionPolicy  RetentionPolicy 
)

Definition at line 620 of file TUScheduler.cpp.

◆ ~TUScheduler()

clang::clangd::TUScheduler::~TUScheduler ( )

Definition at line 636 of file TUScheduler.cpp.

Member Function Documentation

◆ blockUntilIdle()

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 647 of file TUScheduler.cpp.

References clang::clangd::File.

Referenced by clang::clangd::ClangdServer::blockUntilIdleForTest().

◆ getFilesWithCachedAST()

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 753 of file TUScheduler.cpp.

◆ getUsedBytesPerFile()

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 744 of file TUScheduler.cpp.

Referenced by clang::clangd::ClangdServer::getUsedBytesPerFile().

◆ remove()

void clang::clangd::TUScheduler::remove ( PathRef  File)

Remove File from the list of tracked files and schedule removal of its resources.

Definition at line 676 of file TUScheduler.cpp.

References clang::clangd::elog().

Referenced by clang::clangd::ClangdServer::removeDocument().

◆ runWithAST()

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.

Definition at line 683 of file TUScheduler.cpp.

References Action.

Referenced by clang::clangd::ClangdServer::documentSymbols(), clang::clangd::ClangdServer::dumpAST(), clang::clangd::ClangdServer::findDefinitions(), clang::clangd::ClangdServer::findDocumentHighlights(), and clang::clangd::ClangdServer::findHover().

◆ runWithPreamble()

void clang::clangd::TUScheduler::runWithPreamble ( llvm::StringRef  Name,
PathRef  File,
Callback< InputsAndPreamble Action 
)

Schedule an async read of the Preamble.

The preamble may be stale, generated from an older version of the file. Reading from locations in the preamble may cause the files to be re-read. This gives callers two options:

  • validate that the preamble is still valid, and only use it in this case
  • accept that preamble contents may be outdated, and try to avoid reading source code from headers. If there's no preamble yet (because the file was just opened), we'll wait for it to build. The preamble may still be null if it fails to build or is empty. If an error occurs during processing, it is forwarded to the Action callback.

Definition at line 697 of file TUScheduler.cpp.

References Action.

Referenced by clang::clangd::ClangdServer::signatureHelp().

◆ update()

void clang::clangd::TUScheduler::update ( PathRef  File,
ParseInputs  Inputs,
WantDiagnostics  WD,
llvm::unique_function< void(std::vector< Diag >)>  OnUpdated 
)

Schedule an update for File.

Adds File to a list of tracked files if File was not part of it before. FIXME(ibiryukov): remove the callback from this function.

Definition at line 657 of file TUScheduler.cpp.

References clang::clangd::File.

Referenced by clang::clangd::ClangdServer::addDocument().


The documentation for this class was generated from the following files: