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"
24class CompilerInstance;
72 const llvm::json::Object &ClientCaps,
73 llvm::json::Object &ServerCaps) {}
121 virtual std::unique_ptr<ASTListener>
astListeners() {
return nullptr; }
135 template <
typename P>
137 template <
typename P,
typename R>
141 std::optional<Facilities> Fac;
152 std::vector<std::unique_ptr<FeatureModule>> Modules;
153 llvm::DenseMap<void *, FeatureModule *> Map;
155 template <
typename Mod>
struct ID {
156 static_assert(std::is_base_of<FeatureModule, Mod>::value &&
157 std::is_final<Mod>::value,
158 "Modules must be final classes derived from clangd::Module");
162 bool addImpl(
void *
Key, std::unique_ptr<FeatureModule>,
const char *Source);
175 template <
typename Mod>
bool add(std::unique_ptr<Mod>
M) {
176 return addImpl(&ID<Mod>::Key, std::move(
M), LLVM_PRETTY_FUNCTION);
178 template <
typename Mod> Mod *
get() {
179 return static_cast<Mod *
>(Map.lookup(&ID<Mod>::Key));
181 template <
typename Mod>
const Mod *
get()
const {
186template <
typename Mod>
int FeatureModuleSet::ID<Mod>::Key;
CompiledFragmentImpl & Out
const google::protobuf::Message & M
std::unique_ptr< CompilerInvocation > CI
A point in time we can wait for.
static Deadline infinity()
A FeatureModuleSet is a collection of feature modules installed in clangd.
llvm::pointee_iterator< decltype(Modules)::iterator > iterator
bool add(std::unique_ptr< Mod > M)
llvm::pointee_iterator< decltype(Modules)::const_iterator > const_iterator
FeatureModuleSet()=default
const_iterator begin() const
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.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
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.
Shared server facilities needed by the module to get its work done.
const SymbolIndex * Index