9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
33#include "clang/Tooling/Core/Replacement.h"
34#include "llvm/ADT/ArrayRef.h"
35#include "llvm/ADT/FunctionExtras.h"
36#include "llvm/ADT/StringRef.h"
71 llvm::ArrayRef<Diag> Diagnostics) {}
92 std::vector<Range> InactiveRegions) {}
164 std::chrono::milliseconds(50),
165 std::chrono::milliseconds(500),
217 return FeatureModules ? FeatureModules->get<Mod>() :
nullptr;
220 return FeatureModules ? FeatureModules->get<Mod>() :
nullptr;
230 llvm::StringRef Version =
"null",
232 bool ForceRebuild =
false);
245 llvm::function_ref<
bool(llvm::StringRef
File)> Filter);
261 Callback<std::vector<LocatedSymbol>> CB);
266 Callback<std::optional<clangd::Path>> CB);
270 Callback<std::vector<DocumentHighlight>> CB);
274 Callback<std::optional<HoverInfo>> CB);
279 Callback<std::vector<TypeHierarchyItem>> CB);
282 Callback<std::optional<std::vector<TypeHierarchyItem>>> CB);
285 Callback<std::vector<TypeHierarchyItem>> CB);
290 Callback<std::optional<TypeHierarchyItem>> CB);
294 Callback<std::vector<CallHierarchyItem>> CB);
298 Callback<std::vector<CallHierarchyIncomingCall>>);
302 Callback<std::vector<CallHierarchyOutgoingCall>>);
310 Callback<std::vector<SymbolInformation>> CB);
314 Callback<std::vector<DocumentSymbol>> CB);
321 Callback<std::vector<LocatedSymbol>> CB);
325 Callback<std::vector<LocatedSymbol>> CB);
339 Callback<std::vector<TextEdit>> CB);
345 std::optional<std::string> NewName,
418 Callback<std::vector<SymbolDetails>> CB);
422 Callback<std::vector<SelectionRange>> CB);
428 Callback<std::vector<HighlightingToken>>);
432 Callback<std::optional<ASTNode>> CB);
456 llvm::StringMap<TUScheduler::FileStats>
fileStats()
const;
476 return UseDirtyHeaders ? *DirtyFS : TFS;
488 std::unique_ptr<FileIndex> DynamicIdx;
490 std::unique_ptr<BackgroundIndex> BackgroundIdx;
492 std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
499 bool UseDirtyHeaders =
false;
502 bool LineFoldingOnly =
false;
504 bool PreambleParseForwardingFunctions =
true;
506 bool ImportInsertions =
false;
508 bool PublishInactiveRegions =
false;
511 llvm::StringMap<std::optional<FuzzyFindRequest>>
512 CachedCompletionFuzzyFindRequestByFile;
513 mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
515 std::optional<std::string> WorkspaceRoot;
516 std::optional<AsyncTaskRunner> IndexTasks;
517 std::optional<TUScheduler> WorkScheduler;
525 std::unique_ptr<ThreadsafeFS> DirtyFS;
Interface with hooks for users of ClangdServer to be notified of events.
virtual ~Callbacks()=default
virtual void onFileUpdated(PathRef File, const TUStatus &Status)
Called whenever the file status is updated.
virtual void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats)
Called when background indexing tasks are enqueued/started/completed.
virtual void onInactiveRegionsReady(PathRef File, std::vector< Range > InactiveRegions)
Called by ClangdServer when some InactiveRegions for File are ready.
virtual void onSemanticsMaybeChanged(PathRef File)
Called when the meaning of a source code may have changed without an edit.
virtual void onDiagnosticsReady(PathRef File, llvm::StringRef Version, llvm::ArrayRef< Diag > Diagnostics)
Called by ClangdServer when Diagnostics for File are ready.
llvm::StringMap< TUScheduler::FileStats > fileStats() const
Returns estimated memory usage and other statistics for each of the currently open files.
ClangdServer(const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS, const Options &Opts, Callbacks *Callbacks=nullptr)
Creates a new ClangdServer instance.
void prepareRename(PathRef File, Position Pos, std::optional< std::string > NewName, const RenameOptions &RenameOpts, Callback< RenameResult > CB)
Test the validity of a rename operation.
void prepareCallHierarchy(PathRef File, Position Pos, Callback< std::vector< CallHierarchyItem > > CB)
Get information about call hierarchy for a given position.
void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction, Callback< std::optional< TypeHierarchyItem > > CB)
Resolve type hierarchy item in the given direction.
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol > > CB)
Retrieve the symbols within the specified file.
void workspaceSymbols(StringRef Query, int Limit, Callback< std::vector< SymbolInformation > > CB)
Retrieve the top symbols from the workspace matching a query.
void diagnostics(PathRef File, Callback< std::vector< Diag > > CB)
Fetches diagnostics for current version of the File.
void typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Callback< std::vector< TypeHierarchyItem > > CB)
Get information about type hierarchy for a given position.
void removeDocument(PathRef File)
Remove File from list of tracked files, schedule a request to free resources associated with it.
void outgoingCalls(const CallHierarchyItem &Item, Callback< std::vector< CallHierarchyOutgoingCall > >)
Resolve outgoing calls for a given call hierarchy item.
void addDocument(PathRef File, StringRef Contents, llvm::StringRef Version="null", WantDiagnostics WD=WantDiagnostics::Auto, bool ForceRebuild=false)
Add a File to the list of tracked C++ files or update the contents if File is already tracked.
void findDocumentHighlights(PathRef File, Position Pos, Callback< std::vector< DocumentHighlight > > CB)
Get document highlights for a given position.
Mod * featureModule()
Gets the installed feature module of a given type, if any.
static std::function< Context(PathRef)> createConfiguredContextProvider(const config::Provider *Provider, ClangdServer::Callbacks *)
Creates a context provider that loads and installs config.
void signatureHelp(PathRef File, Position Pos, MarkupKind DocumentationFormat, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
void findReferences(PathRef File, Position Pos, uint32_t Limit, bool AddContainer, Callback< ReferencesResult > CB)
Retrieve locations for symbol references.
void switchSourceHeader(PathRef Path, Callback< std::optional< clangd::Path > > CB)
Switch to a corresponding source file when given a header file, and vice versa.
void findType(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol > > CB)
Retrieve symbols for types referenced at Pos.
void findImplementations(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol > > CB)
Retrieve implementations for virtual method.
static Options optsForTest()
void subTypes(const TypeHierarchyItem &Item, Callback< std::vector< TypeHierarchyItem > > CB)
Get direct children of a type hierarchy item.
void semanticRanges(PathRef File, const std::vector< Position > &Pos, Callback< std::vector< SelectionRange > > CB)
Get semantic ranges around a specified position in a file.
void formatFile(PathRef File, const std::vector< Range > &Rngs, Callback< tooling::Replacements > CB)
Run formatting for the File with content Code.
void applyTweak(PathRef File, Range Sel, StringRef ID, Callback< Tweak::Effect > CB)
Apply the code tweak with a specified ID.
void semanticHighlights(PathRef File, Callback< std::vector< HighlightingToken > >)
const Mod * featureModule() const
void getAST(PathRef File, std::optional< Range > R, Callback< std::optional< ASTNode > > CB)
Describe the AST subtree for a piece of code.
void symbolInfo(PathRef File, Position Pos, Callback< std::vector< SymbolDetails > > CB)
Get symbol info for given position.
void onFileEvent(const DidChangeWatchedFilesParams &Params)
Called when an event occurs for a watched file in the workspace.
void superTypes(const TypeHierarchyItem &Item, Callback< std::optional< std::vector< TypeHierarchyItem > > > CB)
Get direct parents of a type hierarchy item.
void profile(MemoryTree &MT) const
Builds a nested representation of memory used by components.
void findHover(PathRef File, Position Pos, Callback< std::optional< HoverInfo > > CB)
Get code hover for a given position.
void formatOnType(PathRef File, Position Pos, StringRef TriggerText, Callback< std::vector< TextEdit > > CB)
Run formatting after TriggerText was typed at Pos in File with content Code.
void rename(PathRef File, Position Pos, llvm::StringRef NewName, const RenameOptions &Opts, Callback< RenameResult > CB)
Rename all occurrences of the symbol at the Pos in File to NewName.
void customAction(PathRef File, llvm::StringRef Name, Callback< InputsAndAST > Action)
Runs an arbitrary action that has access to the AST of the specified file.
void codeAction(const CodeActionInputs &Inputs, Callback< CodeActionResult > CB)
Surface code actions (quick-fixes for diagnostics, or available code tweaks) for a given range in a f...
void locateSymbolAt(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol > > CB)
Find declaration/definition locations of symbol at a specified position.
void incomingCalls(const CallHierarchyItem &Item, Callback< std::vector< CallHierarchyIncomingCall > >)
Resolve incoming calls for a given call hierarchy item.
bool blockUntilIdleForTest(std::optional< double > TimeoutSeconds=10)
void inlayHints(PathRef File, std::optional< Range > RestrictRange, Callback< std::vector< InlayHint > >)
Resolve inlay hints for a given document.
void codeComplete(PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts, Callback< CodeCompleteResult > CB)
Run code completion for File at Pos.
void reparseOpenFilesIfNeeded(llvm::function_ref< bool(llvm::StringRef File)> Filter)
Requests a reparse of currently opened files using their latest source.
void foldingRanges(StringRef File, Callback< std::vector< FoldingRange > > CB)
Retrieve ranges that can be used to fold code within the specified file.
void documentLinks(PathRef File, Callback< std::vector< DocumentLink > > CB)
Get all document links in a file.
std::shared_ptr< const std::string > getDraft(PathRef File) const
Gets the contents of a currently tracked file.
A context is an immutable container for per-request data that must be propagated through layers that ...
A thread-safe container for files opened in a workspace, addressed by filenames.
A FeatureModuleSet is a collection of feature modules installed in clangd.
Provides compilation arguments used for parsing C and C++ files.
This class handles building module files for a given source file.
PreambleThrottler controls which preambles can build at any given time.
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
ASTActionInvalidation
Defines how a runWithAST action is implicitly cancelled by other actions.
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
An interface base for small context-sensitive refactoring actions.
A source of configuration fragments.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
llvm::function_ref< void(tidy::ClangTidyOptions &, llvm::StringRef)> TidyProviderRef
A factory to modify a tidy::ClangTidyOptions that doesn't hold any state.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
@ Auto
Diagnostics must not be generated for this snapshot.
std::string Path
A typedef to represent a file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Configuration of the AST retention policy.
Represents programming constructs like functions or constructors in the context of call hierarchy.
std::vector< TweakRef > TweakRefs
std::vector< Rename > Renames
std::vector< QuickFix > QuickFixes
bool operator<(const DiagRef &Other) const
bool operator==(const DiagRef &Other) const
bool BuildDynamicSymbolIndex
If true, ClangdServer builds a dynamic in-memory index for symbols in opened files and uses the index...
std::function< Context(PathRef)> ContextProvider
If set, queried to derive a processing context for some work.
std::vector< std::string > QueryDriverGlobs
Clangd will execute compiler drivers matching one of these globs to fetch system include path.
bool UseDirtyHeaders
If true, use the dirty buffer contents when building Preambles.
clangd::PreambleThrottler * PreambleThrottler
This throttler controls which preambles may be built at a given time.
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
TidyProviderRef ClangTidyProvider
The Options provider to use when running clang-tidy.
operator TUScheduler::Options() const
bool PreambleParseForwardingFunctions
SymbolIndex * StaticIndex
If set, use this index to augment code completion results.
std::optional< std::string > WorkspaceRoot
Clangd's workspace root.
bool PublishInactiveRegions
Whether to collect and publish information about inactive preprocessor regions in the document.
llvm::ThreadPriority BackgroundIndexPriority
bool BackgroundIndex
If true, ClangdServer automatically indexes files in the current project on background threads.
ASTRetentionPolicy RetentionPolicy
AST caching policy. The default is to keep up to 3 ASTs in memory.
unsigned AsyncThreadsCount
To process requests asynchronously, ClangdServer spawns worker threads.
bool ImportInsertions
Whether include fixer insertions for Objective-C code should use import instead of include.
DebouncePolicy UpdateDebounce
Time to wait after a new file version before computing diagnostics.
std::optional< std::string > ResourceDir
The resource directory is used to find internal headers, overriding defaults and -resource-dir compil...
FeatureModuleSet * FeatureModules
bool EnableOutgoingCalls
Call hierarchy's outgoing calls feature requires additional index serving structures which increase m...
ModulesBuilder * ModulesManager
Manages to build module files.
bool ImplicitCancellation
Cancel certain requests if the file changes before they begin running.
llvm::StringLiteral Kind
A single-line message to show in the UI.
std::string Title
ID to pass for applyTweak.
Clangd may wait after an update to see if another one comes along.
Represents a single fix-it that editor can apply to fix the error.
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...