Go to the documentation of this file.
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
12 #include "../clang-tidy/ClangTidyOptions.h"
29 #include "clang/Tooling/CompilationDatabase.h"
30 #include "clang/Tooling/Core/Replacement.h"
31 #include "llvm/ADT/FunctionExtras.h"
32 #include "llvm/ADT/IntrusiveRefCntPtr.h"
33 #include "llvm/ADT/Optional.h"
34 #include "llvm/ADT/StringRef.h"
38 #include <type_traits>
48 llvm::vfs::FileSystem &, llvm::StringRef )>;
73 std::vector<Diag> Diagnostics) {}
82 std::vector<HighlightingToken> Highlightings) {}
146 std::chrono::milliseconds(50),
147 std::chrono::milliseconds(500),
182 const Options &Opts, Callbacks *Callbacks =
nullptr);
191 llvm::StringRef Version =
"null",
193 bool ForceRebuild =
false);
219 Callback<std::vector<LocatedSymbol>> CB);
224 Callback<llvm::Optional<clangd::Path>> CB);
228 Callback<std::vector<DocumentHighlight>> CB);
232 Callback<llvm::Optional<HoverInfo>> CB);
237 Callback<llvm::Optional<TypeHierarchyItem>> CB);
242 Callback<llvm::Optional<TypeHierarchyItem>> CB);
246 Callback<std::vector<SymbolInformation>> CB);
250 Callback<std::vector<DocumentSymbol>> CB);
270 StringRef TriggerText,
Callback<std::vector<TextEdit>> CB);
275 Callback<llvm::Optional<Range>> CB);
292 Callback<std::vector<TweakRef>> CB);
308 Callback<std::vector<SymbolDetails>> CB);
312 Callback<std::vector<SelectionRange>> CB);
318 Callback<std::vector<HighlightingToken>>);
327 llvm::StringMap<TUScheduler::FileStats>
fileStats()
const;
336 ArrayRef<tooling::Range> Ranges,
358 std::unique_ptr<FileIndex> DynamicIdx;
360 std::unique_ptr<BackgroundIndex> BackgroundIdx;
362 std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
369 bool SuggestMissingIncludes =
false;
372 bool BuildRecoveryAST =
true;
374 bool PreserveRecoveryASTType =
false;
376 std::function<bool(
const Tweak &)> TweakFilter;
379 llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
380 CachedCompletionFuzzyFindRequestByFile;
381 mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
383 llvm::Optional<std::string> WorkspaceRoot;
llvm::StringMap< TUScheduler::FileStats > fileStats() const
Returns estimated memory usage and other statistics for each of the currently open files.
bool PreserveRecoveryASTType
If true, turn on the -frecovery-ast-type clang flag.
void dumpAST(PathRef File, llvm::unique_function< void(std::string)> Callback)
Only for testing purposes.
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
void prepareRename(PathRef File, Position Pos, const RenameOptions &RenameOpts, Callback< llvm::Optional< Range >> CB)
Test the validity of a rename operation.
DebouncePolicy UpdateDebounce
Time to wait after a new file version before computing diagnostics.
std::string Path
A typedef to represent a file path.
Configuration of the AST retention policy.
bool AsyncPreambleBuilds
Reuse even stale preambles, and rebuild them in the background.
void formatFile(PathRef File, StringRef Code, Callback< tooling::Replacements > CB)
Run formatting for the whole File with content Code.
bool HeavyweightDynamicSymbolIndex
Use a heavier and faster in-memory index implementation.
Diagnostics must not be generated for this snapshot.
void switchSourceHeader(PathRef Path, Callback< llvm::Optional< clangd::Path >> CB)
Switch to a corresponding source file when given a header file, and vice versa.
void findReferences(PathRef File, Position Pos, uint32_t Limit, Callback< ReferencesResult > CB)
Retrieve locations for symbol references.
llvm::Optional< std::string > ResourceDir
The resource directory is used to find internal headers, overriding defaults and -resource-dir compil...
A source of configuration fragments.
static Options optsForTest()
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
Documents should not be synced at all.
Tweak::Intent Intent
A single-line message to show in the UI.
virtual void onFileUpdated(PathRef File, const TUStatus &Status)
Called whenever the file status is updated.
std::vector< std::string > QueryDriverGlobs
Clangd will execute compiler drivers matching one of these globs to fetch system include path.
void rename(PathRef File, Position Pos, llvm::StringRef NewName, const RenameOptions &Opts, Callback< FileEdits > CB)
Rename all occurrences of the symbol at the Pos in File to NewName.
Provides compilation arguments used for parsing C and C++ files.
void enumerateTweaks(PathRef File, Range Sel, Callback< std::vector< TweakRef >> CB)
Enumerate the code tweaks available to the user at a specified point.
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol >> CB)
Retrieve the symbols within the specified file.
void foldingRanges(StringRef File, Callback< std::vector< FoldingRange >> CB)
Retrieve ranges that can be used to fold code within the specified file.
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.
bool BuildRecoveryAST
If true, turn on the -frecovery-ast clang flag.
void formatOnType(PathRef File, StringRef Code, Position Pos, StringRef TriggerText, Callback< std::vector< TextEdit >> CB)
Run formatting after TriggerText was typed at Pos in File with content Code.
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
bool SuggestMissingIncludes
bool TheiaSemanticHighlighting
Enable notification-based semantic highlighting.
SymbolIndex * StaticIndex
If set, use this index to augment code completion results.
virtual ~Callbacks()=default
void removeDocument(PathRef File)
Remove File from list of tracked files, schedule a request to free resources associated with it.
void codeComplete(PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts, Callback< CodeCompleteResult > CB)
Run code completion for File at Pos.
unsigned AsyncThreadsCount
To process requests asynchronously, ClangdServer spawns worker threads.
std::string Title
ID to pass for applyTweak.
void onFileEvent(const DidChangeWatchedFilesParams &Params)
Called when an event occurs for a watched file in the workspace.
virtual void onHighlightingsReady(PathRef File, llvm::StringRef Version, std::vector< HighlightingToken > Highlightings)
Called by ClangdServer when some Highlightings for File are ready.
void semanticHighlights(PathRef File, Callback< std::vector< HighlightingToken >>)
void findDocumentHighlights(PathRef File, Position Pos, Callback< std::vector< DocumentHighlight >> CB)
Get document highlights for a given position.
config::Provider * ConfigProvider
If set, queried to obtain the configuration to handle each request.
void workspaceSymbols(StringRef Query, int Limit, Callback< std::vector< SymbolInformation >> CB)
Retrieve the top symbols from the workspace matching a query.
void documentLinks(PathRef File, Callback< std::vector< DocumentLink >> CB)
Get all document links in a file.
bool BuildDynamicSymbolIndex
If true, ClangdServer builds a dynamic in-memory index for symbols in opened files and uses the index...
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
void signatureHelp(PathRef File, Position Pos, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
void locateSymbolAt(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol >> CB)
Find declaration/definition locations of symbol at a specified position.
virtual void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats)
Called when background indexing tasks are enqueued/started/completed.
Interface with hooks for users of ClangdServer to be notified of events.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
ClangTidyOptionsBuilder GetClangTidyOptions
If set, enable clang-tidy in clangd and use to it get clang-tidy configurations for a particular file...
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
void applyTweak(PathRef File, Range Sel, StringRef ID, Callback< Tweak::Effect > CB)
Apply the code tweak with a specified ID.
Clangd may wait after an update to see if another one comes along.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void symbolInfo(PathRef File, Position Pos, Callback< std::vector< SymbolDetails >> CB)
Get symbol info for given position.
std::function< tidy::ClangTidyOptions(llvm::vfs::FileSystem &, llvm::StringRef)> ClangTidyOptionsBuilder
When set, used by ClangdServer to get clang-tidy options for each particular file.
An interface base for small context-sensitive refactoring actions.
ASTRetentionPolicy RetentionPolicy
AST caching policy. The default is to keep up to 3 ASTs in memory.
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 resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction, Callback< llvm::Optional< TypeHierarchyItem >> CB)
Resolve type hierarchy item in the given direction.
void findHover(PathRef File, Position Pos, Callback< llvm::Optional< HoverInfo >> CB)
Get code hover for a given position.
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for open...
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
bool FoldingRanges
Enable preview of FoldingRanges feature.
void formatRange(PathRef File, StringRef Code, Range Rng, Callback< tooling::Replacements > CB)
Run formatting for Rng inside File with content Code.
virtual void onDiagnosticsReady(PathRef File, llvm::StringRef Version, std::vector< Diag > Diagnostics)
Called by ClangdServer when Diagnostics for File are ready.
ClangdServer(const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS, const Options &Opts, Callbacks *Callbacks=nullptr)
Creates a new ClangdServer instance.
A context is an immutable container for per-request data that must be propagated through layers that ...
std::function< bool(const Tweak &)> TweakFilter
Returns true if the tweak should be enabled.
void typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Callback< llvm::Optional< TypeHierarchyItem >> CB)
Get information about type hierarchy for a given position.
llvm::Optional< std::string > WorkspaceRoot
Clangd's workspace root.
LLVM_NODISCARD bool blockUntilIdleForTest(llvm::Optional< double > TimeoutSeconds=10)