clang-tools  15.0.0git
ClangdServer.cpp
Go to the documentation of this file.
1 //===--- ClangdServer.cpp - 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 #include "ClangdServer.h"
10 #include "CodeComplete.h"
11 #include "Config.h"
12 #include "Diagnostics.h"
13 #include "DumpAST.h"
14 #include "FindSymbols.h"
15 #include "Format.h"
16 #include "HeaderSourceSwitch.h"
17 #include "InlayHints.h"
18 #include "ParsedAST.h"
19 #include "Preamble.h"
20 #include "Protocol.h"
21 #include "SemanticHighlighting.h"
22 #include "SemanticSelection.h"
23 #include "SourceCode.h"
24 #include "TUScheduler.h"
25 #include "XRefs.h"
27 #include "index/FileIndex.h"
28 #include "index/Merge.h"
29 #include "index/StdLib.h"
30 #include "refactor/Rename.h"
31 #include "refactor/Tweak.h"
32 #include "support/Cancellation.h"
33 #include "support/Logger.h"
34 #include "support/MemoryTree.h"
35 #include "support/ThreadsafeFS.h"
36 #include "support/Trace.h"
37 #include "clang/Format/Format.h"
38 #include "clang/Lex/Preprocessor.h"
39 #include "clang/Tooling/CompilationDatabase.h"
40 #include "clang/Tooling/Core/Replacement.h"
41 #include "llvm/ADT/ArrayRef.h"
42 #include "llvm/ADT/Optional.h"
43 #include "llvm/ADT/STLExtras.h"
44 #include "llvm/ADT/StringRef.h"
45 #include "llvm/Support/Error.h"
46 #include "llvm/Support/Path.h"
47 #include "llvm/Support/raw_ostream.h"
48 #include <algorithm>
49 #include <chrono>
50 #include <future>
51 #include <memory>
52 #include <mutex>
53 #include <string>
54 #include <type_traits>
55 
56 namespace clang {
57 namespace clangd {
58 namespace {
59 
60 // Update the FileIndex with new ASTs and plumb the diagnostics responses.
61 struct UpdateIndexCallbacks : public ParsingCallbacks {
62  UpdateIndexCallbacks(FileIndex *FIndex,
63  ClangdServer::Callbacks *ServerCallbacks,
64  const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks)
65  : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
66  Tasks(Tasks) {}
67 
68  void onPreambleAST(PathRef Path, llvm::StringRef Version,
69  const CompilerInvocation &CI, ASTContext &Ctx,
70  Preprocessor &PP,
71  const CanonicalIncludes &CanonIncludes) override {
72  // If this preamble uses a standard library we haven't seen yet, index it.
73  if (FIndex)
74  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
75  indexStdlib(CI, std::move(*Loc));
76 
77  if (FIndex)
78  FIndex->updatePreamble(Path, Version, Ctx, PP, CanonIncludes);
79  }
80 
81  void indexStdlib(const CompilerInvocation &CI, StdLibLocation Loc) {
82  auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
83  CI(std::make_unique<CompilerInvocation>(CI))]() mutable {
84  IndexFileIn IF;
85  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
86  if (Stdlib.isBest(LO))
87  FIndex->updatePreamble(std::move(IF));
88  };
89  if (Tasks)
90  // This doesn't have a semaphore to enforce -j, but it's rare.
91  Tasks->runAsync("IndexStdlib", std::move(Task));
92  else
93  Task();
94  }
95 
96  void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
97  if (FIndex)
98  FIndex->updateMain(Path, AST);
99 
100  assert(AST.getDiagnostics() &&
101  "We issue callback only with fresh preambles");
102  std::vector<Diag> Diagnostics = *AST.getDiagnostics();
103  if (ServerCallbacks)
104  Publish([&]() {
105  ServerCallbacks->onDiagnosticsReady(Path, AST.version(),
106  std::move(Diagnostics));
107  });
108  }
109 
110  void onFailedAST(PathRef Path, llvm::StringRef Version,
111  std::vector<Diag> Diags, PublishFn Publish) override {
112  if (ServerCallbacks)
113  Publish(
114  [&]() { ServerCallbacks->onDiagnosticsReady(Path, Version, Diags); });
115  }
116 
117  void onFileUpdated(PathRef File, const TUStatus &Status) override {
118  if (ServerCallbacks)
119  ServerCallbacks->onFileUpdated(File, Status);
120  }
121 
122  void onPreamblePublished(PathRef File) override {
123  if (ServerCallbacks)
124  ServerCallbacks->onSemanticsMaybeChanged(File);
125  }
126 
127 private:
128  FileIndex *FIndex;
129  ClangdServer::Callbacks *ServerCallbacks;
130  const ThreadsafeFS &TFS;
131  StdLibSet Stdlib;
132  AsyncTaskRunner *Tasks;
133 };
134 
135 class DraftStoreFS : public ThreadsafeFS {
136 public:
137  DraftStoreFS(const ThreadsafeFS &Base, const DraftStore &Drafts)
138  : Base(Base), DirtyFiles(Drafts) {}
139 
140 private:
141  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> viewImpl() const override {
142  auto OFS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
143  Base.view(llvm::None));
144  OFS->pushOverlay(DirtyFiles.asVFS());
145  return OFS;
146  }
147 
148  const ThreadsafeFS &Base;
149  const DraftStore &DirtyFiles;
150 };
151 
152 } // namespace
153 
156  Opts.UpdateDebounce = DebouncePolicy::fixed(/*zero*/ {});
157  Opts.StorePreamblesInMemory = true;
158  Opts.AsyncThreadsCount = 4; // Consistent!
159  return Opts;
160 }
161 
162 ClangdServer::Options::operator TUScheduler::Options() const {
164  Opts.AsyncThreadsCount = AsyncThreadsCount;
165  Opts.RetentionPolicy = RetentionPolicy;
166  Opts.StorePreamblesInMemory = StorePreamblesInMemory;
167  Opts.UpdateDebounce = UpdateDebounce;
168  Opts.ContextProvider = ContextProvider;
169  return Opts;
170 }
171 
173  const ThreadsafeFS &TFS, const Options &Opts,
175  : FeatureModules(Opts.FeatureModules), CDB(CDB), TFS(TFS),
176  DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
177  ClangTidyProvider(Opts.ClangTidyProvider),
178  UseDirtyHeaders(Opts.UseDirtyHeaders),
179  PreambleParseForwardingFunctions(Opts.PreambleParseForwardingFunctions),
180  WorkspaceRoot(Opts.WorkspaceRoot),
181  Transient(Opts.ImplicitCancellation ? TUScheduler::InvalidateOnUpdate
182  : TUScheduler::NoInvalidation),
183  DirtyFS(std::make_unique<DraftStoreFS>(TFS, DraftMgr)) {
184  if (Opts.AsyncThreadsCount != 0)
185  IndexTasks.emplace();
186  // Pass a callback into `WorkScheduler` to extract symbols from a newly
187  // parsed file and rebuild the file index synchronously each time an AST
188  // is parsed.
189  WorkScheduler.emplace(CDB, TUScheduler::Options(Opts),
190  std::make_unique<UpdateIndexCallbacks>(
191  DynamicIdx.get(), Callbacks, TFS,
192  IndexTasks ? IndexTasks.getPointer() : nullptr));
193  // Adds an index to the stack, at higher priority than existing indexes.
194  auto AddIndex = [&](SymbolIndex *Idx) {
195  if (this->Index != nullptr) {
196  MergedIdx.push_back(std::make_unique<MergedIndex>(Idx, this->Index));
197  this->Index = MergedIdx.back().get();
198  } else {
199  this->Index = Idx;
200  }
201  };
202  if (Opts.StaticIndex)
203  AddIndex(Opts.StaticIndex);
204  if (Opts.BackgroundIndex) {
206  BGOpts.ThreadPoolSize = std::max(Opts.AsyncThreadsCount, 1u);
208  if (Callbacks)
210  };
211  BGOpts.ContextProvider = Opts.ContextProvider;
212  BackgroundIdx = std::make_unique<BackgroundIndex>(
213  TFS, CDB,
215  [&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); }),
216  std::move(BGOpts));
217  AddIndex(BackgroundIdx.get());
218  }
219  if (DynamicIdx)
220  AddIndex(DynamicIdx.get());
221 
222  if (Opts.FeatureModules) {
224  *this->WorkScheduler,
225  this->Index,
226  this->TFS,
227  };
228  for (auto &Mod : *Opts.FeatureModules)
229  Mod.initialize(F);
230  }
231 }
232 
234  // Destroying TUScheduler first shuts down request threads that might
235  // otherwise access members concurrently.
236  // (Nobody can be using TUScheduler because we're on the main thread).
237  WorkScheduler.reset();
238  // Now requests have stopped, we can shut down feature modules.
239  if (FeatureModules) {
240  for (auto &Mod : *FeatureModules)
241  Mod.stop();
242  for (auto &Mod : *FeatureModules)
243  Mod.blockUntilIdle(Deadline::infinity());
244  }
245 }
246 
247 void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
248  llvm::StringRef Version,
249  WantDiagnostics WantDiags, bool ForceRebuild) {
250  std::string ActualVersion = DraftMgr.addDraft(File, Version, Contents);
251  ParseOptions Opts;
252  Opts.PreambleParseForwardingFunctions = PreambleParseForwardingFunctions;
253 
254  // Compile command is set asynchronously during update, as it can be slow.
256  Inputs.TFS = &getHeaderFS();
257  Inputs.Contents = std::string(Contents);
258  Inputs.Version = std::move(ActualVersion);
259  Inputs.ForceRebuild = ForceRebuild;
260  Inputs.Opts = std::move(Opts);
261  Inputs.Index = Index;
262  Inputs.ClangTidyProvider = ClangTidyProvider;
263  Inputs.FeatureModules = FeatureModules;
264  bool NewFile = WorkScheduler->update(File, Inputs, WantDiags);
265  // If we loaded Foo.h, we want to make sure Foo.cpp is indexed.
266  if (NewFile && BackgroundIdx)
267  BackgroundIdx->boostRelated(File);
268 }
269 
271  llvm::function_ref<bool(llvm::StringRef File)> Filter) {
272  // Reparse only opened files that were modified.
273  for (const Path &FilePath : DraftMgr.getActiveFiles())
274  if (Filter(FilePath))
275  if (auto Draft = DraftMgr.getDraft(FilePath)) // else disappeared in race?
276  addDocument(FilePath, *Draft->Contents, Draft->Version,
278 }
279 
280 std::shared_ptr<const std::string> ClangdServer::getDraft(PathRef File) const {
281  auto Draft = DraftMgr.getDraft(File);
282  if (!Draft)
283  return nullptr;
284  return std::move(Draft->Contents);
285 }
286 
287 std::function<Context(PathRef)>
289  Callbacks *Publish) {
290  if (!Provider)
291  return [](llvm::StringRef) { return Context::current().clone(); };
292 
293  struct Impl {
294  const config::Provider *Provider;
295  ClangdServer::Callbacks *Publish;
296  std::mutex PublishMu;
297 
298  Impl(const config::Provider *Provider, ClangdServer::Callbacks *Publish)
299  : Provider(Provider), Publish(Publish) {}
300 
301  Context operator()(llvm::StringRef File) {
302  config::Params Params;
303  // Don't reread config files excessively often.
304  // FIXME: when we see a config file change event, use the event timestamp?
305  Params.FreshTime =
306  std::chrono::steady_clock::now() - std::chrono::seconds(5);
307  llvm::SmallString<256> PosixPath;
308  if (!File.empty()) {
309  assert(llvm::sys::path::is_absolute(File));
310  llvm::sys::path::native(File, PosixPath, llvm::sys::path::Style::posix);
311  Params.Path = PosixPath.str();
312  }
313 
314  llvm::StringMap<std::vector<Diag>> ReportableDiagnostics;
315  Config C = Provider->getConfig(Params, [&](const llvm::SMDiagnostic &D) {
316  // Create the map entry even for note diagnostics we don't report.
317  // This means that when the file is parsed with no warnings, we
318  // publish an empty set of diagnostics, clearing any the client has.
319  handleDiagnostic(D, !Publish || D.getFilename().empty()
320  ? nullptr
321  : &ReportableDiagnostics[D.getFilename()]);
322  });
323  // Blindly publish diagnostics for the (unopened) parsed config files.
324  // We must avoid reporting diagnostics for *the same file* concurrently.
325  // Source diags are published elsewhere, but those are different files.
326  if (!ReportableDiagnostics.empty()) {
327  std::lock_guard<std::mutex> Lock(PublishMu);
328  for (auto &Entry : ReportableDiagnostics)
329  Publish->onDiagnosticsReady(Entry.first(), /*Version=*/"",
330  std::move(Entry.second));
331  }
332  return Context::current().derive(Config::Key, std::move(C));
333  }
334 
335  void handleDiagnostic(const llvm::SMDiagnostic &D,
336  std::vector<Diag> *ClientDiagnostics) {
337  switch (D.getKind()) {
338  case llvm::SourceMgr::DK_Error:
339  elog("config error at {0}:{1}:{2}: {3}", D.getFilename(), D.getLineNo(),
340  D.getColumnNo(), D.getMessage());
341  break;
342  case llvm::SourceMgr::DK_Warning:
343  log("config warning at {0}:{1}:{2}: {3}", D.getFilename(),
344  D.getLineNo(), D.getColumnNo(), D.getMessage());
345  break;
346  case llvm::SourceMgr::DK_Note:
347  case llvm::SourceMgr::DK_Remark:
348  vlog("config note at {0}:{1}:{2}: {3}", D.getFilename(), D.getLineNo(),
349  D.getColumnNo(), D.getMessage());
350  ClientDiagnostics = nullptr; // Don't emit notes as LSP diagnostics.
351  break;
352  }
353  if (ClientDiagnostics)
354  ClientDiagnostics->push_back(toDiag(D, Diag::ClangdConfig));
355  }
356  };
357 
358  // Copyable wrapper.
359  return [I(std::make_shared<Impl>(Provider, Publish))](llvm::StringRef Path) {
360  return (*I)(Path);
361  };
362 }
363 
365  DraftMgr.removeDraft(File);
366  WorkScheduler->remove(File);
367 }
368 
370  const clangd::CodeCompleteOptions &Opts,
372  // Copy completion options for passing them to async task handler.
373  auto CodeCompleteOpts = Opts;
374  if (!CodeCompleteOpts.Index) // Respect overridden index.
375  CodeCompleteOpts.Index = Index;
376 
377  auto Task = [Pos, CodeCompleteOpts, File = File.str(), CB = std::move(CB),
378  this](llvm::Expected<InputsAndPreamble> IP) mutable {
379  if (!IP)
380  return CB(IP.takeError());
381  if (auto Reason = isCancelled())
382  return CB(llvm::make_error<CancelledError>(Reason));
383 
384  llvm::Optional<SpeculativeFuzzyFind> SpecFuzzyFind;
385  if (!IP->Preamble) {
386  // No speculation in Fallback mode, as it's supposed to be much faster
387  // without compiling.
388  vlog("Build for file {0} is not ready. Enter fallback mode.", File);
389  } else if (CodeCompleteOpts.Index) {
390  SpecFuzzyFind.emplace();
391  {
392  std::lock_guard<std::mutex> Lock(CachedCompletionFuzzyFindRequestMutex);
393  SpecFuzzyFind->CachedReq = CachedCompletionFuzzyFindRequestByFile[File];
394  }
395  }
396  ParseInputs ParseInput{IP->Command, &getHeaderFS(), IP->Contents.str()};
397  // FIXME: Add traling new line if there is none at eof, workaround a crash,
398  // see https://github.com/clangd/clangd/issues/332
399  if (!IP->Contents.endswith("\n"))
400  ParseInput.Contents.append("\n");
401  ParseInput.Index = Index;
402 
403  CodeCompleteOpts.MainFileSignals = IP->Signals;
404  CodeCompleteOpts.AllScopes = Config::current().Completion.AllScopes;
405  // FIXME(ibiryukov): even if Preamble is non-null, we may want to check
406  // both the old and the new version in case only one of them matches.
408  File, Pos, IP->Preamble, ParseInput, CodeCompleteOpts,
409  SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr);
410  {
411  clang::clangd::trace::Span Tracer("Completion results callback");
412  CB(std::move(Result));
413  }
414  if (SpecFuzzyFind && SpecFuzzyFind->NewReq.hasValue()) {
415  std::lock_guard<std::mutex> Lock(CachedCompletionFuzzyFindRequestMutex);
416  CachedCompletionFuzzyFindRequestByFile[File] =
417  SpecFuzzyFind->NewReq.getValue();
418  }
419  // SpecFuzzyFind is only destroyed after speculative fuzzy find finishes.
420  // We don't want `codeComplete` to wait for the async call if it doesn't use
421  // the result (e.g. non-index completion, speculation fails), so that `CB`
422  // is called as soon as results are available.
423  };
424 
425  // We use a potentially-stale preamble because latency is critical here.
426  WorkScheduler->runWithPreamble(
427  "CodeComplete", File,
428  (Opts.RunParser == CodeCompleteOptions::AlwaysParse)
431  std::move(Task));
432 }
433 
435  MarkupKind DocumentationFormat,
437 
438  auto Action = [Pos, File = File.str(), CB = std::move(CB),
439  DocumentationFormat,
440  this](llvm::Expected<InputsAndPreamble> IP) mutable {
441  if (!IP)
442  return CB(IP.takeError());
443 
444  const auto *PreambleData = IP->Preamble;
445  if (!PreambleData)
446  return CB(error("Failed to parse includes"));
447 
448  ParseInputs ParseInput{IP->Command, &getHeaderFS(), IP->Contents.str()};
449  // FIXME: Add traling new line if there is none at eof, workaround a crash,
450  // see https://github.com/clangd/clangd/issues/332
451  if (!IP->Contents.endswith("\n"))
452  ParseInput.Contents.append("\n");
453  ParseInput.Index = Index;
455  DocumentationFormat));
456  };
457 
458  // Unlike code completion, we wait for a preamble here.
459  WorkScheduler->runWithPreamble("SignatureHelp", File, TUScheduler::Stale,
460  std::move(Action));
461 }
462 
463 void ClangdServer::formatFile(PathRef File, llvm::Optional<Range> Rng,
465  auto Code = getDraft(File);
466  if (!Code)
467  return CB(llvm::make_error<LSPError>("trying to format non-added document",
469  tooling::Range RequestedRange;
470  if (Rng) {
471  llvm::Expected<size_t> Begin = positionToOffset(*Code, Rng->start);
472  if (!Begin)
473  return CB(Begin.takeError());
474  llvm::Expected<size_t> End = positionToOffset(*Code, Rng->end);
475  if (!End)
476  return CB(End.takeError());
477  RequestedRange = tooling::Range(*Begin, *End - *Begin);
478  } else {
479  RequestedRange = tooling::Range(0, Code->size());
480  }
481 
482  // Call clang-format.
483  auto Action = [File = File.str(), Code = std::move(*Code),
484  Ranges = std::vector<tooling::Range>{RequestedRange},
485  CB = std::move(CB), this]() mutable {
486  format::FormatStyle Style = getFormatStyleForFile(File, Code, TFS);
487  tooling::Replacements IncludeReplaces =
488  format::sortIncludes(Style, Code, Ranges, File);
489  auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces);
490  if (!Changed)
491  return CB(Changed.takeError());
492 
493  CB(IncludeReplaces.merge(format::reformat(
494  Style, *Changed,
495  tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
496  File)));
497  };
498  WorkScheduler->runQuick("Format", File, std::move(Action));
499 }
500 
502  StringRef TriggerText,
503  Callback<std::vector<TextEdit>> CB) {
504  auto Code = getDraft(File);
505  if (!Code)
506  return CB(llvm::make_error<LSPError>("trying to format non-added document",
508  llvm::Expected<size_t> CursorPos = positionToOffset(*Code, Pos);
509  if (!CursorPos)
510  return CB(CursorPos.takeError());
511  auto Action = [File = File.str(), Code = std::move(*Code),
512  TriggerText = TriggerText.str(), CursorPos = *CursorPos,
513  CB = std::move(CB), this]() mutable {
514  auto Style = format::getStyle(format::DefaultFormatStyle, File,
515  format::DefaultFallbackStyle, Code,
516  TFS.view(/*CWD=*/llvm::None).get());
517  if (!Style)
518  return CB(Style.takeError());
519 
520  std::vector<TextEdit> Result;
521  for (const tooling::Replacement &R :
522  formatIncremental(Code, CursorPos, TriggerText, *Style))
523  Result.push_back(replacementToEdit(Code, R));
524  return CB(Result);
525  };
526  WorkScheduler->runQuick("FormatOnType", File, std::move(Action));
527 }
528 
530  llvm::Optional<std::string> NewName,
531  const RenameOptions &RenameOpts,
533  auto Action = [Pos, File = File.str(), CB = std::move(CB),
534  NewName = std::move(NewName),
535  RenameOpts](llvm::Expected<InputsAndAST> InpAST) mutable {
536  if (!InpAST)
537  return CB(InpAST.takeError());
538  // prepareRename is latency-sensitive: we don't query the index, as we
539  // only need main-file references
540  auto Results =
541  clangd::rename({Pos, NewName.value_or("__clangd_rename_placeholder"),
542  InpAST->AST, File, /*FS=*/nullptr,
543  /*Index=*/nullptr, RenameOpts});
544  if (!Results) {
545  // LSP says to return null on failure, but that will result in a generic
546  // failure message. If we send an LSP error response, clients can surface
547  // the message to users (VSCode does).
548  return CB(Results.takeError());
549  }
550  return CB(*Results);
551  };
552  WorkScheduler->runWithAST("PrepareRename", File, std::move(Action));
553 }
554 
555 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
556  const RenameOptions &Opts,
558  auto Action = [File = File.str(), NewName = NewName.str(), Pos, Opts,
559  CB = std::move(CB),
560  this](llvm::Expected<InputsAndAST> InpAST) mutable {
561  // Tracks number of files edited per invocation.
562  static constexpr trace::Metric RenameFiles("rename_files",
564  if (!InpAST)
565  return CB(InpAST.takeError());
566  auto R = clangd::rename({Pos, NewName, InpAST->AST, File,
567  DirtyFS->view(llvm::None), Index, Opts});
568  if (!R)
569  return CB(R.takeError());
570 
571  if (Opts.WantFormat) {
572  auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
573  *InpAST->Inputs.TFS);
574  llvm::Error Err = llvm::Error::success();
575  for (auto &E : R->GlobalChanges)
576  Err =
577  llvm::joinErrors(reformatEdit(E.getValue(), Style), std::move(Err));
578 
579  if (Err)
580  return CB(std::move(Err));
581  }
582  RenameFiles.record(R->GlobalChanges.size());
583  return CB(*R);
584  };
585  WorkScheduler->runWithAST("Rename", File, std::move(Action));
586 }
587 
588 // May generate several candidate selections, due to SelectionTree ambiguity.
589 // vector of pointers because GCC doesn't like non-copyable Selection.
590 static llvm::Expected<std::vector<std::unique_ptr<Tweak::Selection>>>
591 tweakSelection(const Range &Sel, const InputsAndAST &AST,
592  llvm::vfs::FileSystem *FS) {
593  auto Begin = positionToOffset(AST.Inputs.Contents, Sel.start);
594  if (!Begin)
595  return Begin.takeError();
596  auto End = positionToOffset(AST.Inputs.Contents, Sel.end);
597  if (!End)
598  return End.takeError();
599  std::vector<std::unique_ptr<Tweak::Selection>> Result;
601  AST.AST.getASTContext(), AST.AST.getTokens(), *Begin, *End,
602  [&](SelectionTree T) {
603  Result.push_back(std::make_unique<Tweak::Selection>(
604  AST.Inputs.Index, AST.AST, *Begin, *End, std::move(T), FS));
605  return false;
606  });
607  assert(!Result.empty() && "Expected at least one SelectionTree");
608  return std::move(Result);
609 }
610 
612  PathRef File, Range Sel, llvm::unique_function<bool(const Tweak &)> Filter,
613  Callback<std::vector<TweakRef>> CB) {
614  // Tracks number of times a tweak has been offered.
615  static constexpr trace::Metric TweakAvailable(
616  "tweak_available", trace::Metric::Counter, "tweak_id");
617  auto Action = [Sel, CB = std::move(CB), Filter = std::move(Filter),
618  FeatureModules(this->FeatureModules)](
619  Expected<InputsAndAST> InpAST) mutable {
620  if (!InpAST)
621  return CB(InpAST.takeError());
622  auto Selections = tweakSelection(Sel, *InpAST, /*FS=*/nullptr);
623  if (!Selections)
624  return CB(Selections.takeError());
625  std::vector<TweakRef> Res;
626  // Don't allow a tweak to fire more than once across ambiguous selections.
627  llvm::DenseSet<llvm::StringRef> PreparedTweaks;
628  auto DeduplicatingFilter = [&](const Tweak &T) {
629  return Filter(T) && !PreparedTweaks.count(T.id());
630  };
631  for (const auto &Sel : *Selections) {
632  for (auto &T : prepareTweaks(*Sel, DeduplicatingFilter, FeatureModules)) {
633  Res.push_back({T->id(), T->title(), T->kind()});
634  PreparedTweaks.insert(T->id());
635  TweakAvailable.record(1, T->id());
636  }
637  }
638 
639  CB(std::move(Res));
640  };
641 
642  WorkScheduler->runWithAST("EnumerateTweaks", File, std::move(Action),
643  Transient);
644 }
645 
646 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
648  // Tracks number of times a tweak has been attempted.
649  static constexpr trace::Metric TweakAttempt(
650  "tweak_attempt", trace::Metric::Counter, "tweak_id");
651  // Tracks number of times a tweak has failed to produce edits.
652  static constexpr trace::Metric TweakFailed(
653  "tweak_failed", trace::Metric::Counter, "tweak_id");
654  TweakAttempt.record(1, TweakID);
655  auto Action = [File = File.str(), Sel, TweakID = TweakID.str(),
656  CB = std::move(CB),
657  this](Expected<InputsAndAST> InpAST) mutable {
658  if (!InpAST)
659  return CB(InpAST.takeError());
660  auto FS = DirtyFS->view(llvm::None);
661  auto Selections = tweakSelection(Sel, *InpAST, FS.get());
662  if (!Selections)
663  return CB(Selections.takeError());
664  llvm::Optional<llvm::Expected<Tweak::Effect>> Effect;
665  // Try each selection, take the first one that prepare()s.
666  // If they all fail, Effect will hold get the last error.
667  for (const auto &Selection : *Selections) {
668  auto T = prepareTweak(TweakID, *Selection, FeatureModules);
669  if (T) {
670  Effect = (*T)->apply(*Selection);
671  break;
672  }
673  Effect = T.takeError();
674  }
675  assert(Effect && "Expected at least one selection");
676  if (*Effect && (*Effect)->FormatEdits) {
677  // Format tweaks that require it centrally here.
678  for (auto &It : (*Effect)->ApplyEdits) {
679  Edit &E = It.second;
680  format::FormatStyle Style =
681  getFormatStyleForFile(File, E.InitialCode, TFS);
682  if (llvm::Error Err = reformatEdit(E, Style))
683  elog("Failed to format {0}: {1}", It.first(), std::move(Err));
684  }
685  } else {
686  TweakFailed.record(1, TweakID);
687  }
688  return CB(std::move(*Effect));
689  };
690  WorkScheduler->runWithAST("ApplyTweak", File, std::move(Action));
691 }
692 
694  Callback<std::vector<LocatedSymbol>> CB) {
695  auto Action = [Pos, CB = std::move(CB),
696  this](llvm::Expected<InputsAndAST> InpAST) mutable {
697  if (!InpAST)
698  return CB(InpAST.takeError());
699  CB(clangd::locateSymbolAt(InpAST->AST, Pos, Index));
700  };
701 
702  WorkScheduler->runWithAST("Definitions", File, std::move(Action));
703 }
704 
706  PathRef Path, Callback<llvm::Optional<clangd::Path>> CB) {
707  // We want to return the result as fast as possible, strategy is:
708  // 1) use the file-only heuristic, it requires some IO but it is much
709  // faster than building AST, but it only works when .h/.cc files are in
710  // the same directory.
711  // 2) if 1) fails, we use the AST&Index approach, it is slower but supports
712  // different code layout.
713  if (auto CorrespondingFile =
714  getCorrespondingHeaderOrSource(Path, TFS.view(llvm::None)))
715  return CB(std::move(CorrespondingFile));
716  auto Action = [Path = Path.str(), CB = std::move(CB),
717  this](llvm::Expected<InputsAndAST> InpAST) mutable {
718  if (!InpAST)
719  return CB(InpAST.takeError());
720  CB(getCorrespondingHeaderOrSource(Path, InpAST->AST, Index));
721  };
722  WorkScheduler->runWithAST("SwitchHeaderSource", Path, std::move(Action));
723 }
724 
726  PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) {
727  auto Action =
728  [Pos, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
729  if (!InpAST)
730  return CB(InpAST.takeError());
731  CB(clangd::findDocumentHighlights(InpAST->AST, Pos));
732  };
733 
734  WorkScheduler->runWithAST("Highlights", File, std::move(Action), Transient);
735 }
736 
738  Callback<llvm::Optional<HoverInfo>> CB) {
739  auto Action = [File = File.str(), Pos, CB = std::move(CB),
740  this](llvm::Expected<InputsAndAST> InpAST) mutable {
741  if (!InpAST)
742  return CB(InpAST.takeError());
744  File, InpAST->Inputs.Contents, *InpAST->Inputs.TFS);
745  CB(clangd::getHover(InpAST->AST, Pos, std::move(Style), Index));
746  };
747 
748  WorkScheduler->runWithAST("Hover", File, std::move(Action), Transient);
749 }
750 
752  TypeHierarchyDirection Direction,
753  Callback<Optional<TypeHierarchyItem>> CB) {
754  auto Action = [File = File.str(), Pos, Resolve, Direction, CB = std::move(CB),
755  this](Expected<InputsAndAST> InpAST) mutable {
756  if (!InpAST)
757  return CB(InpAST.takeError());
758  CB(clangd::getTypeHierarchy(InpAST->AST, Pos, Resolve, Direction, Index,
759  File));
760  };
761 
762  WorkScheduler->runWithAST("TypeHierarchy", File, std::move(Action));
763 }
764 
766  TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction,
767  Callback<llvm::Optional<TypeHierarchyItem>> CB) {
768  WorkScheduler->run(
769  "Resolve Type Hierarchy", "", [=, CB = std::move(CB)]() mutable {
770  clangd::resolveTypeHierarchy(Item, Resolve, Direction, Index);
771  CB(Item);
772  });
773 }
774 
776  PathRef File, Position Pos, Callback<std::vector<CallHierarchyItem>> CB) {
777  auto Action = [File = File.str(), Pos,
778  CB = std::move(CB)](Expected<InputsAndAST> InpAST) mutable {
779  if (!InpAST)
780  return CB(InpAST.takeError());
781  CB(clangd::prepareCallHierarchy(InpAST->AST, Pos, File));
782  };
783  WorkScheduler->runWithAST("CallHierarchy", File, std::move(Action));
784 }
785 
787  const CallHierarchyItem &Item,
788  Callback<std::vector<CallHierarchyIncomingCall>> CB) {
789  WorkScheduler->run("Incoming Calls", "",
790  [CB = std::move(CB), Item, this]() mutable {
791  CB(clangd::incomingCalls(Item, Index));
792  });
793 }
794 
795 void ClangdServer::inlayHints(PathRef File, llvm::Optional<Range> RestrictRange,
796  Callback<std::vector<InlayHint>> CB) {
797  auto Action = [RestrictRange(std::move(RestrictRange)),
798  CB = std::move(CB)](Expected<InputsAndAST> InpAST) mutable {
799  if (!InpAST)
800  return CB(InpAST.takeError());
801  CB(clangd::inlayHints(InpAST->AST, std::move(RestrictRange)));
802  };
803  WorkScheduler->runWithAST("InlayHints", File, std::move(Action), Transient);
804 }
805 
807  // FIXME: Do nothing for now. This will be used for indexing and potentially
808  // invalidating other caches.
809 }
810 
812  llvm::StringRef Query, int Limit,
813  Callback<std::vector<SymbolInformation>> CB) {
814  WorkScheduler->run(
815  "getWorkspaceSymbols", /*Path=*/"",
816  [Query = Query.str(), Limit, CB = std::move(CB), this]() mutable {
817  CB(clangd::getWorkspaceSymbols(Query, Limit, Index,
818  WorkspaceRoot.value_or("")));
819  });
820 }
821 
822 void ClangdServer::documentSymbols(llvm::StringRef File,
823  Callback<std::vector<DocumentSymbol>> CB) {
824  auto Action =
825  [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
826  if (!InpAST)
827  return CB(InpAST.takeError());
828  CB(clangd::getDocumentSymbols(InpAST->AST));
829  };
830  WorkScheduler->runWithAST("DocumentSymbols", File, std::move(Action),
831  Transient);
832 }
833 
834 void ClangdServer::foldingRanges(llvm::StringRef File,
835  Callback<std::vector<FoldingRange>> CB) {
836  auto Action =
837  [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
838  if (!InpAST)
839  return CB(InpAST.takeError());
840  CB(clangd::getFoldingRanges(InpAST->AST));
841  };
842  WorkScheduler->runWithAST("FoldingRanges", File, std::move(Action),
843  Transient);
844 }
845 
846 void ClangdServer::findType(llvm::StringRef File, Position Pos,
847  Callback<std::vector<LocatedSymbol>> CB) {
848  auto Action =
849  [Pos, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
850  if (!InpAST)
851  return CB(InpAST.takeError());
852  CB(clangd::findType(InpAST->AST, Pos));
853  };
854  WorkScheduler->runWithAST("FindType", File, std::move(Action));
855 }
856 
858  PathRef File, Position Pos, Callback<std::vector<LocatedSymbol>> CB) {
859  auto Action = [Pos, CB = std::move(CB),
860  this](llvm::Expected<InputsAndAST> InpAST) mutable {
861  if (!InpAST)
862  return CB(InpAST.takeError());
863  CB(clangd::findImplementations(InpAST->AST, Pos, Index));
864  };
865 
866  WorkScheduler->runWithAST("Implementations", File, std::move(Action));
867 }
868 
871  auto Action = [Pos, Limit, CB = std::move(CB),
872  this](llvm::Expected<InputsAndAST> InpAST) mutable {
873  if (!InpAST)
874  return CB(InpAST.takeError());
875  CB(clangd::findReferences(InpAST->AST, Pos, Limit, Index));
876  };
877 
878  WorkScheduler->runWithAST("References", File, std::move(Action));
879 }
880 
882  Callback<std::vector<SymbolDetails>> CB) {
883  auto Action =
884  [Pos, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
885  if (!InpAST)
886  return CB(InpAST.takeError());
887  CB(clangd::getSymbolInfo(InpAST->AST, Pos));
888  };
889 
890  WorkScheduler->runWithAST("SymbolInfo", File, std::move(Action));
891 }
892 
894  const std::vector<Position> &Positions,
895  Callback<std::vector<SelectionRange>> CB) {
896  auto Action = [Positions, CB = std::move(CB)](
897  llvm::Expected<InputsAndAST> InpAST) mutable {
898  if (!InpAST)
899  return CB(InpAST.takeError());
900  std::vector<SelectionRange> Result;
901  for (const auto &Pos : Positions) {
902  if (auto Range = clangd::getSemanticRanges(InpAST->AST, Pos))
903  Result.push_back(std::move(*Range));
904  else
905  return CB(Range.takeError());
906  }
907  CB(std::move(Result));
908  };
909  WorkScheduler->runWithAST("SemanticRanges", File, std::move(Action));
910 }
911 
913  Callback<std::vector<DocumentLink>> CB) {
914  auto Action =
915  [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
916  if (!InpAST)
917  return CB(InpAST.takeError());
918  CB(clangd::getDocumentLinks(InpAST->AST));
919  };
920  WorkScheduler->runWithAST("DocumentLinks", File, std::move(Action),
921  Transient);
922 }
923 
925  PathRef File, Callback<std::vector<HighlightingToken>> CB) {
926  auto Action =
927  [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
928  if (!InpAST)
929  return CB(InpAST.takeError());
930  CB(clangd::getSemanticHighlightings(InpAST->AST));
931  };
932  WorkScheduler->runWithAST("SemanticHighlights", File, std::move(Action),
933  Transient);
934 }
935 
936 void ClangdServer::getAST(PathRef File, llvm::Optional<Range> R,
937  Callback<llvm::Optional<ASTNode>> CB) {
938  auto Action =
939  [R, CB(std::move(CB))](llvm::Expected<InputsAndAST> Inputs) mutable {
940  if (!Inputs)
941  return CB(Inputs.takeError());
942  if (!R) {
943  // It's safe to pass in the TU, as dumpAST() does not
944  // deserialize the preamble.
945  auto Node = DynTypedNode::create(
946  *Inputs->AST.getASTContext().getTranslationUnitDecl());
947  return CB(dumpAST(Node, Inputs->AST.getTokens(),
948  Inputs->AST.getASTContext()));
949  }
950  unsigned Start, End;
951  if (auto Offset = positionToOffset(Inputs->Inputs.Contents, R->start))
952  Start = *Offset;
953  else
954  return CB(Offset.takeError());
955  if (auto Offset = positionToOffset(Inputs->Inputs.Contents, R->end))
956  End = *Offset;
957  else
958  return CB(Offset.takeError());
959  bool Success = SelectionTree::createEach(
960  Inputs->AST.getASTContext(), Inputs->AST.getTokens(), Start, End,
961  [&](SelectionTree T) {
962  if (const SelectionTree::Node *N = T.commonAncestor()) {
963  CB(dumpAST(N->ASTNode, Inputs->AST.getTokens(),
964  Inputs->AST.getASTContext()));
965  return true;
966  }
967  return false;
968  });
969  if (!Success)
970  CB(llvm::None);
971  };
972  WorkScheduler->runWithAST("GetAST", File, std::move(Action));
973 }
974 
975 void ClangdServer::customAction(PathRef File, llvm::StringRef Name,
977  WorkScheduler->runWithAST(Name, File, std::move(Action));
978 }
979 
980 void ClangdServer::diagnostics(PathRef File, Callback<std::vector<Diag>> CB) {
981  auto Action =
982  [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
983  if (!InpAST)
984  return CB(InpAST.takeError());
985  if (auto Diags = InpAST->AST.getDiagnostics())
986  return CB(*Diags);
987  // FIXME: Use ServerCancelled error once it is settled in LSP-3.17.
988  return CB(llvm::make_error<LSPError>("server is busy parsing includes",
989  ErrorCode::InternalError));
990  };
991 
992  WorkScheduler->runWithAST("Diagnostics", File, std::move(Action));
993 }
994 
995 llvm::StringMap<TUScheduler::FileStats> ClangdServer::fileStats() const {
996  return WorkScheduler->fileStats();
997 }
998 
999 LLVM_NODISCARD bool
1000 ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
1001  // Order is important here: we don't want to block on A and then B,
1002  // if B might schedule work on A.
1003 
1004  // Nothing else can schedule work on TUScheduler, because it's not threadsafe
1005  // and we're blocking the main thread.
1006  if (!WorkScheduler->blockUntilIdle(timeoutSeconds(TimeoutSeconds)))
1007  return false;
1008  // TUScheduler is the only thing that starts background indexing work.
1009  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
1010  return false;
1011 
1012  // Unfortunately we don't have strict topological order between the rest of
1013  // the components. E.g. CDB broadcast triggers backrgound indexing.
1014  // This queries the CDB which may discover new work if disk has changed.
1015  //
1016  // So try each one a few times in a loop.
1017  // If there are no tricky interactions then all after the first are no-ops.
1018  // Then on the last iteration, verify they're idle without waiting.
1019  //
1020  // There's a small chance they're juggling work and we didn't catch them :-(
1021  for (llvm::Optional<double> Timeout :
1022  {TimeoutSeconds, TimeoutSeconds, llvm::Optional<double>(0)}) {
1023  if (!CDB.blockUntilIdle(timeoutSeconds(Timeout)))
1024  return false;
1025  if (BackgroundIdx && !BackgroundIdx->blockUntilIdleForTest(Timeout))
1026  return false;
1027  if (FeatureModules && llvm::any_of(*FeatureModules, [&](FeatureModule &M) {
1028  return !M.blockUntilIdle(timeoutSeconds(Timeout));
1029  }))
1030  return false;
1031  }
1032 
1033  assert(WorkScheduler->blockUntilIdle(Deadline::zero()) &&
1034  "Something scheduled work while we're blocking the main thread!");
1035  return true;
1036 }
1037 
1038 void ClangdServer::profile(MemoryTree &MT) const {
1039  if (DynamicIdx)
1040  DynamicIdx->profile(MT.child("dynamic_index"));
1041  if (BackgroundIdx)
1042  BackgroundIdx->profile(MT.child("background_index"));
1043  WorkScheduler->profile(MT.child("tuscheduler"));
1044 }
1045 } // namespace clangd
1046 } // namespace clang
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:555
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
WantDiags
WantDiagnostics WantDiags
Definition: TUScheduler.cpp:494
clang::clangd::BackgroundQueue::Stats
Definition: Background.h:85
XRefs.h
Loc
SourceLocation Loc
Definition: KernelNameRestrictionCheck.cpp:45
clang::clangd::incomingCalls
std::vector< CallHierarchyIncomingCall > incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index)
Definition: XRefs.cpp:2098
Base
std::unique_ptr< GlobalCompilationDatabase > Base
Definition: GlobalCompilationDatabaseTests.cpp:85
clang::clangd::MemoryTree::child
MemoryTree & child(llvm::StringLiteral Name)
No copy of the Name.
Definition: MemoryTree.h:39
clang::clangd::BackgroundIndexStorage::createDiskBackedStorageFactory
static Factory createDiskBackedStorageFactory(std::function< llvm::Optional< ProjectInfo >(PathRef)> GetProjectInfo)
Definition: BackgroundIndexStorage.cpp:144
clang::clangd::timeoutSeconds
Deadline timeoutSeconds(llvm::Optional< double > Seconds)
Makes a deadline from a timeout in seconds. None means wait forever.
Definition: Threading.cpp:112
clang::clangd::getFoldingRanges
llvm::Expected< std::vector< FoldingRange > > getFoldingRanges(ParsedAST &AST)
Returns a list of ranges whose contents might be collapsible in an editor.
Definition: SemanticSelection.cpp:159
clang::clangd::Deadline::infinity
static Deadline infinity()
Definition: Threading.h:50
clang::clangd::Config::AllScopes
bool AllScopes
Whether code completion includes results that are not visible in current scopes.
Definition: Config.h:126
clang::clangd::findReferences
ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit, const SymbolIndex *Index)
Returns references of the symbol at a specified Pos.
Definition: XRefs.cpp:1334
clang::clangd::Edit
A set of edits generated for a single file.
Definition: SourceCode.h:184
clang::clangd::rename
llvm::Expected< RenameResult > rename(const RenameInputs &RInputs)
Renames all occurrences of the symbol.
Definition: Rename.cpp:691
E
const Expr * E
Definition: AvoidBindCheck.cpp:88
CodeComplete.h
clang::clangd::FeatureModule
A FeatureModule contributes a vertical feature to clangd.
Definition: FeatureModule.h:55
clang::clangd::Path
std::string Path
A typedef to represent a file path.
Definition: Path.h:26
clang::clangd::resolveTypeHierarchy
void resolveTypeHierarchy(TypeHierarchyItem &Item, int ResolveLevels, TypeHierarchyDirection Direction, const SymbolIndex *Index)
Definition: XRefs.cpp:2056
Tracer
std::unique_ptr< trace::EventTracer > Tracer
Definition: TraceTests.cpp:161
clang::clangd::error
llvm::Error error(std::error_code EC, const char *Fmt, Ts &&... Vals)
Definition: Logger.h:79
clang::clangd::config::Params::FreshTime
std::chrono::steady_clock::time_point FreshTime
Hint that stale data is OK to improve performance (e.g.
Definition: ConfigProvider.h:40
clang::clangd::Context::current
static const Context & current()
Returns the context for the current thread, creating it if needed.
Definition: Context.cpp:27
FormatStyle
static cl::opt< std::string > FormatStyle("format-style", cl::desc(R"( Style for formatting code around applied fixes: - 'none' (default) turns off formatting - 'file' (literally 'file', not a placeholder) uses .clang-format file in the closest parent directory - '{ <json> }' specifies options inline, e.g. -format-style='{BasedOnStyle: llvm, IndentWidth: 8}' - 'llvm', 'google', 'webkit', 'mozilla' See clang-format documentation for the up-to-date information about formatting styles and options. This option overrides the 'FormatStyle` option in .clang-tidy file, if any. )"), cl::init("none"), cl::cat(ClangTidyCategory))
clang::clangd::InputsAndAST
Definition: TUScheduler.h:37
clang::clangd::findImplementations
std::vector< LocatedSymbol > findImplementations(ParsedAST &AST, Position Pos, const SymbolIndex *Index)
Returns implementations at a specified Pos:
Definition: XRefs.cpp:1281
clang::clangd::Context::clone
Context clone() const
Clone this context object.
Definition: Context.cpp:20
clang::clangd::BackgroundIndex::Options::ContextProvider
std::function< Context(PathRef)> ContextProvider
Definition: Background.h:146
Diagnostics
WantDiagnostics Diagnostics
Definition: TUScheduler.cpp:602
ParseInput
const ParseInputs & ParseInput
Definition: CodeComplete.cpp:1206
clang::clangd::ParsedAST::getASTContext
ASTContext & getASTContext()
Note that the returned ast will not contain decls from the preamble that were not deserialized during...
Definition: ParsedAST.cpp:697
DumpAST.h
clang::clangd::WantDiagnostics::Auto
@ Auto
Diagnostics must not be generated for this snapshot.
clang::clangd::SelectionTree::createEach
static bool createEach(ASTContext &AST, const syntax::TokenBuffer &Tokens, unsigned Begin, unsigned End, llvm::function_ref< bool(SelectionTree)> Func)
Definition: Selection.cpp:1027
clang::clangd::PreambleData::Preamble
PrecompiledPreamble Preamble
Definition: Preamble.h:55
CI
std::unique_ptr< CompilerInvocation > CI
Definition: TUScheduler.cpp:491
clang::clangd::DraftStore::addDraft
std::string addDraft(PathRef File, llvm::StringRef Version, StringRef Contents)
Replace contents of the draft for File with Contents.
Definition: DraftStore.cpp:74
clang::clangd::ClangdServer::findType
void findType(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol >> CB)
Retrieve symbols for types referenced at Pos.
Definition: ClangdServer.cpp:846
clang::clangd::Range::start
Position start
The range's start position.
Definition: Protocol.h:184
clang::clangd::reformatEdit
llvm::Error reformatEdit(Edit &E, const format::FormatStyle &Style)
Formats the edits and code around it according to Style.
Definition: SourceCode.cpp:1054
Preamble.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:936
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:705
Ctx
Context Ctx
Definition: TUScheduler.cpp:495
clang::clangd::ClangdServer::findReferences
void findReferences(PathRef File, Position Pos, uint32_t Limit, Callback< ReferencesResult > CB)
Retrieve locations for symbol references.
Definition: ClangdServer.cpp:869
Trace.h
clang::clangd::Config
Settings that express user/project preferences and control clangd behavior.
Definition: Config.h:45
clang::clangd::config::Provider
A source of configuration fragments.
Definition: ConfigProvider.h:62
clang::clangd::ClangdServer::optsForTest
static Options optsForTest()
Definition: ClangdServer.cpp:154
HeaderSourceSwitch.h
Format.h
FindSymbols.h
clang::clangd::getSemanticRanges
llvm::Expected< SelectionRange > getSemanticRanges(ParsedAST &AST, Position Pos)
Returns the list of all interesting ranges around the Position Pos.
Definition: SemanticSelection.cpp:101
clang::clangd::FileIndex
This manages symbols from files and an in-memory index on all symbols.
Definition: FileIndex.h:109
clang::clangd::GlobalCompilationDatabase
Provides compilation arguments used for parsing C and C++ files.
Definition: GlobalCompilationDatabase.h:34
clang::clangd::FeatureModule::Facilities
Shared server facilities needed by the module to get its work done.
Definition: FeatureModule.h:75
clang::clangd::ClangdServer::documentSymbols
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol >> CB)
Retrieve the symbols within the specified file.
Definition: ClangdServer.cpp:822
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:834
clang::clangd::replacementToEdit
TextEdit replacementToEdit(llvm::StringRef Code, const tooling::Replacement &R)
Definition: SourceCode.cpp:495
clang::clangd::ClangdServer::findImplementations
void findImplementations(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol >> CB)
Retrieve implementations for virtual method.
Definition: ClangdServer.cpp:857
clang::clangd::TUScheduler::Stale
@ Stale
The preamble may be generated from an older version of the file.
Definition: TUScheduler.h:286
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:247
Cancellation.h
Pos
size_t Pos
Definition: NoLintDirectiveHandler.cpp:97
clang::clangd::DraftStore::removeDraft
void removeDraft(PathRef File)
Remove the draft from the store.
Definition: DraftStore.cpp:85
clang::clangd::TUScheduler::StaleOrAbsent
@ StaleOrAbsent
Besides accepting stale preamble, this also allow preamble to be absent (not ready or failed to build...
Definition: TUScheduler.h:289
InlayHints.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:529
clang::clangd::WantDiagnostics
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
Definition: TUScheduler.h:52
Protocol.h
M
const google::protobuf::Message & M
Definition: Server.cpp:309
ThreadsafeFS.h
clang::clangd::findType
std::vector< LocatedSymbol > findType(ParsedAST &AST, Position Pos)
Returns symbols for types referenced at Pos.
Definition: XRefs.cpp:1942
Inputs
ParseInputs Inputs
Definition: TUScheduler.cpp:492
clang::clangd::isCancelled
int isCancelled(const Context &Ctx)
If the current context is within a cancelled task, returns the reason.
Definition: Cancellation.cpp:35
clang::clangd::prepareTweaks
std::vector< std::unique_ptr< Tweak > > prepareTweaks(const Tweak::Selection &S, llvm::function_ref< bool(const Tweak &)> Filter, const FeatureModuleSet *Modules)
Calls prepare() on all tweaks that satisfy the filter, returning those that can run on the selection.
Definition: Tweak.cpp:73
Offset
size_t Offset
Definition: CodeComplete.cpp:1203
clang::clangd::ClangdServer::Options
Definition: ClangdServer.h:95
Rename.h
clang::clangd::Position
Definition: Protocol.h:153
Code
std::string Code
Definition: FindTargetTests.cpp:67
clang::clangd::ParseInputs
Information required to run clang, e.g. to parse AST or do code completion.
Definition: Compiler.h:46
clang::clangd::dumpAST
ASTNode dumpAST(const DynTypedNode &N, const syntax::TokenBuffer &Tokens, const ASTContext &Ctx)
Definition: DumpAST.cpp:401
CanonicalIncludes.h
ns1::ns2::D
@ D
Definition: CategoricalFeature.h:3
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:280
clang::clangd::locateSymbolAt
std::vector< LocatedSymbol > locateSymbolAt(ParsedAST &AST, Position Pos, const SymbolIndex *Index)
Get definition of symbol at a specified Pos.
Definition: XRefs.cpp:760
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:364
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:369
clang::clangd::ErrorCode::InvalidParams
@ InvalidParams
clang::clangd::PreambleData
The parsed preamble and associated data.
Definition: Preamble.h:49
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:30
SemanticSelection.h
clang::clangd::DidChangeWatchedFilesParams
Definition: Protocol.h:756
Logger.h
clang::clangd::DraftStore::getActiveFiles
std::vector< Path > getActiveFiles() const
Definition: DraftStore.cpp:28
clang::clangd::getSymbolInfo
std::vector< SymbolDetails > getSymbolInfo(ParsedAST &AST, Position Pos)
Get info about symbols at Pos.
Definition: XRefs.cpp:1514
clang::clangd::codeComplete
CodeCompleteResult codeComplete(PathRef FileName, Position Pos, const PreambleData *Preamble, const ParseInputs &ParseInput, CodeCompleteOptions Opts, SpeculativeFuzzyFind *SpecFuzzyFind)
Gets code completions at a specified Pos in FileName.
Definition: CodeComplete.cpp:2026
clang::clangd::positionToOffset
llvm::Expected< size_t > positionToOffset(llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength)
Turn a [line, column] pair into an offset in Code.
Definition: SourceCode.cpp:172
clang::clangd::ClangdServer::inlayHints
void inlayHints(PathRef File, llvm::Optional< Range > RestrictRange, Callback< std::vector< InlayHint >>)
Resolve inlay hints for a given document.
Definition: ClangdServer.cpp:795
clang::clangd::ClangdServer::onFileEvent
void onFileEvent(const DidChangeWatchedFilesParams &Params)
Called when an event occurs for a watched file in the workspace.
Definition: ClangdServer.cpp:806
clang::clangd::DraftStore::getDraft
llvm::Optional< Draft > getDraft(PathRef File) const
Definition: DraftStore.cpp:18
clang::clangd::BackgroundIndex::Options::ThreadPoolSize
size_t ThreadPoolSize
Definition: Background.h:138
clang::clangd::config::Provider::getConfig
Config getConfig(const Params &, DiagnosticCallback) const
Build a config based on this provider.
Definition: ConfigProvider.cpp:168
clang::clangd::toDiag
Diag toDiag(const llvm::SMDiagnostic &D, Diag::DiagSource Source)
Definition: Diagnostics.cpp:433
clang::clangd::ClangdServer::semanticHighlights
void semanticHighlights(PathRef File, Callback< std::vector< HighlightingToken >>)
Definition: ClangdServer.cpp:924
clang::clangd::RenameOptions
Definition: Rename.h:22
clang::clangd::vlog
void vlog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:72
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:725
clang::clangd::trace::Metric::Distribution
@ Distribution
A distribution of values with a meaningful mean and count.
Definition: Trace.h:52
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:786
Diagnostics.h
Results
std::vector< CodeCompletionResult > Results
Definition: CodeComplete.cpp:784
clang::clangd::Range::end
Position end
The range's end position.
Definition: Protocol.h:187
clang::clangd::getHover
llvm::Optional< HoverInfo > getHover(ParsedAST &AST, Position Pos, const format::FormatStyle &Style, const SymbolIndex *Index)
Get the hover information when hovering at Pos.
Definition: Hover.cpp:960
Name
Token Name
Definition: MacroToEnumCheck.cpp:89
clang::clangd::indexStandardLibrary
SymbolSlab indexStandardLibrary(llvm::StringRef HeaderSources, std::unique_ptr< CompilerInvocation > CI, const StdLibLocation &Loc, const ThreadsafeFS &TFS)
Definition: StdLib.cpp:208
clang::clangd::SelectionTree
Definition: Selection.h:76
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:501
FeatureModules
FeatureModuleSet FeatureModules
Definition: ClangdLSPServerTests.cpp:73
FileIndex.h
clang::clangd::BackgroundIndex::Options::OnProgress
std::function< void(BackgroundQueue::Stats)> OnProgress
Definition: Background.h:142
clang::clangd::getSemanticHighlightings
std::vector< HighlightingToken > getSemanticHighlightings(ParsedAST &AST)
Definition: SemanticHighlighting.cpp:792
clang::clangd::signatureHelp
SignatureHelp signatureHelp(PathRef FileName, Position Pos, const PreambleData &Preamble, const ParseInputs &ParseInput, MarkupKind DocumentationFormat)
Get signature help at a specified Pos in FileName.
Definition: CodeComplete.cpp:2062
clang::clangd::getDocumentSymbols
llvm::Expected< std::vector< DocumentSymbol > > getDocumentSymbols(ParsedAST &AST)
Retrieves the symbols contained in the "main file" section of an AST in the same order that they appe...
Definition: FindSymbols.cpp:652
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:463
clang::clangd::Config::Completion
struct clang::clangd::Config::@6 Completion
Configures code completion feature.
clang::clangd::getFormatStyleForFile
format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, const ThreadsafeFS &TFS)
Choose the clang-format style we should apply to a certain file.
Definition: SourceCode.cpp:577
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:41
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:29
clang::clangd::log
void log(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:67
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:811
Entry
Definition: Modularize.cpp:427
clang::clangd::BackgroundIndex::Options
Definition: Background.h:135
SourceCode.h
clang::clangd::ClangdServer::documentLinks
void documentLinks(PathRef File, Callback< std::vector< DocumentLink >> CB)
Get all document links in a file.
Definition: ClangdServer.cpp:912
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:113
StdLib.h
clang::clangd::trace::Metric::Counter
@ Counter
An aggregate number whose rate of change over time is meaningful.
Definition: Trace.h:46
clang::clangd::MarkupKind
MarkupKind
Definition: Protocol.h:392
Config.h
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:693
clang::clangd::TypeHierarchyDirection
TypeHierarchyDirection
Definition: Protocol.h:1371
clang::clangd::TypeHierarchyItem
Definition: Protocol.h:1388
clang::clangd::Context::derive
Context derive(const Key< Type > &Key, typename std::decay< Type >::type Value) const &
Derives a child context It is safe to move or destroy a parent context after calling derive().
Definition: Context.h:119
clang::clangd::ClangdServer::Callbacks::onBackgroundIndexProgress
virtual void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats)
Called when background indexing tasks are enqueued/started/completed.
Definition: ClangdServer.h:78
clang::clangd::ClangdServer::Callbacks
Interface with hooks for users of ClangdServer to be notified of events.
Definition: ClangdServer.h:61
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:27
clang::clangd::trace::Metric
Represents measurements of clangd events, e.g.
Definition: Trace.h:38
clang::clangd::ParseOptions
Definition: Compiler.h:41
clang::clangd::ThreadsafeFS::view
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > view(llvm::NoneType CWD) const
Obtain a vfs::FileSystem with an arbitrary initial working directory.
Definition: ThreadsafeFS.h:33
clang::clangd::TUScheduler::Options
Definition: TUScheduler.h:186
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:646
clang::clangd::ClangdServer::signatureHelp
void signatureHelp(PathRef File, Position Pos, MarkupKind DocumentationFormat, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
Definition: ClangdServer.cpp:434
clang::clangd::Range
Definition: Protocol.h:182
C
const Criteria C
Definition: FunctionCognitiveComplexityCheck.cpp:93
SemanticHighlighting.h
MemoryTree.h
clang::clangd::CodeCompleteResult
Definition: CodeComplete.h:238
clang::clangd::CodeCompleteOptions::AlwaysParse
@ AlwaysParse
Block until we can run the parser (e.g.
Definition: CodeComplete.h:110
clang::clangd::config::Params
Describes the context used to evaluate configuration fragments.
Definition: ConfigProvider.h:33
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:881
clang::clangd::ParsedAST::getTokens
const syntax::TokenBuffer & getTokens() const
Tokens recorded while parsing the main file.
Definition: ParsedAST.h:106
ClangdServer.h
clang::clangd::config::Params::Path
llvm::StringRef Path
Absolute path to a source file we're applying the config to.
Definition: ConfigProvider.h:36
clang::clangd::formatIncremental
std::vector< tooling::Replacement > formatIncremental(llvm::StringRef OriginalCode, unsigned OriginalCursor, llvm::StringRef InsertedText, format::FormatStyle Style)
Applies limited formatting around new InsertedText.
Definition: Format.cpp:277
clang::clangd::Diag::ClangdConfig
@ ClangdConfig
Definition: Diagnostics.h:102
TUScheduler.h
clang::clangd::prepareTweak
llvm::Expected< std::unique_ptr< Tweak > > prepareTweak(StringRef ID, const Tweak::Selection &S, const FeatureModuleSet *Modules)
Definition: Tweak.cpp:92
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:270
Diags
CapturedDiags Diags
Definition: ConfigCompileTests.cpp:39
clang::clangd::Tweak
An interface base for small context-sensitive refactoring actions.
Definition: Tweak.h:46
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:893
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:765
clang::clangd::CallHierarchyItem
Represents programming constructs like functions or constructors in the context of call hierarchy.
Definition: Protocol.h:1456
clang::clangd::Config::current
static const Config & current()
Returns the Config of the current Context, or an empty configuration.
Definition: Config.cpp:17
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:737
clang::clangd::getCorrespondingHeaderOrSource
llvm::Optional< Path > getCorrespondingHeaderOrSource(PathRef OriginalFile, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS)
Given a header file, returns the best matching source file, and vice visa.
Definition: HeaderSourceSwitch.cpp:20
clang::clangd::getTypeHierarchy
llvm::Optional< TypeHierarchyItem > getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels, TypeHierarchyDirection Direction, const SymbolIndex *Index, PathRef TUPath)
Get type hierarchy information at Pos.
Definition: XRefs.cpp:2009
clang::clangd::TUScheduler
Handles running tasks for ClangdServer and managing the resources (e.g., preambles and ASTs) for open...
Definition: TUScheduler.h:184
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::DebouncePolicy::fixed
static DebouncePolicy fixed(clock::duration)
A policy that always returns the same duration, useful for tests.
Definition: TUScheduler.cpp:1771
clang::clangd::Config::Key
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
Definition: Config.h:49
Merge.h
clang::clangd::inlayHints
std::vector< InlayHint > inlayHints(ParsedAST &AST, llvm::Optional< Range > RestrictRange)
Compute and return inlay hints for a file.
Definition: InlayHints.cpp:681
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:611
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:69
clang::clangd::elog
void elog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:61
clang::clangd::ClangdServer::~ClangdServer
~ClangdServer()
Definition: ClangdServer.cpp:233
clang::clangd::getDocumentLinks
std::vector< DocumentLink > getDocumentLinks(ParsedAST &AST)
Get all document links.
Definition: XRefs.cpp:844
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:775
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:172
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::prepareCallHierarchy
std::vector< CallHierarchyItem > prepareCallHierarchy(ParsedAST &AST, Position Pos, PathRef TUPath)
Get call hierarchy information at Pos.
Definition: XRefs.cpp:2076
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:751
clang::clangd::FileChangeType::Changed
@ Changed
The file got changed.
clang::clangd::tweakSelection
static llvm::Expected< std::vector< std::unique_ptr< Tweak::Selection > > > tweakSelection(const Range &Sel, const InputsAndAST &AST, llvm::vfs::FileSystem *FS)
Definition: ClangdServer.cpp:591
ParsedAST.h
clang::clangd::findDocumentHighlights
std::vector< DocumentHighlight > findDocumentHighlights(ParsedAST &AST, Position Pos)
Returns highlights for all usages of a symbol at Pos.
Definition: XRefs.cpp:1240
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:288
Action
FieldAction Action
Definition: MemberwiseConstructor.cpp:261
clang::clangd::trace::Span
Records an event whose duration is the lifetime of the Span object.
Definition: Trace.h:143