clang-tools 20.0.0git
|
A FeatureModule contributes a vertical feature to clangd. More...
#include <FeatureModule.h>
Classes | |
struct | ASTListener |
Extension point that allows modules to observe and modify an AST build. More... | |
struct | Facilities |
Shared server facilities needed by the module to get its work done. More... | |
Public Member Functions | |
virtual | ~FeatureModule () |
virtual void | initializeLSP (LSPBinder &Bind, const llvm::json::Object &ClientCaps, llvm::json::Object &ServerCaps) |
Called by the server to connect this feature module to LSP. | |
void | initialize (const Facilities &F) |
Called by the server to prepare this module for use. | |
virtual void | stop () |
Requests that the module cancel background work and go idle soon. | |
virtual bool | blockUntilIdle (Deadline) |
Waits until the module is idle (no background work) or a deadline expires. | |
virtual void | contributeTweaks (std::vector< std::unique_ptr< Tweak > > &Out) |
Tweaks implemented by this module. | |
virtual std::unique_ptr< ASTListener > | astListeners () |
Can be called asynchronously before building an AST. | |
Protected Types | |
template<typename P > | |
using | OutgoingNotification = llvm::unique_function< void(const P &)> |
Types of function objects that feature modules use for outgoing calls. | |
template<typename P , typename R > | |
using | OutgoingMethod = llvm::unique_function< void(const P &, Callback< R >)> |
Protected Member Functions | |
Facilities & | facilities () |
Accessors for modules to access shared server facilities they depend on. | |
TUScheduler & | scheduler () |
The scheduler is used to run tasks on worker threads and access ASTs. | |
const SymbolIndex * | index () |
The index is used to get information about the whole codebase. | |
const ThreadsafeFS & | fs () |
The filesystem is used to read source files on disk. | |
A FeatureModule contributes a vertical feature to clangd.
The lifetime of a module is roughly:
module hooks can be called by the server at this point. Server facilities (scheduler etc) are available.
FeatureModules are not threadsafe in general. A module's entrypoints are:
Conventionally, standard feature modules live in the clangd
namespace, and other exposed details live in a sub-namespace.
Definition at line 56 of file FeatureModule.h.
|
protected |
Definition at line 138 of file FeatureModule.h.
|
protected |
Types of function objects that feature modules use for outgoing calls.
(Bound throuh LSPBinder, made available here for convenience).
Definition at line 136 of file FeatureModule.h.
|
inlinevirtual |
Perform shutdown sequence on destruction in case the ClangdServer was never initialized. Usually redundant, but shutdown is idempotent.
Definition at line 58 of file FeatureModule.h.
References blockUntilIdle(), clang::clangd::Deadline::infinity(), and stop().
|
inlinevirtual |
Can be called asynchronously before building an AST.
Definition at line 121 of file FeatureModule.h.
|
inlinevirtual |
Waits until the module is idle (no background work) or a deadline expires.
In general all modules should eventually go idle, though it may take a long time (e.g. background indexing). FeatureModules should go idle quickly if stop() has been called. Called by the server when shutting down, and also by tests.
Definition at line 96 of file FeatureModule.h.
Referenced by ~FeatureModule().
|
inlinevirtual |
Tweaks implemented by this module.
Can be called asynchronously when enumerating or applying code actions.
Definition at line 100 of file FeatureModule.h.
|
protected |
Accessors for modules to access shared server facilities they depend on.
Definition at line 20 of file FeatureModule.cpp.
Referenced by fs(), index(), and scheduler().
|
inlineprotected |
The filesystem is used to read source files on disk.
Definition at line 131 of file FeatureModule.h.
References facilities(), and clang::clangd::FeatureModule::Facilities::FS.
|
inlineprotected |
The index is used to get information about the whole codebase.
Definition at line 129 of file FeatureModule.h.
References facilities(), and clang::clangd::FeatureModule::Facilities::Index.
void clang::clangd::FeatureModule::initialize | ( | const Facilities & | F | ) |
Called by the server to prepare this module for use.
Definition at line 15 of file FeatureModule.cpp.
|
inlinevirtual |
Called by the server to connect this feature module to LSP.
The module should register the methods/notifications/commands it handles, and update the server capabilities to advertise them.
This is only called if the module is running in ClangdLSPServer! FeatureModules with a public interface should work without LSP bindings.
Definition at line 71 of file FeatureModule.h.
|
inlineprotected |
The scheduler is used to run tasks on worker threads and access ASTs.
Definition at line 127 of file FeatureModule.h.
References facilities(), and clang::clangd::FeatureModule::Facilities::Scheduler.
|
inlinevirtual |
Requests that the module cancel background work and go idle soon.
Does not block, the caller will call blockUntilIdle() instead. After a module is stop()ed, it should not receive any more requests. Called by the server when shutting down. May be called multiple times, should be idempotent.
Definition at line 89 of file FeatureModule.h.
Referenced by ~FeatureModule().