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"
92 std::vector<Range> InactiveRegions) {}
159 std::chrono::milliseconds(50),
160 std::chrono::milliseconds(500),
212 return FeatureModules ? FeatureModules->
get<Mod>() :
nullptr;
215 return FeatureModules ? FeatureModules->
get<Mod>() :
nullptr;
225 llvm::StringRef Version =
"null",
227 bool ForceRebuild =
false);
240 llvm::function_ref<
bool(llvm::StringRef
File)> Filter);
256 Callback<std::vector<LocatedSymbol>> CB);
261 Callback<std::optional<clangd::Path>> CB);
265 Callback<std::vector<DocumentHighlight>> CB);
269 Callback<std::optional<HoverInfo>> CB);
274 Callback<std::vector<TypeHierarchyItem>> CB);
277 Callback<std::optional<std::vector<TypeHierarchyItem>>> CB);
280 Callback<std::vector<TypeHierarchyItem>> CB);
285 Callback<std::optional<TypeHierarchyItem>> CB);
289 Callback<std::vector<CallHierarchyItem>> CB);
293 Callback<std::vector<CallHierarchyIncomingCall>>);
301 Callback<std::vector<SymbolInformation>> CB);
305 Callback<std::vector<DocumentSymbol>> CB);
312 Callback<std::vector<LocatedSymbol>> CB);
316 Callback<std::vector<LocatedSymbol>> CB);
330 Callback<std::vector<TextEdit>> CB);
336 std::optional<std::string> NewName,
409 Callback<std::vector<SymbolDetails>> CB);
413 Callback<std::vector<SelectionRange>> CB);
419 Callback<std::vector<HighlightingToken>>);
423 Callback<std::optional<ASTNode>> CB);
447 llvm::StringMap<TUScheduler::FileStats>
fileStats()
const;
467 return UseDirtyHeaders ? *DirtyFS : TFS;
479 std::unique_ptr<FileIndex> DynamicIdx;
481 std::unique_ptr<BackgroundIndex> BackgroundIdx;
483 std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
490 bool UseDirtyHeaders =
false;
493 bool LineFoldingOnly =
false;
495 bool PreambleParseForwardingFunctions =
false;
497 bool ImportInsertions =
false;
499 bool PublishInactiveRegions =
false;
502 llvm::StringMap<std::optional<FuzzyFindRequest>>
503 CachedCompletionFuzzyFindRequestByFile;
504 mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
506 std::optional<std::string> WorkspaceRoot;
507 std::optional<AsyncTaskRunner> IndexTasks;
508 std::optional<TUScheduler> WorkScheduler;
516 std::unique_ptr<ThreadsafeFS> DirtyFS;
llvm::SmallString< 256U > Name
WantDiagnostics Diagnostics
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.
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
llvm::StringMap< TUScheduler::FileStats > fileStats() const
Returns estimated memory usage and other statistics for each of the currently open files.
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 formatFile(PathRef File, std::optional< Range > Rng, Callback< tooling::Replacements > CB)
Run formatting for the File with content Code.
void removeDocument(PathRef File)
Remove File from list of tracked files, schedule a request to free resources associated with it.
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 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.
llvm::function_ref< void(tidy::ClangTidyOptions &, llvm::StringRef)> TidyProviderRef
A factory to modify a tidy::ClangTidyOptions that doesn't hold any state.
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
std::string Path
A typedef to represent a file path.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
@ Auto
Diagnostics must not be generated for this snapshot.
llvm::StringRef PathRef
A typedef to represent a ref to 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.
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
TidyProviderRef ClangTidyProvider
The Options provider to use when running clang-tidy.
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
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
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...