clang-tools  14.0.0git
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"
15 #include "Diagnostics.h"
16 #include "DraftStore.h"
17 #include "FeatureModule.h"
19 #include "Hover.h"
20 #include "Protocol.h"
21 #include "SemanticHighlighting.h"
22 #include "TUScheduler.h"
23 #include "XRefs.h"
24 #include "index/Background.h"
25 #include "index/FileIndex.h"
26 #include "index/Index.h"
27 #include "refactor/Rename.h"
28 #include "refactor/Tweak.h"
29 #include "support/Cancellation.h"
30 #include "support/Function.h"
31 #include "support/MemoryTree.h"
32 #include "support/Path.h"
33 #include "support/ThreadsafeFS.h"
34 #include "clang/Tooling/CompilationDatabase.h"
35 #include "clang/Tooling/Core/Replacement.h"
36 #include "llvm/ADT/FunctionExtras.h"
37 #include "llvm/ADT/IntrusiveRefCntPtr.h"
38 #include "llvm/ADT/Optional.h"
39 #include "llvm/ADT/StringRef.h"
40 #include <functional>
41 #include <memory>
42 #include <string>
43 #include <type_traits>
44 #include <utility>
45 #include <vector>
46 
47 namespace clang {
48 namespace clangd {
49 /// Manages a collection of source files and derived data (ASTs, indexes),
50 /// and provides language-aware features such as code completion.
51 ///
52 /// The primary client is ClangdLSPServer which exposes these features via
53 /// the Language Server protocol. ClangdServer may also be embedded directly,
54 /// though its API is not stable over time.
55 ///
56 /// ClangdServer should be used from a single thread. Many potentially-slow
57 /// operations have asynchronous APIs and deliver their results on another
58 /// thread.
59 /// Such operations support cancellation: if the caller sets up a cancelable
60 /// context, many operations will notice cancellation and fail early.
61 /// (ClangdLSPServer uses this to implement $/cancelRequest).
62 class ClangdServer {
63 public:
64  /// Interface with hooks for users of ClangdServer to be notified of events.
65  class Callbacks {
66  public:
67  virtual ~Callbacks() = default;
68 
69  /// Called by ClangdServer when \p Diagnostics for \p File are ready.
70  /// These pushed diagnostics might correspond to an older version of the
71  /// file, they do not interfere with "pull-based" ClangdServer::diagnostics.
72  /// May be called concurrently for separate files, not for a single file.
73  virtual void onDiagnosticsReady(PathRef File, llvm::StringRef Version,
74  std::vector<Diag> Diagnostics) {}
75  /// Called whenever the file status is updated.
76  /// May be called concurrently for separate files, not for a single file.
77  virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
78 
79  /// Called when background indexing tasks are enqueued/started/completed.
80  /// Not called concurrently.
81  virtual void
83 
84  /// Called when the meaning of a source code may have changed without an
85  /// edit. Usually clients assume that responses to requests are valid until
86  /// they next edit the file. If they're invalidated at other times, we
87  /// should tell the client. In particular, when an asynchronous preamble
88  /// build finishes, we can provide more accurate semantic tokens, so we
89  /// should tell the client to refresh.
90  virtual void onSemanticsMaybeChanged(PathRef File) {}
91  };
92  /// Creates a context provider that loads and installs config.
93  /// Errors in loading config are reported as diagnostics via Callbacks.
94  /// (This is typically used as ClangdServer::Options::ContextProvider).
95  static std::function<Context(PathRef)>
98 
99  struct Options {
100  /// To process requests asynchronously, ClangdServer spawns worker threads.
101  /// If this is zero, no threads are spawned. All work is done on the calling
102  /// thread, and callbacks are invoked before "async" functions return.
104 
105  /// AST caching policy. The default is to keep up to 3 ASTs in memory.
107 
108  /// Cached preambles are potentially large. If false, store them on disk.
110 
111  /// If true, ClangdServer builds a dynamic in-memory index for symbols in
112  /// opened files and uses the index to augment code completion results.
114  /// If true, ClangdServer automatically indexes files in the current project
115  /// on background threads. The index is stored in the project root.
116  bool BackgroundIndex = false;
117 
118  /// If set, use this index to augment code completion results.
120 
121  /// If set, queried to derive a processing context for some work.
122  /// Usually used to inject Config (see createConfiguredContextProvider).
123  ///
124  /// When the provider is called, the active context will be that inherited
125  /// from the request (e.g. addDocument()), or from the ClangdServer
126  /// constructor if there is no such request (e.g. background indexing).
127  ///
128  /// The path is an absolute path of the file being processed.
129  /// If there is no particular file (e.g. project loading) then it is empty.
130  std::function<Context(PathRef)> ContextProvider;
131 
132  /// The Options provider to use when running clang-tidy. If null, clang-tidy
133  /// checks will be disabled.
135 
136  /// Clangd's workspace root. Relevant for "workspace" operations not bound
137  /// to a particular file.
138  /// FIXME: If not set, should use the current working directory.
139  llvm::Optional<std::string> WorkspaceRoot;
140 
141  /// The resource directory is used to find internal headers, overriding
142  /// defaults and -resource-dir compiler flag).
143  /// If None, ClangdServer calls CompilerInvocation::GetResourcePath() to
144  /// obtain the standard resource directory.
145  llvm::Optional<std::string> ResourceDir = llvm::None;
146 
147  /// Time to wait after a new file version before computing diagnostics.
149  /*Min=*/std::chrono::milliseconds(50),
150  /*Max=*/std::chrono::milliseconds(500),
151  /*RebuildRatio=*/1,
152  };
153 
154  /// Cancel certain requests if the file changes before they begin running.
155  /// This is useful for "transient" actions like enumerateTweaks that were
156  /// likely implicitly generated, and avoids redundant work if clients forget
157  /// to cancel. Clients that always cancel stale requests should clear this.
158  bool ImplicitCancellation = true;
159 
160  /// Clangd will execute compiler drivers matching one of these globs to
161  /// fetch system include path.
162  std::vector<std::string> QueryDriverGlobs;
163 
164  /// Enable preview of FoldingRanges feature.
165  bool FoldingRanges = false;
166 
168 
169  explicit operator TUScheduler::Options() const;
170  };
171  // Sensible default options for use in tests.
172  // Features like indexing must be enabled if desired.
173  static Options optsForTest();
174 
175  /// Creates a new ClangdServer instance.
176  ///
177  /// ClangdServer uses \p CDB to obtain compilation arguments for parsing. Note
178  /// that ClangdServer only obtains compilation arguments once for each newly
179  /// added file (i.e., when processing a first call to addDocument) and reuses
180  /// those arguments for subsequent reparses. However, ClangdServer will check
181  /// if compilation arguments changed on calls to forceReparse().
182  ClangdServer(const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS,
183  const Options &Opts, Callbacks *Callbacks = nullptr);
184  ~ClangdServer();
185 
186  /// Gets the installed feature module of a given type, if any.
187  /// This exposes access the public interface of feature modules that have one.
188  template <typename Mod> Mod *featureModule() {
189  return FeatureModules ? FeatureModules->get<Mod>() : nullptr;
190  }
191  template <typename Mod> const Mod *featureModule() const {
192  return FeatureModules ? FeatureModules->get<Mod>() : nullptr;
193  }
194 
195  /// Add a \p File to the list of tracked C++ files or update the contents if
196  /// \p File is already tracked. Also schedules parsing of the AST for it on a
197  /// separate thread. When the parsing is complete, DiagConsumer passed in
198  /// constructor will receive onDiagnosticsReady callback.
199  /// Version identifies this snapshot and is propagated to ASTs, preambles,
200  /// diagnostics etc built from it. If empty, a version number is generated.
201  void addDocument(PathRef File, StringRef Contents,
202  llvm::StringRef Version = "null",
204  bool ForceRebuild = false);
205 
206  /// Remove \p File from list of tracked files, schedule a request to free
207  /// resources associated with it. Pending diagnostics for closed files may not
208  /// be delivered, even if requested with WantDiags::Auto or WantDiags::Yes.
209  /// An empty set of diagnostics will be delivered, with Version = "".
210  void removeDocument(PathRef File);
211 
212  /// Requests a reparse of currently opened files using their latest source.
213  /// This will typically only rebuild if something other than the source has
214  /// changed (e.g. the CDB yields different flags, or files included in the
215  /// preamble have been modified).
217  llvm::function_ref<bool(llvm::StringRef File)> Filter);
218 
219  /// Run code completion for \p File at \p Pos.
220  ///
221  /// This method should only be called for currently tracked files.
222  void codeComplete(PathRef File, Position Pos,
223  const clangd::CodeCompleteOptions &Opts,
225 
226  /// Provide signature help for \p File at \p Pos. This method should only be
227  /// called for tracked files.
229 
230  /// Find declaration/definition locations of symbol at a specified position.
231  void locateSymbolAt(PathRef File, Position Pos,
232  Callback<std::vector<LocatedSymbol>> CB);
233 
234  /// Switch to a corresponding source file when given a header file, and vice
235  /// versa.
237  Callback<llvm::Optional<clangd::Path>> CB);
238 
239  /// Get document highlights for a given position.
241  Callback<std::vector<DocumentHighlight>> CB);
242 
243  /// Get code hover for a given position.
244  void findHover(PathRef File, Position Pos,
245  Callback<llvm::Optional<HoverInfo>> CB);
246 
247  /// Get information about type hierarchy for a given position.
248  void typeHierarchy(PathRef File, Position Pos, int Resolve,
249  TypeHierarchyDirection Direction,
250  Callback<llvm::Optional<TypeHierarchyItem>> CB);
251 
252  /// Resolve type hierarchy item in the given direction.
253  void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve,
254  TypeHierarchyDirection Direction,
255  Callback<llvm::Optional<TypeHierarchyItem>> CB);
256 
257  /// Get information about call hierarchy for a given position.
259  Callback<std::vector<CallHierarchyItem>> CB);
260 
261  /// Resolve incoming calls for a given call hierarchy item.
262  void incomingCalls(const CallHierarchyItem &Item,
263  Callback<std::vector<CallHierarchyIncomingCall>>);
264 
265  /// Resolve inlay hints for a given document.
266  void inlayHints(PathRef File, Callback<std::vector<InlayHint>>);
267 
268  /// Retrieve the top symbols from the workspace matching a query.
269  void workspaceSymbols(StringRef Query, int Limit,
270  Callback<std::vector<SymbolInformation>> CB);
271 
272  /// Retrieve the symbols within the specified file.
273  void documentSymbols(StringRef File,
274  Callback<std::vector<DocumentSymbol>> CB);
275 
276  /// Retrieve ranges that can be used to fold code within the specified file.
277  void foldingRanges(StringRef File, Callback<std::vector<FoldingRange>> CB);
278 
279  /// Retrieve implementations for virtual method.
281  Callback<std::vector<LocatedSymbol>> CB);
282 
283  /// Retrieve locations for symbol references.
284  void findReferences(PathRef File, Position Pos, uint32_t Limit,
286 
287  /// Run formatting for the \p File with content \p Code.
288  /// If \p Rng is non-null, formats only that region.
289  void formatFile(PathRef File, llvm::Optional<Range> Rng,
291 
292  /// Run formatting after \p TriggerText was typed at \p Pos in \p File with
293  /// content \p Code.
294  void formatOnType(PathRef File, Position Pos, StringRef TriggerText,
295  Callback<std::vector<TextEdit>> CB);
296 
297  /// Test the validity of a rename operation.
298  ///
299  /// If NewName is provided, it performs a name validation.
300  void prepareRename(PathRef File, Position Pos,
301  llvm::Optional<std::string> NewName,
302  const RenameOptions &RenameOpts,
304 
305  /// Rename all occurrences of the symbol at the \p Pos in \p File to
306  /// \p NewName.
307  /// If WantFormat is false, the final TextEdit will be not formatted,
308  /// embedders could use this method to get all occurrences of the symbol (e.g.
309  /// highlighting them in prepare stage).
310  void rename(PathRef File, Position Pos, llvm::StringRef NewName,
311  const RenameOptions &Opts, Callback<RenameResult> CB);
312 
313  struct TweakRef {
314  std::string ID; /// ID to pass for applyTweak.
315  std::string Title; /// A single-line message to show in the UI.
316  llvm::StringLiteral Kind;
317  };
318  /// Enumerate the code tweaks available to the user at a specified point.
319  /// Tweaks where Filter returns false will not be checked or included.
320  void enumerateTweaks(PathRef File, Range Sel,
321  llvm::unique_function<bool(const Tweak &)> Filter,
322  Callback<std::vector<TweakRef>> CB);
323 
324  /// Apply the code tweak with a specified \p ID.
325  void applyTweak(PathRef File, Range Sel, StringRef ID,
327 
328  /// Called when an event occurs for a watched file in the workspace.
329  void onFileEvent(const DidChangeWatchedFilesParams &Params);
330 
331  /// Get symbol info for given position.
332  /// Clangd extension - not part of official LSP.
333  void symbolInfo(PathRef File, Position Pos,
334  Callback<std::vector<SymbolDetails>> CB);
335 
336  /// Get semantic ranges around a specified position in a file.
337  void semanticRanges(PathRef File, const std::vector<Position> &Pos,
338  Callback<std::vector<SelectionRange>> CB);
339 
340  /// Get all document links in a file.
341  void documentLinks(PathRef File, Callback<std::vector<DocumentLink>> CB);
342 
343  void semanticHighlights(PathRef File,
344  Callback<std::vector<HighlightingToken>>);
345 
346  /// Describe the AST subtree for a piece of code.
347  void getAST(PathRef File, llvm::Optional<Range> R,
348  Callback<llvm::Optional<ASTNode>> CB);
349 
350  /// Runs an arbitrary action that has access to the AST of the specified file.
351  /// The action will execute on one of ClangdServer's internal threads.
352  /// The AST is only valid for the duration of the callback.
353  /// As with other actions, the file must have been opened.
354  void customAction(PathRef File, llvm::StringRef Name,
356 
357  /// Fetches diagnostics for current version of the \p File. This might fail if
358  /// server is busy (building a preamble) and would require a long time to
359  /// prepare diagnostics. If it fails, clients should wait for
360  /// onSemanticsMaybeChanged and then retry.
361  /// These 'pulled' diagnostics do not interfere with the diagnostics 'pushed'
362  /// to Callbacks::onDiagnosticsReady, and clients may use either or both.
363  void diagnostics(PathRef File, Callback<std::vector<Diag>> CB);
364 
365  /// Returns estimated memory usage and other statistics for each of the
366  /// currently open files.
367  /// Overall memory usage of clangd may be significantly more than reported
368  /// here, as this metric does not account (at least) for:
369  /// - memory occupied by static and dynamic index,
370  /// - memory required for in-flight requests,
371  /// FIXME: those metrics might be useful too, we should add them.
372  llvm::StringMap<TUScheduler::FileStats> fileStats() const;
373 
374  /// Gets the contents of a currently tracked file. Returns nullptr if the file
375  /// isn't being tracked.
376  std::shared_ptr<const std::string> getDraft(PathRef File) const;
377 
378  // Blocks the main thread until the server is idle. Only for use in tests.
379  // Returns false if the timeout expires.
380  // FIXME: various subcomponents each get the full timeout, so it's more of
381  // an order of magnitude than a hard deadline.
382  LLVM_NODISCARD bool
383  blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds = 10);
384 
385  /// Builds a nested representation of memory used by components.
386  void profile(MemoryTree &MT) const;
387 
388 private:
389  FeatureModuleSet *FeatureModules;
390  const GlobalCompilationDatabase &CDB;
391  const ThreadsafeFS &TFS;
392 
393  Path ResourceDir;
394  // The index used to look up symbols. This could be:
395  // - null (all index functionality is optional)
396  // - the dynamic index owned by ClangdServer (DynamicIdx)
397  // - the static index passed to the constructor
398  // - a merged view of a static and dynamic index (MergedIndex)
399  const SymbolIndex *Index = nullptr;
400  // If present, an index of symbols in open files. Read via *Index.
401  std::unique_ptr<FileIndex> DynamicIdx;
402  // If present, the new "auto-index" maintained in background threads.
403  std::unique_ptr<BackgroundIndex> BackgroundIdx;
404  // Storage for merged views of the various indexes.
405  std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
406 
407  // When set, provides clang-tidy options for a specific file.
408  TidyProviderRef ClangTidyProvider;
409 
410  // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
411  llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
412  CachedCompletionFuzzyFindRequestByFile;
413  mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
414 
415  llvm::Optional<std::string> WorkspaceRoot;
416  llvm::Optional<TUScheduler> WorkScheduler;
417  // Invalidation policy used for actions that we assume are "transient".
419 
420  // Store of the current versions of the open documents.
421  // Only written from the main thread (despite being threadsafe).
422  DraftStore DraftMgr;
423 
424  std::unique_ptr<ThreadsafeFS> DirtyFS;
425 };
426 
427 } // namespace clangd
428 } // namespace clang
429 
430 #endif
clang::clangd::ClangdServer::TweakRef::Kind
llvm::StringLiteral Kind
A single-line message to show in the UI.
Definition: ClangdServer.h:316
clang::clangd::DraftStore
A thread-safe container for files opened in a workspace, addressed by filenames.
Definition: DraftStore.h:28
clang::clangd::ClangdServer::rename
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.
Definition: ClangdServer.cpp:519
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:947
clang::clangd::BackgroundQueue::Stats
Definition: Background.h:86
XRefs.h
clang::clangd::ClangdServer::Callbacks::onSemanticsMaybeChanged
virtual void onSemanticsMaybeChanged(PathRef File)
Called when the meaning of a source code may have changed without an edit.
Definition: ClangdServer.h:90
clang::clangd::ClangdServer::featureModule
Mod * featureModule()
Gets the installed feature module of a given type, if any.
Definition: ClangdServer.h:188
clang::clangd::FeatureModuleSet::get
Mod * get()
Definition: FeatureModule.h:172
Background.h
clang::clangd::FeatureModuleSet
A FeatureModuleSet is a collection of feature modules installed in clangd.
Definition: FeatureModule.h:145
clang::clangd::getDefaultAsyncThreadsCount
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
Definition: TUScheduler.cpp:1488
CodeComplete.h
clang::clangd::ClangdServer::Options::UpdateDebounce
DebouncePolicy UpdateDebounce
Time to wait after a new file version before computing diagnostics.
Definition: ClangdServer.h:148
clang::clangd::Path
std::string Path
A typedef to represent a file path.
Definition: Path.h:26
clang::clangd::ClangdServer::customAction
void customAction(PathRef File, llvm::StringRef Name, Callback< InputsAndAST > Action)
Runs an arbitrary action that has access to the AST of the specified file.
Definition: ClangdServer.cpp:927
clang::clangd::ASTRetentionPolicy
Configuration of the AST retention policy.
Definition: TUScheduler.h:63
Path.h
clang::clangd::ClangdServer::Options::FeatureModules
FeatureModuleSet * FeatureModules
Definition: ClangdServer.h:167
Diagnostics
WantDiagnostics Diagnostics
Definition: TUScheduler.cpp:567
clang::clangd::WantDiagnostics::Auto
@ Auto
Diagnostics must not be generated for this snapshot.
Index.h
clang::clangd::ClangdServer::getAST
void getAST(PathRef File, llvm::Optional< Range > R, Callback< llvm::Optional< ASTNode >> CB)
Describe the AST subtree for a piece of code.
Definition: ClangdServer.cpp:888
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:669
clang::clangd::ClangdServer::findReferences
void findReferences(PathRef File, Position Pos, uint32_t Limit, Callback< ReferencesResult > CB)
Retrieve locations for symbol references.
Definition: ClangdServer.cpp:821
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:145
ConfigProvider.h
clang::clangd::config::Provider
A source of configuration fragments.
Definition: ConfigProvider.h:64
clang::clangd::ClangdServer::optsForTest
static Options optsForTest()
Definition: ClangdServer.cpp:135
DraftStore.h
clang::clangd::ClangdServer::Options::StorePreamblesInMemory
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
Definition: ClangdServer.h:109
clang::clangd::ClangdServer
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
Definition: ClangdServer.h:62
clang::clangd::ClangdServer::Callbacks::onFileUpdated
virtual void onFileUpdated(PathRef File, const TUStatus &Status)
Called whenever the file status is updated.
Definition: ClangdServer.h:77
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:162
clang::clangd::GlobalCompilationDatabase
Provides compilation arguments used for parsing C and C++ files.
Definition: GlobalCompilationDatabase.h:36
Action
llvm::unique_function< void()> Action
Definition: TUScheduler.cpp:604
clang::clangd::ClangdServer::Options::ImplicitCancellation
bool ImplicitCancellation
Cancel certain requests if the file changes before they begin running.
Definition: ClangdServer.h:158
clang::clangd::ClangdServer::documentSymbols
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol >> CB)
Retrieve the symbols within the specified file.
Definition: ClangdServer.cpp:785
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:797
clang::clangd::ClangdServer::findImplementations
void findImplementations(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol >> CB)
Retrieve implementations for virtual method.
Definition: ClangdServer.cpp:809
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:223
clang::clangd::ClangdServer::inlayHints
void inlayHints(PathRef File, Callback< std::vector< InlayHint >>)
Resolve inlay hints for a given document.
Definition: ClangdServer.cpp:759
Cancellation.h
clang::clangd::ClangdServer::prepareRename
void prepareRename(PathRef File, Position Pos, llvm::Optional< std::string > NewName, const RenameOptions &RenameOpts, Callback< RenameResult > CB)
Test the validity of a rename operation.
Definition: ClangdServer.cpp:493
clang::clangd::WantDiagnostics
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
Definition: TUScheduler.h:53
clang::clangd::ClangdServer::TweakRef::ID
std::string ID
Definition: ClangdServer.h:314
Protocol.h
ThreadsafeFS.h
Hover.h
clang::clangd::ClangdServer::Options
Definition: ClangdServer.h:99
Rename.h
clang::clangd::Position
Definition: Protocol.h:148
clang::clangd::TUStatus
Definition: TUScheduler.h:113
clang::clangd::ClangdServer::getDraft
std::shared_ptr< const std::string > getDraft(PathRef File) const
Gets the contents of a currently tracked file.
Definition: ClangdServer.cpp:255
clang::clangd::ClangdServer::Options::StaticIndex
SymbolIndex * StaticIndex
If set, use this index to augment code completion results.
Definition: ClangdServer.h:119
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:339
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:344
clang::clangd::ClangdServer::Options::AsyncThreadsCount
unsigned AsyncThreadsCount
To process requests asynchronously, ClangdServer spawns worker threads.
Definition: ClangdServer.h:103
clang::clangd::ClangdServer::TweakRef::Title
std::string Title
ID to pass for applyTweak.
Definition: ClangdServer.h:315
Tweak.h
clang::clangd::MemoryTree
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...
Definition: MemoryTree.h:32
GlobalCompilationDatabase.h
clang::clangd::DidChangeWatchedFilesParams
Definition: Protocol.h:746
clang::clangd::ClangdServer::onFileEvent
void onFileEvent(const DidChangeWatchedFilesParams &Params)
Called when an event occurs for a watched file in the workspace.
Definition: ClangdServer.cpp:769
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::clangd::ClangdServer::semanticHighlights
void semanticHighlights(PathRef File, Callback< std::vector< HighlightingToken >>)
Definition: ClangdServer.cpp:876
clang::clangd::RenameOptions
Definition: Rename.h:24
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:689
clang::clangd::ClangdServer::incomingCalls
void incomingCalls(const CallHierarchyItem &Item, Callback< std::vector< CallHierarchyIncomingCall >>)
Resolve incoming calls for a given call hierarchy item.
Definition: ClangdServer.cpp:750
Diagnostics.h
clang::clangd::ClangdServer::formatOnType
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.
Definition: ClangdServer.cpp:465
clang::clangd::ClangdServer::Options::ContextProvider
std::function< Context(PathRef)> ContextProvider
If set, queried to derive a processing context for some work.
Definition: ClangdServer.h:130
FileIndex.h
clang::clangd::ClangdServer::formatFile
void formatFile(PathRef File, llvm::Optional< Range > Rng, Callback< tooling::Replacements > CB)
Run formatting for the File with content Code.
Definition: ClangdServer.cpp:427
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:45
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:774
clang::clangd::ClangdServer::documentLinks
void documentLinks(PathRef File, Callback< std::vector< DocumentLink >> CB)
Get all document links in a file.
Definition: ClangdServer.cpp:864
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:113
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:111
clang::clangd::ClangdServer::signatureHelp
void signatureHelp(PathRef File, Position Pos, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
Definition: ClangdServer.cpp:405
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:657
clang::clangd::TypeHierarchyDirection
TypeHierarchyDirection
Definition: Protocol.h:1351
clang::clangd::ClangdServer::diagnostics
void diagnostics(PathRef File, Callback< std::vector< Diag >> CB)
Fetches diagnostics for current version of the File.
Definition: ClangdServer.cpp:932
clang::clangd::TypeHierarchyItem
Definition: Protocol.h:1368
FeatureModule.h
clang::clangd::ClangdServer::Callbacks::onBackgroundIndexProgress
virtual void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats)
Called when background indexing tasks are enqueued/started/completed.
Definition: ClangdServer.h:82
ID
static char ID
Definition: Logger.cpp:74
clang::clangd::ClangdServer::Callbacks
Interface with hooks for users of ClangdServer to be notified of events.
Definition: ClangdServer.h:65
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:29
clang::clangd::ThreadsafeFS
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
Definition: ThreadsafeFS.h:28
clang::clangd::TUScheduler::ASTActionInvalidation
ASTActionInvalidation
Defines how a runWithAST action is implicitly cancelled by other actions.
Definition: TUScheduler.h:257
clang::clangd::ClangdServer::TweakRef
Definition: ClangdServer.h:313
clang::clangd::TUScheduler::Options
Definition: TUScheduler.h:188
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:610
clang::clangd::Range
Definition: Protocol.h:177
clang::clangd::ClangdServer::profile
void profile(MemoryTree &MT) const
Builds a nested representation of memory used by components.
Definition: ClangdServer.cpp:987
SemanticHighlighting.h
clang::clangd::DebouncePolicy
Clangd may wait after an update to see if another one comes along.
Definition: TUScheduler.h:74
MemoryTree.h
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:833
Function.h
TUScheduler.h
clang::clangd::ClangdServer::reparseOpenFilesIfNeeded
void reparseOpenFilesIfNeeded(llvm::function_ref< bool(llvm::StringRef File)> Filter)
Requests a reparse of currently opened files using their latest source.
Definition: ClangdServer.cpp:245
clang::clangd::Tweak
An interface base for small context-sensitive refactoring actions.
Definition: Tweak.h:49
clang::clangd::ClangdServer::Options::RetentionPolicy
ASTRetentionPolicy RetentionPolicy
AST caching policy. The default is to keep up to 3 ASTs in memory.
Definition: ClangdServer.h:106
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:845
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:729
clang::clangd::CallHierarchyItem
Represents programming constructs like functions or constructors in the context of call hierarchy.
Definition: Protocol.h:1436
clang::clangd::ClangdServer::Options::ClangTidyProvider
TidyProviderRef ClangTidyProvider
The Options provider to use when running clang-tidy.
Definition: ClangdServer.h:134
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:701
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:165
Pos
Position Pos
Definition: SourceCode.cpp:657
clang::clangd::ClangdServer::enumerateTweaks
void enumerateTweaks(PathRef File, Range Sel, llvm::unique_function< bool(const Tweak &)> Filter, Callback< std::vector< TweakRef >> CB)
Enumerate the code tweaks available to the user at a specified point.
Definition: ClangdServer.cpp:575
clang::clangd::TidyProviderRef
llvm::function_ref< void(tidy::ClangTidyOptions &, llvm::StringRef)> TidyProviderRef
A factory to modify a tidy::ClangTidyOptions that doesn't hold any state.
Definition: TidyProvider.h:29
clang::clangd::BackgroundIndex
Definition: Background.h:134
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:73
clang::clangd::ClangdServer::~ClangdServer
~ClangdServer()
Definition: ClangdServer.cpp:209
clang::clangd::ClangdServer::prepareCallHierarchy
void prepareCallHierarchy(PathRef File, Position Pos, Callback< std::vector< CallHierarchyItem >> CB)
Get information about call hierarchy for a given position.
Definition: ClangdServer.cpp:739
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:153
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::featureModule
const Mod * featureModule() const
Definition: ClangdServer.h:191
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:715
clang::clangd::ClangdServer::Options::WorkspaceRoot
llvm::Optional< std::string > WorkspaceRoot
Clangd's workspace root.
Definition: ClangdServer.h:139
clang::clangd::ClangdServer::blockUntilIdleForTest
LLVM_NODISCARD bool blockUntilIdleForTest(llvm::Optional< double > TimeoutSeconds=10)
Definition: ClangdServer.cpp:952
clang::clangd::ClangdServer::createConfiguredContextProvider
static std::function< Context(PathRef)> createConfiguredContextProvider(const config::Provider *Provider, ClangdServer::Callbacks *)
Creates a context provider that loads and installs config.
Definition: ClangdServer.cpp:263