clang-tools  11.0.0
ClangdServer.h
Go to the documentation of this file.
1 //===--- ClangdServer.h - Main clangd server code ----------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
11 
12 #include "../clang-tidy/ClangTidyOptions.h"
13 #include "CodeComplete.h"
14 #include "ConfigProvider.h"
16 #include "Hover.h"
17 #include "Protocol.h"
18 #include "SemanticHighlighting.h"
19 #include "TUScheduler.h"
20 #include "XRefs.h"
21 #include "index/Background.h"
22 #include "index/FileIndex.h"
23 #include "index/Index.h"
24 #include "refactor/Rename.h"
25 #include "refactor/Tweak.h"
26 #include "support/Cancellation.h"
27 #include "support/Function.h"
28 #include "support/ThreadsafeFS.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"
35 #include <functional>
36 #include <future>
37 #include <string>
38 #include <type_traits>
39 #include <utility>
40 
41 namespace clang {
42 namespace clangd {
43 
44 /// When set, used by ClangdServer to get clang-tidy options for each particular
45 /// file. Must be thread-safe. We use this instead of ClangTidyOptionsProvider
46 /// to allow reading tidy configs from the VFS used for parsing.
47 using ClangTidyOptionsBuilder = std::function<tidy::ClangTidyOptions(
48  llvm::vfs::FileSystem &, llvm::StringRef /*File*/)>;
49 
50 /// Manages a collection of source files and derived data (ASTs, indexes),
51 /// and provides language-aware features such as code completion.
52 ///
53 /// The primary client is ClangdLSPServer which exposes these features via
54 /// the Language Server protocol. ClangdServer may also be embedded directly,
55 /// though its API is not stable over time.
56 ///
57 /// ClangdServer should be used from a single thread. Many potentially-slow
58 /// operations have asynchronous APIs and deliver their results on another
59 /// thread.
60 /// Such operations support cancellation: if the caller sets up a cancelable
61 /// context, many operations will notice cancellation and fail early.
62 /// (ClangdLSPServer uses this to implement $/cancelRequest).
63 class ClangdServer {
64 public:
65  /// Interface with hooks for users of ClangdServer to be notified of events.
66  class Callbacks {
67  public:
68  virtual ~Callbacks() = default;
69 
70  /// Called by ClangdServer when \p Diagnostics for \p File are ready.
71  /// May be called concurrently for separate files, not for a single file.
72  virtual void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
73  std::vector<Diag> Diagnostics) {}
74  /// Called whenever the file status is updated.
75  /// May be called concurrently for separate files, not for a single file.
76  virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
77 
78  /// Called by ClangdServer when some \p Highlightings for \p File are ready.
79  /// May be called concurrently for separate files, not for a single file.
80  virtual void
81  onHighlightingsReady(PathRef File, llvm::StringRef Version,
82  std::vector<HighlightingToken> Highlightings) {}
83 
84  /// Called when background indexing tasks are enqueued/started/completed.
85  /// Not called concurrently.
86  virtual void
88  };
89 
90  struct Options {
91  /// To process requests asynchronously, ClangdServer spawns worker threads.
92  /// If this is zero, no threads are spawned. All work is done on the calling
93  /// thread, and callbacks are invoked before "async" functions return.
95 
96  /// AST caching policy. The default is to keep up to 3 ASTs in memory.
98 
99  /// Cached preambles are potentially large. If false, store them on disk.
101  /// Reuse even stale preambles, and rebuild them in the background.
102  /// This improves latency at the cost of accuracy.
103  bool AsyncPreambleBuilds = true;
104 
105  /// If true, ClangdServer builds a dynamic in-memory index for symbols in
106  /// opened files and uses the index to augment code completion results.
108  /// Use a heavier and faster in-memory index implementation.
110  /// If true, ClangdServer automatically indexes files in the current project
111  /// on background threads. The index is stored in the project root.
112  bool BackgroundIndex = false;
113 
114  /// If set, use this index to augment code completion results.
116 
117  /// If set, queried to obtain the configuration to handle each request.
119 
120  /// If set, enable clang-tidy in clangd and use to it get clang-tidy
121  /// configurations for a particular file.
122  /// Clangd supports only a small subset of ClangTidyOptions, these options
123  /// (Checks, CheckOptions) are about which clang-tidy checks will be
124  /// enabled.
126 
127  /// If true, turn on the `-frecovery-ast` clang flag.
128  bool BuildRecoveryAST = true;
129 
130  /// If true, turn on the `-frecovery-ast-type` clang flag.
132 
133  /// Clangd's workspace root. Relevant for "workspace" operations not bound
134  /// to a particular file.
135  /// FIXME: If not set, should use the current working directory.
136  llvm::Optional<std::string> WorkspaceRoot;
137 
138  /// The resource directory is used to find internal headers, overriding
139  /// defaults and -resource-dir compiler flag).
140  /// If None, ClangdServer calls CompilerInvocation::GetResourcePath() to
141  /// obtain the standard resource directory.
142  llvm::Optional<std::string> ResourceDir = llvm::None;
143 
144  /// Time to wait after a new file version before computing diagnostics.
146  /*Min=*/std::chrono::milliseconds(50),
147  /*Max=*/std::chrono::milliseconds(500),
148  /*RebuildRatio=*/1,
149  };
150 
152 
153  /// Clangd will execute compiler drivers matching one of these globs to
154  /// fetch system include path.
155  std::vector<std::string> QueryDriverGlobs;
156 
157  /// Enable notification-based semantic highlighting.
159 
160  /// Enable preview of FoldingRanges feature.
161  bool FoldingRanges = false;
162 
163  /// Returns true if the tweak should be enabled.
164  std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
165  return !T.hidden(); // only enable non-hidden tweaks.
166  };
167 
168  explicit operator TUScheduler::Options() const;
169  };
170  // Sensible default options for use in tests.
171  // Features like indexing must be enabled if desired.
172  static Options optsForTest();
173 
174  /// Creates a new ClangdServer instance.
175  ///
176  /// ClangdServer uses \p CDB to obtain compilation arguments for parsing. Note
177  /// that ClangdServer only obtains compilation arguments once for each newly
178  /// added file (i.e., when processing a first call to addDocument) and reuses
179  /// those arguments for subsequent reparses. However, ClangdServer will check
180  /// if compilation arguments changed on calls to forceReparse().
181  ClangdServer(const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS,
182  const Options &Opts, Callbacks *Callbacks = nullptr);
183 
184  /// Add a \p File to the list of tracked C++ files or update the contents if
185  /// \p File is already tracked. Also schedules parsing of the AST for it on a
186  /// separate thread. When the parsing is complete, DiagConsumer passed in
187  /// constructor will receive onDiagnosticsReady callback.
188  /// Version identifies this snapshot and is propagated to ASTs, preambles,
189  /// diagnostics etc built from it.
190  void addDocument(PathRef File, StringRef Contents,
191  llvm::StringRef Version = "null",
193  bool ForceRebuild = false);
194 
195  /// Remove \p File from list of tracked files, schedule a request to free
196  /// resources associated with it. Pending diagnostics for closed files may not
197  /// be delivered, even if requested with WantDiags::Auto or WantDiags::Yes.
198  /// An empty set of diagnostics will be delivered, with Version = "".
200 
201  /// Run code completion for \p File at \p Pos.
202  /// Request is processed asynchronously.
203  ///
204  /// This method should only be called for currently tracked files. However, it
205  /// is safe to call removeDocument for \p File after this method returns, even
206  /// while returned future is not yet ready.
207  /// A version of `codeComplete` that runs \p Callback on the processing thread
208  /// when codeComplete results become available.
210  const clangd::CodeCompleteOptions &Opts,
212 
213  /// Provide signature help for \p File at \p Pos. This method should only be
214  /// called for tracked files.
216 
217  /// Find declaration/definition locations of symbol at a specified position.
219  Callback<std::vector<LocatedSymbol>> CB);
220 
221  /// Switch to a corresponding source file when given a header file, and vice
222  /// versa.
224  Callback<llvm::Optional<clangd::Path>> CB);
225 
226  /// Get document highlights for a given position.
228  Callback<std::vector<DocumentHighlight>> CB);
229 
230  /// Get code hover for a given position.
232  Callback<llvm::Optional<HoverInfo>> CB);
233 
234  /// Get information about type hierarchy for a given position.
235  void typeHierarchy(PathRef File, Position Pos, int Resolve,
236  TypeHierarchyDirection Direction,
237  Callback<llvm::Optional<TypeHierarchyItem>> CB);
238 
239  /// Resolve type hierarchy item in the given direction.
240  void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve,
241  TypeHierarchyDirection Direction,
242  Callback<llvm::Optional<TypeHierarchyItem>> CB);
243 
244  /// Retrieve the top symbols from the workspace matching a query.
245  void workspaceSymbols(StringRef Query, int Limit,
246  Callback<std::vector<SymbolInformation>> CB);
247 
248  /// Retrieve the symbols within the specified file.
249  void documentSymbols(StringRef File,
250  Callback<std::vector<DocumentSymbol>> CB);
251 
252  /// Retrieve ranges that can be used to fold code within the specified file.
253  void foldingRanges(StringRef File, Callback<std::vector<FoldingRange>> CB);
254 
255  /// Retrieve locations for symbol references.
256  void findReferences(PathRef File, Position Pos, uint32_t Limit,
258 
259  /// Run formatting for \p Rng inside \p File with content \p Code.
260  void formatRange(PathRef File, StringRef Code, Range Rng,
262 
263  /// Run formatting for the whole \p File with content \p Code.
264  void formatFile(PathRef File, StringRef Code,
266 
267  /// Run formatting after \p TriggerText was typed at \p Pos in \p File with
268  /// content \p Code.
269  void formatOnType(PathRef File, StringRef Code, Position Pos,
270  StringRef TriggerText, Callback<std::vector<TextEdit>> CB);
271 
272  /// Test the validity of a rename operation.
274  const RenameOptions &RenameOpts,
275  Callback<llvm::Optional<Range>> CB);
276 
277  /// Rename all occurrences of the symbol at the \p Pos in \p File to
278  /// \p NewName.
279  /// If WantFormat is false, the final TextEdit will be not formatted,
280  /// embedders could use this method to get all occurrences of the symbol (e.g.
281  /// highlighting them in prepare stage).
282  void rename(PathRef File, Position Pos, llvm::StringRef NewName,
283  const RenameOptions &Opts, Callback<FileEdits> CB);
284 
285  struct TweakRef {
286  std::string ID; /// ID to pass for applyTweak.
287  std::string Title; /// A single-line message to show in the UI.
289  };
290  /// Enumerate the code tweaks available to the user at a specified point.
291  void enumerateTweaks(PathRef File, Range Sel,
292  Callback<std::vector<TweakRef>> CB);
293 
294  /// Apply the code tweak with a specified \p ID.
295  void applyTweak(PathRef File, Range Sel, StringRef ID,
297 
298  /// Only for testing purposes.
299  /// Waits until all requests to worker thread are finished and dumps AST for
300  /// \p File. \p File must be in the list of added documents.
301  void dumpAST(PathRef File, llvm::unique_function<void(std::string)> Callback);
302  /// Called when an event occurs for a watched file in the workspace.
303  void onFileEvent(const DidChangeWatchedFilesParams &Params);
304 
305  /// Get symbol info for given position.
306  /// Clangd extension - not part of official LSP.
308  Callback<std::vector<SymbolDetails>> CB);
309 
310  /// Get semantic ranges around a specified position in a file.
311  void semanticRanges(PathRef File, const std::vector<Position> &Pos,
312  Callback<std::vector<SelectionRange>> CB);
313 
314  /// Get all document links in a file.
315  void documentLinks(PathRef File, Callback<std::vector<DocumentLink>> CB);
316 
318  Callback<std::vector<HighlightingToken>>);
319 
320  /// Returns estimated memory usage and other statistics for each of the
321  /// currently open files.
322  /// Overall memory usage of clangd may be significantly more than reported
323  /// here, as this metric does not account (at least) for:
324  /// - memory occupied by static and dynamic index,
325  /// - memory required for in-flight requests,
326  /// FIXME: those metrics might be useful too, we should add them.
327  llvm::StringMap<TUScheduler::FileStats> fileStats() const;
328 
329  // Blocks the main thread until the server is idle. Only for use in tests.
330  // Returns false if the timeout expires.
331  LLVM_NODISCARD bool
332  blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds = 10);
333 
334 private:
335  void formatCode(PathRef File, llvm::StringRef Code,
336  ArrayRef<tooling::Range> Ranges,
338 
339  /// Derives a context for a task processing the specified source file.
340  /// This includes the current configuration (see Options::ConfigProvider).
341  /// The empty string means no particular file is the target.
342  /// Rather than called by each feature, this is exposed to the components
343  /// that control worker threads, like TUScheduler and BackgroundIndex.
344  /// This means it's OK to do some IO here, and it cuts across all features.
345  Context createProcessingContext(PathRef) const;
346  config::Provider *ConfigProvider = nullptr;
347 
348  const ThreadsafeFS &TFS;
349 
350  Path ResourceDir;
351  // The index used to look up symbols. This could be:
352  // - null (all index functionality is optional)
353  // - the dynamic index owned by ClangdServer (DynamicIdx)
354  // - the static index passed to the constructor
355  // - a merged view of a static and dynamic index (MergedIndex)
356  const SymbolIndex *Index = nullptr;
357  // If present, an index of symbols in open files. Read via *Index.
358  std::unique_ptr<FileIndex> DynamicIdx;
359  // If present, the new "auto-index" maintained in background threads.
360  std::unique_ptr<BackgroundIndex> BackgroundIdx;
361  // Storage for merged views of the various indexes.
362  std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
363 
364  // When set, provides clang-tidy options for a specific file.
365  ClangTidyOptionsBuilder GetClangTidyOptions;
366 
367  // If this is true, suggest include insertion fixes for diagnostic errors that
368  // can be caused by missing includes (e.g. member access in incomplete type).
369  bool SuggestMissingIncludes = false;
370 
371  // If true, preserve expressions in AST for broken code.
372  bool BuildRecoveryAST = true;
373  // If true, preserve the type for recovery AST.
374  bool PreserveRecoveryASTType = false;
375 
376  std::function<bool(const Tweak &)> TweakFilter;
377 
378  // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
379  llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
380  CachedCompletionFuzzyFindRequestByFile;
381  mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
382 
383  llvm::Optional<std::string> WorkspaceRoot;
384  // WorkScheduler has to be the last member, because its destructor has to be
385  // called before all other members to stop the worker thread that references
386  // ClangdServer.
387  TUScheduler WorkScheduler;
388 };
389 
390 } // namespace clangd
391 } // namespace clang
392 
393 #endif
clang::clangd::ClangdServer::fileStats
llvm::StringMap< TUScheduler::FileStats > fileStats() const
Returns estimated memory usage and other statistics for each of the currently open files.
Definition: ClangdServer.cpp:757
clang::clangd::BackgroundQueue::Stats
Definition: Background.h:82
XRefs.h
Background.h
clang::clangd::ClangdServer::Options::PreserveRecoveryASTType
bool PreserveRecoveryASTType
If true, turn on the -frecovery-ast-type clang flag.
Definition: ClangdServer.h:131
clang::clangd::ClangdServer::dumpAST
void dumpAST(PathRef File, llvm::unique_function< void(std::string)> Callback)
Only for testing purposes.
Definition: ClangdServer.cpp:528
clang::clangd::getDefaultAsyncThreadsCount
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
Definition: TUScheduler.cpp:1215
CodeComplete.h
clang::clangd::ClangdServer::prepareRename
void prepareRename(PathRef File, Position Pos, const RenameOptions &RenameOpts, Callback< llvm::Optional< Range >> CB)
Test the validity of a rename operation.
Definition: ClangdServer.cpp:351
clang::clangd::ClangdServer::Options::UpdateDebounce
DebouncePolicy UpdateDebounce
Time to wait after a new file version before computing diagnostics.
Definition: ClangdServer.h:145
clang::clangd::Path
std::string Path
A typedef to represent a file path.
Definition: Path.h:20
clang::clangd::ASTRetentionPolicy
Configuration of the AST retention policy.
Definition: TUScheduler.h:58
clang::clangd::ClangdServer::Options::AsyncPreambleBuilds
bool AsyncPreambleBuilds
Reuse even stale preambles, and rebuild them in the background.
Definition: ClangdServer.h:103
clang::clangd::ClangdServer::formatFile
void formatFile(PathRef File, StringRef Code, Callback< tooling::Replacements > CB)
Run formatting for the whole File with content Code.
Definition: ClangdServer.cpp:321
clang::clangd::ClangdServer::Options::HeavyweightDynamicSymbolIndex
bool HeavyweightDynamicSymbolIndex
Use a heavier and faster in-memory index implementation.
Definition: ClangdServer.h:109
clang::clangd::WantDiagnostics::Auto
Diagnostics must not be generated for this snapshot.
Index.h
Contents
llvm::StringRef Contents
Definition: DraftStoreTests.cpp:22
clang::clangd::ClangdServer::switchSourceHeader
void switchSourceHeader(PathRef Path, Callback< llvm::Optional< clangd::Path >> CB)
Switch to a corresponding source file when given a header file, and vice versa.
Definition: ClangdServer.cpp:560
clang::clangd::ClangdServer::findReferences
void findReferences(PathRef File, Position Pos, uint32_t Limit, Callback< ReferencesResult > CB)
Retrieve locations for symbol references.
Definition: ClangdServer.cpp:690
clang::clangd::ClangdServer::Options::ResourceDir
llvm::Optional< std::string > ResourceDir
The resource directory is used to find internal headers, overriding defaults and -resource-dir compil...
Definition: ClangdServer.h:142
ConfigProvider.h
clang::clangd::config::Provider
A source of configuration fragments.
Definition: ConfigProvider.h:60
clang::clangd::ClangdServer::optsForTest
static Options optsForTest()
Definition: ClangdServer.cpp:114
clang::clangd::ClangdServer::Options::StorePreamblesInMemory
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
Definition: ClangdServer.h:100
clang::clangd::ClangdServer
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
Definition: ClangdServer.h:63
clang::clangd::TextDocumentSyncKind::None
Documents should not be synced at all.
clang::clangd::ClangdServer::TweakRef::Intent
Tweak::Intent Intent
A single-line message to show in the UI.
Definition: ClangdServer.h:288
clang::clangd::ClangdServer::Callbacks::onFileUpdated
virtual void onFileUpdated(PathRef File, const TUStatus &Status)
Called whenever the file status is updated.
Definition: ClangdServer.h:76
clang::clangd::ClangdServer::Options::QueryDriverGlobs
std::vector< std::string > QueryDriverGlobs
Clangd will execute compiler drivers matching one of these globs to fetch system include path.
Definition: ClangdServer.h:155
clang::clangd::ClangdServer::rename
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.
Definition: ClangdServer.cpp:391
clang::clangd::GlobalCompilationDatabase
Provides compilation arguments used for parsing C and C++ files.
Definition: GlobalCompilationDatabase.h:35
clang::clangd::ClangdServer::enumerateTweaks
void enumerateTweaks(PathRef File, Range Sel, Callback< std::vector< TweakRef >> CB)
Enumerate the code tweaks available to the user at a specified point.
Definition: ClangdServer.cpp:454
clang::clangd::ClangdServer::documentSymbols
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol >> CB)
Retrieve the symbols within the specified file.
Definition: ClangdServer.cpp:666
clang::clangd::ClangdServer::foldingRanges
void foldingRanges(StringRef File, Callback< std::vector< FoldingRange >> CB)
Retrieve ranges that can be used to fold code within the specified file.
Definition: ClangdServer.cpp:678
clang::clangd::ClangdServer::addDocument
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.
Definition: ClangdServer.cpp:190
Cancellation.h
clang::clangd::ClangdServer::Options::BuildRecoveryAST
bool BuildRecoveryAST
If true, turn on the -frecovery-ast clang flag.
Definition: ClangdServer.h:128
clang::clangd::ClangdServer::formatOnType
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.
Definition: ClangdServer.cpp:327
clang::clangd::WantDiagnostics
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
Definition: TUScheduler.h:48
clang::clangd::ClangdServer::TweakRef::ID
std::string ID
Definition: ClangdServer.h:286
clang::clangd::ClangdServer::Options::SuggestMissingIncludes
bool SuggestMissingIncludes
Definition: ClangdServer.h:151
Protocol.h
ThreadsafeFS.h
Hover.h
clang::clangd::ClangdServer::Options
Definition: ClangdServer.h:90
Rename.h
clang::clangd::Position
Definition: Protocol.h:144
Code
std::string Code
Definition: FindTargetTests.cpp:67
clang::clangd::TUStatus
Definition: TUScheduler.h:108
clang::clangd::ClangdServer::Options::TheiaSemanticHighlighting
bool TheiaSemanticHighlighting
Enable notification-based semantic highlighting.
Definition: ClangdServer.h:158
clang::clangd::ClangdServer::Options::StaticIndex
SymbolIndex * StaticIndex
If set, use this index to augment code completion results.
Definition: ClangdServer.h:115
clang::clangd::ClangdServer::Callbacks::~Callbacks
virtual ~Callbacks()=default
clang::clangd::ClangdServer::removeDocument
void removeDocument(PathRef File)
Remove File from list of tracked files, schedule a request to free resources associated with it.
Definition: ClangdServer.cpp:217
clang::clangd::ClangdServer::codeComplete
void codeComplete(PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts, Callback< CodeCompleteResult > CB)
Run code completion for File at Pos.
Definition: ClangdServer.cpp:219
clang::clangd::ClangdServer::Options::AsyncThreadsCount
unsigned AsyncThreadsCount
To process requests asynchronously, ClangdServer spawns worker threads.
Definition: ClangdServer.h:94
clang::clangd::ClangdServer::TweakRef::Title
std::string Title
ID to pass for applyTweak.
Definition: ClangdServer.h:287
Tweak.h
GlobalCompilationDatabase.h
clang::clangd::DidChangeWatchedFilesParams
Definition: Protocol.h:720
clang::clangd::ClangdServer::onFileEvent
void onFileEvent(const DidChangeWatchedFilesParams &Params)
Called when an event occurs for a watched file in the workspace.
Definition: ClangdServer.cpp:650
clang::clangd::ClangdServer::Callbacks::onHighlightingsReady
virtual void onHighlightingsReady(PathRef File, llvm::StringRef Version, std::vector< HighlightingToken > Highlightings)
Called by ClangdServer when some Highlightings for File are ready.
Definition: ClangdServer.h:81
clang::clangd::ClangdServer::semanticHighlights
void semanticHighlights(PathRef File, Callback< std::vector< HighlightingToken >>)
Definition: ClangdServer.cpp:745
clang::clangd::RenameOptions
Definition: Rename.h:29
clang::clangd::ClangdServer::findDocumentHighlights
void findDocumentHighlights(PathRef File, Position Pos, Callback< std::vector< DocumentHighlight >> CB)
Get document highlights for a given position.
Definition: ClangdServer.cpp:601
clang::clangd::ClangdServer::Options::ConfigProvider
config::Provider * ConfigProvider
If set, queried to obtain the configuration to handle each request.
Definition: ClangdServer.h:118
clang::clangd::Tweak::Intent
Intent
Output of a tweak.
Definition: Tweak.h:71
FileIndex.h
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:44
clang::clangd::ClangdServer::workspaceSymbols
void workspaceSymbols(StringRef Query, int Limit, Callback< std::vector< SymbolInformation >> CB)
Retrieve the top symbols from the workspace matching a query.
Definition: ClangdServer.cpp:655
clang::clangd::ClangdServer::documentLinks
void documentLinks(PathRef File, Callback< std::vector< DocumentLink >> CB)
Get all document links in a file.
Definition: ClangdServer.cpp:733
clang::clangd::CompletionItemKind::File
clang::clangd::ClangdServer::Options::BuildDynamicSymbolIndex
bool BuildDynamicSymbolIndex
If true, ClangdServer builds a dynamic in-memory index for symbols in opened files and uses the index...
Definition: ClangdServer.h:107
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:85
clang::clangd::ClangdServer::signatureHelp
void signatureHelp(PathRef File, Position Pos, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
Definition: ClangdServer.cpp:284
clang::clangd::ClangdServer::locateSymbolAt
void locateSymbolAt(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol >> CB)
Find declaration/definition locations of symbol at a specified position.
Definition: ClangdServer.cpp:548
clang::clangd::TypeHierarchyDirection
TypeHierarchyDirection
Definition: Protocol.h:1270
clang::clangd::TypeHierarchyItem
Definition: Protocol.h:1285
clang::clangd::ClangdServer::Callbacks::onBackgroundIndexProgress
virtual void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats)
Called when background indexing tasks are enqueued/started/completed.
Definition: ClangdServer.h:87
clang::clangd::ClangdServer::Callbacks
Interface with hooks for users of ClangdServer to be notified of events.
Definition: ClangdServer.h:66
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:23
clang::clangd::ClangdServer::Options::GetClangTidyOptions
ClangTidyOptionsBuilder GetClangTidyOptions
If set, enable clang-tidy in clangd and use to it get clang-tidy configurations for a particular file...
Definition: ClangdServer.h:125
clang::clangd::ThreadsafeFS
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
Definition: ThreadsafeFS.h:28
RenameOpts
RenameOptions RenameOpts
Definition: ClangdLSPServerTests.cpp:68
clang::clangd::ClangdServer::TweakRef
Definition: ClangdServer.h:285
clang::clangd::TUScheduler::Options
Definition: TUScheduler.h:178
clang::clangd::ClangdServer::applyTweak
void applyTweak(PathRef File, Range Sel, StringRef ID, Callback< Tweak::Effect > CB)
Apply the code tweak with a specified ID.
Definition: ClangdServer.cpp:487
clang::clangd::Range
Definition: Protocol.h:173
SemanticHighlighting.h
clang::clangd::DebouncePolicy
Clangd may wait after an update to see if another one comes along.
Definition: TUScheduler.h:69
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::ClangdServer::symbolInfo
void symbolInfo(PathRef File, Position Pos, Callback< std::vector< SymbolDetails >> CB)
Get symbol info for given position.
Definition: ClangdServer.cpp:702
Function.h
clang::clangd::ClangTidyOptionsBuilder
std::function< tidy::ClangTidyOptions(llvm::vfs::FileSystem &, llvm::StringRef)> ClangTidyOptionsBuilder
When set, used by ClangdServer to get clang-tidy options for each particular file.
Definition: ClangdServer.h:48
TUScheduler.h
clang::clangd::Tweak
An interface base for small context-sensitive refactoring actions.
Definition: Tweak.h:46
clang::clangd::ClangdServer::Options::RetentionPolicy
ASTRetentionPolicy RetentionPolicy
AST caching policy. The default is to keep up to 3 ASTs in memory.
Definition: ClangdServer.h:97
clang::clangd::ClangdServer::semanticRanges
void semanticRanges(PathRef File, const std::vector< Position > &Pos, Callback< std::vector< SelectionRange >> CB)
Get semantic ranges around a specified position in a file.
Definition: ClangdServer.cpp:714
clang::clangd::ClangdServer::resolveTypeHierarchy
void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction, Callback< llvm::Optional< TypeHierarchyItem >> CB)
Resolve type hierarchy item in the given direction.
Definition: ClangdServer.cpp:643
clang::clangd::ClangdServer::findHover
void findHover(PathRef File, Position Pos, Callback< llvm::Optional< HoverInfo >> CB)
Get code hover for a given position.
Definition: ClangdServer.cpp:614
clang::clangd::TUScheduler
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for open...
Definition: TUScheduler.h:176
clang::clangd::Callback
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
Definition: Function.h:28
clang::clangd::ClangdServer::Options::FoldingRanges
bool FoldingRanges
Enable preview of FoldingRanges feature.
Definition: ClangdServer.h:161
clang::clangd::ClangdServer::formatRange
void formatRange(PathRef File, StringRef Code, Range Rng, Callback< tooling::Replacements > CB)
Run formatting for Rng inside File with content Code.
Definition: ClangdServer.cpp:309
Pos
Position Pos
Definition: SourceCode.cpp:649
clang::clangd::BackgroundIndex
Definition: Background.h:129
clang::clangd::ClangdServer::Callbacks::onDiagnosticsReady
virtual void onDiagnosticsReady(PathRef File, llvm::StringRef Version, std::vector< Diag > Diagnostics)
Called by ClangdServer when Diagnostics for File are ready.
Definition: ClangdServer.h:72
clang::clangd::ClangdServer::ClangdServer
ClangdServer(const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS, const Options &Opts, Callbacks *Callbacks=nullptr)
Creates a new ClangdServer instance.
Definition: ClangdServer.cpp:134
clang::clangd::Context
A context is an immutable container for per-request data that must be propagated through layers that ...
Definition: Context.h:69
clang::clangd::ClangdServer::Options::TweakFilter
std::function< bool(const Tweak &)> TweakFilter
Returns true if the tweak should be enabled.
Definition: ClangdServer.h:164
clang::clangd::ClangdServer::typeHierarchy
void typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Callback< llvm::Optional< TypeHierarchyItem >> CB)
Get information about type hierarchy for a given position.
Definition: ClangdServer.cpp:629
clang::clangd::ClangdServer::Options::WorkspaceRoot
llvm::Optional< std::string > WorkspaceRoot
Clangd's workspace root.
Definition: ClangdServer.h:136
clang::clangd::ClangdServer::blockUntilIdleForTest
LLVM_NODISCARD bool blockUntilIdleForTest(llvm::Optional< double > TimeoutSeconds=10)
Definition: ClangdServer.cpp:790