9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATUREMODULE_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATUREMODULE_H
14#include "clang/Basic/Diagnostic.h"
15#include "llvm/ADT/FunctionExtras.h"
16#include "llvm/Support/Compiler.h"
17#include "llvm/Support/JSON.h"
18#include "llvm/Support/Registry.h"
25class CompilerInstance;
73 const llvm::json::Object &ClientCaps,
74 llvm::json::Object &ServerCaps) {}
141 virtual std::unique_ptr<ASTListener>
astListeners() {
return nullptr; }
155 template <
typename P>
157 template <
typename P,
typename R>
161 std::optional<Facilities> Fac;
177 std::vector<std::unique_ptr<FeatureModule>> Modules;
178 llvm::DenseMap<void *, FeatureModule *> Map;
180 template <
typename Mod>
struct ID {
181 static_assert(std::is_base_of<FeatureModule, Mod>::value &&
182 std::is_final<Mod>::value,
183 "Modules must be final classes derived from clangd::Module");
187 bool addImpl(
void *
Key, std::unique_ptr<FeatureModule>,
const char *Source);
202 void add(std::unique_ptr<FeatureModule> M);
203 template <
typename Mod>
bool add(std::unique_ptr<Mod> M) {
204 return addImpl(&ID<Mod>::Key, std::move(M), LLVM_PRETTY_FUNCTION);
206 template <
typename Mod> Mod *
get() {
207 return static_cast<Mod *
>(Map.lookup(&ID<Mod>::Key));
209 template <
typename Mod>
const Mod *
get()
const {
214template <
typename Mod>
int FeatureModuleSet::ID<Mod>::Key;
222extern template class Registry<clang::clangd::FeatureModule>;
A point in time we can wait for.
static Deadline infinity()
llvm::pointee_iterator< decltype(Modules)::iterator > iterator
bool add(std::unique_ptr< Mod > M)
FeatureModuleSet()=default
static FeatureModuleSet fromRegistry()
const_iterator begin() const
void add(std::unique_ptr< FeatureModule > M)
llvm::pointee_iterator< decltype(Modules)::const_iterator > const_iterator
const_iterator end() const
A FeatureModule contributes a vertical feature to clangd.
virtual std::unique_ptr< ASTListener > astListeners()
Can be called asynchronously before building an AST.
const SymbolIndex * index()
The index is used to get information about the whole codebase.
Facilities & facilities()
Accessors for modules to access shared server facilities they depend on.
void initialize(const Facilities &F)
Called by the server to prepare this module for use.
TUScheduler & scheduler()
The scheduler is used to run tasks on worker threads and access ASTs.
llvm::unique_function< void(const P &, Callback< R >)> OutgoingMethod
llvm::unique_function< void(const P &)> OutgoingNotification
Types of function objects that feature modules use for outgoing calls.
const ThreadsafeFS & fs()
The filesystem is used to read source files on disk.
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 initializeLSP(LSPBinder &Bind, const llvm::json::Object &ClientCaps, llvm::json::Object &ServerCaps)
Called by the server to connect this feature module to LSP.
virtual void contributeTweaks(std::vector< std::unique_ptr< Tweak > > &Out)
Tweaks implemented by this module.
Values in a Context are indexed by typed keys.
LSPBinder collects a table of functions that handle LSP calls.
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for open...
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
An interface base for small context-sensitive refactoring actions.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
llvm::Registry< FeatureModule > FeatureModuleRegistry
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
A top-level diagnostic that may have Notes and Fixes.
Extension point that allows modules to observe and modify an AST build.
virtual void sawDiagnostic(const clang::Diagnostic &, clangd::Diag &)
Called everytime a diagnostic is encountered.
virtual ~ASTListener()=default
Listeners are destroyed once the AST is built.
virtual void beforeExecute(CompilerInstance &CI)
Called before every AST build, both for main file and preamble.
virtual void afterExecute(CompilerInstance &CI)
Called after FrontendAction::Execute() for a main-file build, once clangd has collected tokens and re...
virtual void finalizeDiagnostic(clangd::Diag &)
Called after a diagnostic is fully assembled, including notes and fixes, and before it is returned to...
virtual void beforePPCallbacks(CompilerInstance &CI)
Called before every AST build, after the Preprocessor and ASTConsumer are set up, but before clangd i...
Shared server facilities needed by the module to get its work done.
const SymbolIndex * Index