clang-tools 10.0.0

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 "FindSymbols.h"
12 #include "Format.h"
13 #include "FormattedString.h"
14 #include "HeaderSourceSwitch.h"
15 #include "Headers.h"
16 #include "Logger.h"
17 #include "ParsedAST.h"
18 #include "Preamble.h"
19 #include "Protocol.h"
20 #include "SemanticHighlighting.h"
21 #include "SemanticSelection.h"
22 #include "SourceCode.h"
23 #include "TUScheduler.h"
24 #include "Trace.h"
25 #include "XRefs.h"
26 #include "index/CanonicalIncludes.h"
27 #include "index/FileIndex.h"
28 #include "index/Merge.h"
29 #include "refactor/Rename.h"
30 #include "refactor/Tweak.h"
31 #include "clang/Format/Format.h"
32 #include "clang/Frontend/CompilerInstance.h"
33 #include "clang/Frontend/CompilerInvocation.h"
34 #include "clang/Lex/Preprocessor.h"
35 #include "clang/Tooling/CompilationDatabase.h"
36 #include "clang/Tooling/Core/Replacement.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/Optional.h"
39 #include "llvm/ADT/STLExtras.h"
40 #include "llvm/ADT/ScopeExit.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/Support/Errc.h"
43 #include "llvm/Support/Error.h"
44 #include "llvm/Support/FileSystem.h"
45 #include "llvm/Support/Path.h"
46 #include "llvm/Support/raw_ostream.h"
47 #include <algorithm>
48 #include <future>
49 #include <memory>
50 #include <mutex>
51 #include <type_traits>
52
53 namespace clang {
54 namespace clangd {
55 namespace {
56
57 // Update the FileIndex with new ASTs and plumb the diagnostics responses.
58 struct UpdateIndexCallbacks : public ParsingCallbacks {
59 UpdateIndexCallbacks(FileIndex *FIndex, DiagnosticsConsumer &DiagConsumer,
60 bool SemanticHighlighting)
61 : FIndex(FIndex), DiagConsumer(DiagConsumer),
62 SemanticHighlighting(SemanticHighlighting) {}
63
64 void onPreambleAST(PathRef Path, ASTContext &Ctx,
65 std::shared_ptr<clang::Preprocessor> PP,
66 const CanonicalIncludes &CanonIncludes) override {
67 if (FIndex)
68 FIndex->updatePreamble(Path, Ctx, std::move(PP), CanonIncludes);
69 }
70
71 void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
72 if (FIndex)
73 FIndex->updateMain(Path, AST);
74
75 std::vector<Diag> Diagnostics = AST.getDiagnostics();
76 std::vector<HighlightingToken> Highlightings;
77 if (SemanticHighlighting)
78 Highlightings = getSemanticHighlightings(AST);
79
80 Publish([&]() {
81 DiagConsumer.onDiagnosticsReady(Path, std::move(Diagnostics));
82 if (SemanticHighlighting)
83 DiagConsumer.onHighlightingsReady(Path, std::move(Highlightings));
84 });
85 }
86
87 void onFailedAST(PathRef Path, std::vector<Diag> Diags,
88 PublishFn Publish) override {
89 Publish([&]() { DiagConsumer.onDiagnosticsReady(Path, Diags); });
90 }
91
92 void onFileUpdated(PathRef File, const TUStatus &Status) override {
93 DiagConsumer.onFileUpdated(File, Status);
94 }
95
96 private:
97 FileIndex *FIndex;
98 DiagnosticsConsumer &DiagConsumer;
99 bool SemanticHighlighting;
100 };
101 } // namespace
102
103 ClangdServer::Options ClangdServer::optsForTest() {
104 ClangdServer::Options Opts;
105 Opts.UpdateDebounce = std::chrono::steady_clock::duration::zero(); // Faster!
106 Opts.StorePreamblesInMemory = true;
107 Opts.AsyncThreadsCount = 4; // Consistent!
108 Opts.SemanticHighlighting = true;
109 return Opts;
110 }
111
112 ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
113 const FileSystemProvider &FSProvider,
114 DiagnosticsConsumer &DiagConsumer,
115 const Options &Opts)
116 : FSProvider(FSProvider),
117 DynamicIdx(Opts.BuildDynamicSymbolIndex
118 ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex)
119 : nullptr),
120 GetClangTidyOptions(Opts.GetClangTidyOptions),
121 SuggestMissingIncludes(Opts.SuggestMissingIncludes),
122 CrossFileRename(Opts.CrossFileRename), TweakFilter(Opts.TweakFilter),
123 WorkspaceRoot(Opts.WorkspaceRoot),
124 // Pass a callback into `WorkScheduler` to extract symbols from a newly
125 // parsed file and rebuild the file index synchronously each time an AST
126 // is parsed.
127 // FIXME(ioeric): this can be slow and we may be able to index on less
128 // critical paths.
129 WorkScheduler(
130 CDB, Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
131 std::make_unique<UpdateIndexCallbacks>(DynamicIdx.get(), DiagConsumer,
132 Opts.SemanticHighlighting),
133 Opts.UpdateDebounce, Opts.RetentionPolicy) {
134 // Adds an index to the stack, at higher priority than existing indexes.
135 auto AddIndex = [&](SymbolIndex *Idx) {
136 if (this->Index != nullptr) {
137 MergedIdx.push_back(std::make_unique<MergedIndex>(Idx, this->Index));
138 this->Index = MergedIdx.back().get();
139 } else {
140 this->Index = Idx;
141 }
142 };
143 if (Opts.StaticIndex)
144 AddIndex(Opts.StaticIndex);
145 if (Opts.BackgroundIndex) {
146 BackgroundIdx = std::make_unique<BackgroundIndex>(
147 Context::current().clone(), FSProvider, CDB,
148 BackgroundIndexStorage::createDiskBackedStorageFactory(
149 [&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); }),
150 std::max(Opts.AsyncThreadsCount, 1u));
151 AddIndex(BackgroundIdx.get());
152 }
153 if (DynamicIdx)
154 AddIndex(DynamicIdx.get());
155 }
156
157 void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
158 WantDiagnostics WantDiags) {
159 auto FS = FSProvider.getFileSystem();
160
161 ParseOptions Opts;
162 Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults();
163 // FIXME: call tidy options builder on the worker thread, it can do IO.
164 if (GetClangTidyOptions)
165 Opts.ClangTidyOpts = GetClangTidyOptions(*FS, File);
166 Opts.SuggestMissingIncludes = SuggestMissingIncludes;
167
168 // Compile command is set asynchronously during update, as it can be slow.
169 ParseInputs Inputs;
170 Inputs.FS = FS;
171 Inputs.Contents = Contents;
172 Inputs.Opts = std::move(Opts);
173 Inputs.Index = Index;
174 bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);
175 // If we loaded Foo.h, we want to make sure Foo.cpp is indexed.
176 if (NewFile && BackgroundIdx)
177 BackgroundIdx->boostRelated(File);
178 }
179
180 void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); }
181
182 llvm::StringRef ClangdServer::getDocument(PathRef File) const {
183 return WorkScheduler.getContents(File);
184 }
185
186 void ClangdServer::codeComplete(PathRef File, Position Pos,
187 const clangd::CodeCompleteOptions &Opts,
188 Callback<CodeCompleteResult> CB) {
189 // Copy completion options for passing them to async task handler.
190 auto CodeCompleteOpts = Opts;
191 if (!CodeCompleteOpts.Index) // Respect overridden index.
192 CodeCompleteOpts.Index = Index;
193
194 auto Task = [Pos, FS = FSProvider.getFileSystem(), CodeCompleteOpts,
195 File = File.str(), CB = std::move(CB),
196 this](llvm::Expected<InputsAndPreamble> IP) mutable {
197 if (!IP)
198 return CB(IP.takeError());
199 if (isCancelled())
200 return CB(llvm::make_error<CancelledError>());
201
202 llvm::Optional<SpeculativeFuzzyFind> SpecFuzzyFind;
203 if (!IP->Preamble) {
204 // No speculation in Fallback mode, as it's supposed to be much faster
205 // without compiling.
206 vlog("Build for file {0} is not ready. Enter fallback mode.", File);
207 } else {
208 if (CodeCompleteOpts.Index && CodeCompleteOpts.SpeculativeIndexRequest) {
209 SpecFuzzyFind.emplace();
210 {
211 std::lock_guard<std::mutex> Lock(
212 CachedCompletionFuzzyFindRequestMutex);
213 SpecFuzzyFind->CachedReq =
214 CachedCompletionFuzzyFindRequestByFile[File];
215 }
216 }
217 }
218 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check
219 // both the old and the new version in case only one of them matches.
220 CodeCompleteResult Result = clangd::codeComplete(
221 File, IP->Command, IP->Preamble, IP->Contents, Pos, FS,
222 CodeCompleteOpts, SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr);
223 {
224 clang::clangd::trace::Span Tracer("Completion results callback");
225 CB(std::move(Result));
226 }
227 if (SpecFuzzyFind && SpecFuzzyFind->NewReq.hasValue()) {
228 std::lock_guard<std::mutex> Lock(CachedCompletionFuzzyFindRequestMutex);
229 CachedCompletionFuzzyFindRequestByFile[File] =
230 SpecFuzzyFind->NewReq.getValue();
231 }
232 // SpecFuzzyFind is only destroyed after speculative fuzzy find finishes.
233 // We don't want `codeComplete` to wait for the async call if it doesn't use
234 // the result (e.g. non-index completion, speculation fails), so that `CB`
235 // is called as soon as results are available.
236 };
237
238 // We use a potentially-stale preamble because latency is critical here.
239 WorkScheduler.runWithPreamble(
240 "CodeComplete", File,
241 (Opts.RunParser == CodeCompleteOptions::AlwaysParse)
242 ? TUScheduler::Stale
243 : TUScheduler::StaleOrAbsent,
244 std::move(Task));
245 }
246
247 void ClangdServer::signatureHelp(PathRef File, Position Pos,
248 Callback<SignatureHelp> CB) {
249
250 auto Action = [Pos, FS = FSProvider.getFileSystem(), File = File.str(),
251 CB = std::move(CB),
252 this](llvm::Expected<InputsAndPreamble> IP) mutable {
253 if (!IP)
254 return CB(IP.takeError());
255
256 auto PreambleData = IP->Preamble;
257 CB(clangd::signatureHelp(File, IP->Command, PreambleData, IP->Contents, Pos,
258 FS, Index));
259 };
260
261 // Unlike code completion, we wait for an up-to-date preamble here.
262 // Signature help is often triggered after code completion. If the code
263 // completion inserted a header to make the symbol available, then using
264 // the old preamble would yield useless results.
265 WorkScheduler.runWithPreamble("SignatureHelp", File, TUScheduler::Consistent,
266 std::move(Action));
267 }
268
269 llvm::Expected<tooling::Replacements>
270 ClangdServer::formatRange(llvm::StringRef Code, PathRef File, Range Rng) {
271 llvm::Expected<size_t> Begin = positionToOffset(Code, Rng.start);
272 if (!Begin)
273 return Begin.takeError();
274 llvm::Expected<size_t> End = positionToOffset(Code, Rng.end);
275 if (!End)
276 return End.takeError();
277 return formatCode(Code, File, {tooling::Range(*Begin, *End - *Begin)});
278 }
279
280 llvm::Expected<tooling::Replacements>
281 ClangdServer::formatFile(llvm::StringRef Code, PathRef File) {
282 // Format everything.
283 return formatCode(Code, File, {tooling::Range(0, Code.size())});
284 }
285
286 llvm::Expected<std::vector<TextEdit>>
287 ClangdServer::formatOnType(llvm::StringRef Code, PathRef File, Position Pos,
288 StringRef TriggerText) {
289 llvm::Expected<size_t> CursorPos = positionToOffset(Code, Pos);
290 if (!CursorPos)
291 return CursorPos.takeError();
292 auto FS = FSProvider.getFileSystem();
293 auto Style = format::getStyle(format::DefaultFormatStyle, File,
294 format::DefaultFallbackStyle, Code, FS.get());
295 if (!Style)
296 return Style.takeError();
297
298 std::vector<TextEdit> Result;
299 for (const tooling::Replacement &R :
300 formatIncremental(Code, *CursorPos, TriggerText, *Style))
301 Result.push_back(replacementToEdit(Code, R));
302 return Result;
303 }
304
305 void ClangdServer::prepareRename(PathRef File, Position Pos,
306 Callback<llvm::Optional<Range>> CB) {
307 auto Action = [Pos, File = File.str(), CB = std::move(CB),
308 this](llvm::Expected<InputsAndAST> InpAST) mutable {
309 if (!InpAST)
310 return CB(InpAST.takeError());
311 auto &AST = InpAST->AST;
312 const auto &SM = AST.getSourceManager();
313 SourceLocation Loc =
314 SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
315 Pos, AST.getSourceManager(), AST.getLangOpts()));
316 auto Range = getTokenRange(SM, AST.getLangOpts(), Loc);
317 if (!Range)
318 return CB(llvm::None); // "rename" is not valid at the position.
319
320 if (CrossFileRename)
321 // FIXME: we now assume cross-file rename always succeeds, revisit this.
322 return CB(*Range);
323
324 // Performing the local rename isn't substantially more expensive than
325 // doing an AST-based check, so we just rename and throw away the results.
326 auto Changes = clangd::rename({Pos, "dummy", AST, File, Index,
327 /*AllowCrossFile=*/false,
328 /*GetDirtyBuffer=*/nullptr});
329 if (!Changes) {
330 // LSP says to return null on failure, but that will result in a generic
331 // failure message. If we send an LSP error response, clients can surface
332 // the message to users (VSCode does).
333 return CB(Changes.takeError());
334 }
335 return CB(*Range);
336 };
337 WorkScheduler.runWithAST("PrepareRename", File, std::move(Action));
338 }
339
340 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
341 bool WantFormat, Callback<FileEdits> CB) {
342 // A snapshot of all file dirty buffers.
343 llvm::StringMap<std::string> Snapshot = WorkScheduler.getAllFileContents();
344 auto Action = [File = File.str(), NewName = NewName.str(), Pos, WantFormat,
345 CB = std::move(CB), Snapshot = std::move(Snapshot),
346 this](llvm::Expected<InputsAndAST> InpAST) mutable {
347 if (!InpAST)
348 return CB(InpAST.takeError());
349 auto GetDirtyBuffer =
350 [&Snapshot](PathRef AbsPath) -> llvm::Optional<std::string> {
351 auto It = Snapshot.find(AbsPath);
352 if (It == Snapshot.end())
353 return llvm::None;
354 return It->second;
355 };
356 auto Edits = clangd::rename({Pos, NewName, InpAST->AST, File, Index,
357 CrossFileRename, GetDirtyBuffer});
358 if (!Edits)
359 return CB(Edits.takeError());
360
361 if (WantFormat) {
362 auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
363 InpAST->Inputs.FS.get());
364 llvm::Error Err = llvm::Error::success();
365 for (auto &E : *Edits)
366 Err =
367 llvm::joinErrors(reformatEdit(E.getValue(), Style), std::move(Err));
368
369 if (Err)
370 return CB(std::move(Err));
371 }
372 return CB(std::move(*Edits));
373 };
374 WorkScheduler.runWithAST("Rename", File, std::move(Action));
375 }
376
377 static llvm::Expected<Tweak::Selection>
378 tweakSelection(const Range &Sel, const InputsAndAST &AST) {
379 auto Begin = positionToOffset(AST.Inputs.Contents, Sel.start);
380 if (!Begin)
381 return Begin.takeError();
382 auto End = positionToOffset(AST.Inputs.Contents, Sel.end);
383 if (!End)
384 return End.takeError();
385 return Tweak::Selection(AST.Inputs.Index, AST.AST, *Begin, *End);
386 }
387
388 void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
389 Callback<std::vector<TweakRef>> CB) {
390 auto Action = [File = File.str(), Sel, CB = std::move(CB),
391 this](Expected<InputsAndAST> InpAST) mutable {
392 if (!InpAST)
393 return CB(InpAST.takeError());
394 auto Selection = tweakSelection(Sel, *InpAST);
395 if (!Selection)
396 return CB(Selection.takeError());
397 std::vector<TweakRef> Res;
398 for (auto &T : prepareTweaks(*Selection, TweakFilter))
399 Res.push_back({T->id(), T->title(), T->intent()});
400
401 CB(std::move(Res));
402 };
403
404 WorkScheduler.runWithAST("EnumerateTweaks", File, std::move(Action));
405 }
406
407 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
408 Callback<Tweak::Effect> CB) {
409 auto Action =
410 [File = File.str(), Sel, TweakID = TweakID.str(), CB = std::move(CB),
411 FS = FSProvider.getFileSystem()](Expected<InputsAndAST> InpAST) mutable {
412 if (!InpAST)
413 return CB(InpAST.takeError());
414 auto Selection = tweakSelection(Sel, *InpAST);
415 if (!Selection)
416 return CB(Selection.takeError());
417 auto A = prepareTweak(TweakID, *Selection);
418 if (!A)
419 return CB(A.takeError());
420 auto Effect = (*A)->apply(*Selection);
421 if (!Effect)
422 return CB(Effect.takeError());
423 for (auto &It : Effect->ApplyEdits) {
424 Edit &E = It.second;
425 format::FormatStyle Style =
426 getFormatStyleForFile(File, E.InitialCode, FS.get());
427 if (llvm::Error Err = reformatEdit(E, Style))
428 elog("Failed to format {0}: {1}", It.first(), std::move(Err));
429 }
430 return CB(std::move(*Effect));
431 };
432 WorkScheduler.runWithAST("ApplyTweak", File, std::move(Action));
433 }
434
435 void ClangdServer::dumpAST(PathRef File,
436 llvm::unique_function<void(std::string)> Callback) {
437 auto Action = [Callback = std::move(Callback)](
438 llvm::Expected<InputsAndAST> InpAST) mutable {
439 if (!InpAST) {
440 llvm::consumeError(InpAST.takeError());
441 return Callback("<no-ast>");
442 }
443 std::string Result;
444
445 llvm::raw_string_ostream ResultOS(Result);
446 clangd::dumpAST(InpAST->AST, ResultOS);
447 ResultOS.flush();
448
449 Callback(Result);
450 };
451
452 WorkScheduler.runWithAST("DumpAST", File, std::move(Action));
453 }
454
455 void ClangdServer::locateSymbolAt(PathRef File, Position Pos,
456 Callback<std::vector<LocatedSymbol>> CB) {
457 auto Action = [Pos, CB = std::move(CB),
458 this](llvm::Expected<InputsAndAST> InpAST) mutable {
459 if (!InpAST)
460 return CB(InpAST.takeError());
461 CB(clangd::locateSymbolAt(InpAST->AST, Pos, Index));
462 };
463
464 WorkScheduler.runWithAST("Definitions", File, std::move(Action));
465 }
466
467 void ClangdServer::switchSourceHeader(
468 PathRef Path, Callback<llvm::Optional<clangd::Path>> CB) {
469 // We want to return the result as fast as possible, strategy is:
470 // 1) use the file-only heuristic, it requires some IO but it is much
471 // faster than building AST, but it only works when .h/.cc files are in
472 // the same directory.
473 // 2) if 1) fails, we use the AST&Index approach, it is slower but supports
474 // different code layout.
475 if (auto CorrespondingFile =
476 getCorrespondingHeaderOrSource(Path, FSProvider.getFileSystem()))
477 return CB(std::move(CorrespondingFile));
478 auto Action = [Path = Path.str(), CB = std::move(CB),
479 this](llvm::Expected<InputsAndAST> InpAST) mutable {
480 if (!InpAST)
481 return CB(InpAST.takeError());
482 CB(getCorrespondingHeaderOrSource(Path, InpAST->AST, Index));
483 };
484 WorkScheduler.runWithAST("SwitchHeaderSource", Path, std::move(Action));
485 }
486
487 llvm::Expected<tooling::Replacements>
488 ClangdServer::formatCode(llvm::StringRef Code, PathRef File,
489 llvm::ArrayRef<tooling::Range> Ranges) {
490 // Call clang-format.
491 format::FormatStyle Style =
492 getFormatStyleForFile(File, Code, FSProvider.getFileSystem().get());
493 tooling::Replacements IncludeReplaces =
494 format::sortIncludes(Style, Code, Ranges, File);
495 auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces);
496 if (!Changed)
497 return Changed.takeError();
498
499 return IncludeReplaces.merge(format::reformat(
500 Style, *Changed,
501 tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
502 File));
503 }
504
505 void ClangdServer::findDocumentHighlights(
506 PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) {
507 auto Action =
508 [Pos, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
509 if (!InpAST)
510 return CB(InpAST.takeError());
511 CB(clangd::findDocumentHighlights(InpAST->AST, Pos));
512 };
513
514 WorkScheduler.runWithAST("Highlights", File, std::move(Action));
515 }
516
517 void ClangdServer::findHover(PathRef File, Position Pos,
518 Callback<llvm::Optional<HoverInfo>> CB) {
519 auto Action = [File = File.str(), Pos, CB = std::move(CB),
520 this](llvm::Expected<InputsAndAST> InpAST) mutable {
521 if (!InpAST)
522 return CB(InpAST.takeError());
523 format::FormatStyle Style = getFormatStyleForFile(
524 File, InpAST->Inputs.Contents, InpAST->Inputs.FS.get());
525 CB(clangd::getHover(InpAST->AST, Pos, std::move(Style), Index));
526 };
527
528 WorkScheduler.runWithAST("Hover", File, std::move(Action));
529 }
530
531 void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve,
532 TypeHierarchyDirection Direction,
533 Callback<Optional<TypeHierarchyItem>> CB) {
534 auto Action = [File = File.str(), Pos, Resolve, Direction, CB = std::move(CB),
535 this](Expected<InputsAndAST> InpAST) mutable {
536 if (!InpAST)
537 return CB(InpAST.takeError());
538 CB(clangd::getTypeHierarchy(InpAST->AST, Pos, Resolve, Direction, Index,
539 File));
540 };
541
542 WorkScheduler.runWithAST("Type Hierarchy", File, std::move(Action));
543 }
544
545 void ClangdServer::resolveTypeHierarchy(
546 TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction,
547 Callback<llvm::Optional<TypeHierarchyItem>> CB) {
548 clangd::resolveTypeHierarchy(Item, Resolve, Direction, Index);
549 CB(Item);
550 }
551
552 void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
553 // FIXME: Do nothing for now. This will be used for indexing and potentially
554 // invalidating other caches.
555 }
556
557 void ClangdServer::workspaceSymbols(
558 llvm::StringRef Query, int Limit,
559 Callback<std::vector<SymbolInformation>> CB) {
560 WorkScheduler.run(
561 "getWorkspaceSymbols",
562 [Query = Query.str(), Limit, CB = std::move(CB), this]() mutable {
563 CB(clangd::getWorkspaceSymbols(Query, Limit, Index,
564 WorkspaceRoot.getValueOr("")));
565 });
566 }
567
568 void ClangdServer::documentSymbols(llvm::StringRef File,
569 Callback<std::vector<DocumentSymbol>> CB) {
570 auto Action =
571 [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
572 if (!InpAST)
573 return CB(InpAST.takeError());
574 CB(clangd::getDocumentSymbols(InpAST->AST));
575 };
576 WorkScheduler.runWithAST("documentSymbols", File, std::move(Action));
577 }
578
579 void ClangdServer::findReferences(PathRef File, Position Pos, uint32_t Limit,
580 Callback<ReferencesResult> CB) {
581 auto Action = [Pos, Limit, CB = std::move(CB),
582 this](llvm::Expected<InputsAndAST> InpAST) mutable {
583 if (!InpAST)
584 return CB(InpAST.takeError());
585 CB(clangd::findReferences(InpAST->AST, Pos, Limit, Index));
586 };
587
588 WorkScheduler.runWithAST("References", File, std::move(Action));
589 }
590
591 void ClangdServer::symbolInfo(PathRef File, Position Pos,
592 Callback<std::vector<SymbolDetails>> CB) {
593 auto Action =
594 [Pos, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
595 if (!InpAST)
596 return CB(InpAST.takeError());
597 CB(clangd::getSymbolInfo(InpAST->AST, Pos));
598 };
599
600 WorkScheduler.runWithAST("SymbolInfo", File, std::move(Action));
601 }
602
603 void ClangdServer::semanticRanges(PathRef File, Position Pos,
604 Callback<std::vector<Range>> CB) {
605 auto Action =
606 [Pos, CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
607 if (!InpAST)
608 return CB(InpAST.takeError());
609 CB(clangd::getSemanticRanges(InpAST->AST, Pos));
610 };
611 WorkScheduler.runWithAST("SemanticRanges", File, std::move(Action));
612 }
613
614 void ClangdServer::documentLinks(PathRef File,
615 Callback<std::vector<DocumentLink>> CB) {
616 auto Action =
617 [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
618 if (!InpAST)
619 return CB(InpAST.takeError());
620 CB(clangd::getDocumentLinks(InpAST->AST));
621 };
622 WorkScheduler.runWithAST("DocumentLinks", File, std::move(Action));
623 }
624
625 std::vector<std::pair<Path, std::size_t>>
626 ClangdServer::getUsedBytesPerFile() const {
627 return WorkScheduler.getUsedBytesPerFile();
628 }
629
630 LLVM_NODISCARD bool
631 ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
632 return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) &&
633 (!BackgroundIdx ||
634 BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds));
635 }
636
637 } // namespace clangd
638 } // namespace clang
Loc
SourceLocation Loc
&#39;#&#39; location in the include directive
Definition: IncludeOrderCheck.cpp:37
Limit
int Limit
Definition: FindSymbolsTests.cpp:71
FormattedString.h
Code
std::string Code
Definition: FindTargetTests.cpp:67
clang::clangd::WantDiagnostics
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
Definition: TUScheduler.h:47
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:246
clang::clangd::ClangdServer::addDocument
void addDocument(PathRef File, StringRef Contents, WantDiagnostics WD=WantDiagnostics::Auto)
Add a File to the list of tracked C++ files or update the contents if File is already tracked...
Definition: ClangdServer.cpp:157
clang::clangd::getWorkspaceSymbols
llvm::Expected< std::vector< SymbolInformation > > getWorkspaceSymbols(llvm::StringRef Query, int Limit, const SymbolIndex *const Index, llvm::StringRef HintPath)
Searches for the symbols matching Query.
Definition: FindSymbols.cpp:67
Trace.h
Contents
llvm::StringRef Contents
Definition: CodeComplete.cpp:1021
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:186
clang::clangd::Range::start
Position start
The range&#39;s start position.
Definition: Protocol.h:158
clang::clangd::TUScheduler::Stale
The preamble may be generated from an older version of the file.
Definition: TUScheduler.h:214
FindSymbols.h
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:531
clang::clangd::ClangdServer::Options::BackgroundIndex
bool BackgroundIndex
If true, ClangdServer automatically indexes files in the current project on background threads...
Definition: ClangdServer.h:101
Changes
tooling::Replacements Changes
Definition: Format.cpp:108
clang::clangd::MessageType::Error
An error message.
ClangdServer.h
SemanticHighlighting.h
clang::clangd::CodeCompleteResult
Definition: CodeComplete.h:215
clang::clangd::prepareTweak
llvm::Expected< std::unique_ptr< Tweak > > prepareTweak(StringRef ID, const Tweak::Selection &S)
Definition: Tweak.cpp:77
clang::clangd::TUScheduler::blockUntilIdle
bool blockUntilIdle(Deadline D) const
Wait until there are no scheduled or running tasks.
Definition: TUScheduler.cpp:878
clang::clangd::getDocumentLinks
std::vector< DocumentLink > getDocumentLinks(ParsedAST &AST)
Get all document links.
Definition: XRefs.cpp:170
clang::clangd::TUScheduler::remove
void remove(PathRef File)
Remove File from the list of tracked files and schedule removal of its resources. ...
Definition: TUScheduler.cpp:907
clang::clangd::dumpAST
void dumpAST(ParsedAST &AST, llvm::raw_ostream &OS)
For testing/debugging purposes.
Definition: ParsedAST.cpp:213
clang::clangd::ClangdServer::onFileEvent
void onFileEvent(const DidChangeWatchedFilesParams &Params)
Called when an event occurs for a watched file in the workspace.
Definition: ClangdServer.cpp:552
clang::clangd::resolveTypeHierarchy
void resolveTypeHierarchy(TypeHierarchyItem &Item, int ResolveLevels, TypeHierarchyDirection Direction, const SymbolIndex *Index)
Definition: XRefs.cpp:807
clang::clangd::DidChangeWatchedFilesParams
Definition: Protocol.h:583
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:85
clang::clangd::BackgroundIndexStorage::createDiskBackedStorageFactory
static Factory createDiskBackedStorageFactory(std::function< llvm::Optional< ProjectInfo >(PathRef)> GetProjectInfo)
Definition: BackgroundIndexStorage.cpp:146
SourceCode.h
clang::clangd::ClangdServer::ClangdServer
ClangdServer(const GlobalCompilationDatabase &CDB, const FileSystemProvider &FSProvider, DiagnosticsConsumer &DiagConsumer, const Options &Opts)
Creates a new ClangdServer instance.
Definition: ClangdServer.cpp:112
Protocol.h
clang::clangd::FileIndex
This manages symbols from files and an in-memory index on all symbols.
Definition: FileIndex.h:95
clang::clangd::TUScheduler::StaleOrAbsent
Besides accepting stale preamble, this also allow preamble to be absent (not ready or failed to build...
Definition: TUScheduler.h:217
clang::clangd::getBeginningOfIdentifier
SourceLocation getBeginningOfIdentifier(const Position &Pos, const SourceManager &SM, const LangOptions &LangOpts)
Get the beginning SourceLocation at a specified Pos in the main file.
Definition: SourceCode.cpp:277
clang::clangd::ParseOptions::SuggestMissingIncludes
bool SuggestMissingIncludes
Definition: Compiler.h:40
clang::clangd::InputsAndAST::AST
ParsedAST & AST
Definition: TUScheduler.h:36
clang::clangd::Position
Definition: Protocol.h:127
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:23
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::blockUntilIdleForTest
LLVM_NODISCARD bool blockUntilIdleForTest(llvm::Optional< double > TimeoutSeconds=10)
Definition: ClangdServer.cpp:631
FS
MockFSProvider FS
Definition: HeadersTests.cpp:119
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:423
clang::clangd::ClangdServer::optsForTest
static Options optsForTest()
Definition: ClangdServer.cpp:103
clang::clangd::TextDocumentSyncKind::None
Documents should not be synced at all.
clang::clangd::ParseOptions::ClangTidyOpts
tidy::ClangTidyOptions ClangTidyOpts
Definition: Compiler.h:39
clang::clangd::FileSystemProvider
Definition: FSProvider.h:20
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:505
clang::clangd::ClangdServer::Options::AsyncThreadsCount
unsigned AsyncThreadsCount
To process requests asynchronously, ClangdServer spawns worker threads.
Definition: ClangdServer.h:86
clang::clangd::vlog
void vlog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:67
clang::clangd::TUScheduler::update
bool update(PathRef File, ParseInputs Inputs, WantDiagnostics WD)
Schedule an update for File.
Definition: TUScheduler.cpp:888
clang::clangd::Edit::InitialCode
std::string InitialCode
Definition: SourceCode.h:206
clang::clangd::elog
void elog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:56
clang::clangd::ParseInputs::Contents
std::string Contents
Definition: Compiler.h:47
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:407
Headers.h
CanonicalIncludes.h
FSProvider
MockFSProvider FSProvider
Definition: FindSymbolsTests.cpp:67
clang::clangd::tweakSelection
static llvm::Expected< Tweak::Selection > tweakSelection(const Range &Sel, const InputsAndAST &AST)
Definition: ClangdServer.cpp:378
clang::clangd::signatureHelp
SignatureHelp signatureHelp(PathRef FileName, const tooling::CompileCommand &Command, const PreambleData *Preamble, llvm::StringRef Contents, Position Pos, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, const SymbolIndex *Index)
Definition: CodeComplete.cpp:1749
clang::clangd::isCancelled
bool isCancelled(const Context &Ctx)
True if the current context is within a cancelable task which was cancelled.
Definition: Cancellation.cpp:26
Tweak.h
clang::clangd::GlobalCompilationDatabase
Provides compilation arguments used for parsing C and C++ files.
Definition: GlobalCompilationDatabase.h:35
Ctx
Context Ctx
Definition: TUScheduler.cpp:237
clang::clangd::getSymbolInfo
std::vector< SymbolDetails > getSymbolInfo(ParsedAST &AST, Position Pos)
Get info about symbols at Pos.
Definition: XRefs.cpp:519
clang::clangd::ClangdServer::documentLinks
void documentLinks(PathRef File, Callback< std::vector< DocumentLink >> CB)
Get all document links in a file.
Definition: ClangdServer.cpp:614
clang::clangd::getHover
llvm::Optional< HoverInfo > getHover(ParsedAST &AST, Position Pos, format::FormatStyle Style, const SymbolIndex *Index)
Get the hover information when hovering at Pos.
Definition: Hover.cpp:483
clang::clangd::Range
Definition: Protocol.h:156
clang::clangd::SymbolOrigin::AST
CodeComplete.h
Preamble.h
clang::clangd::Context::clone
Context clone() const
Clone this context object.
Definition: Context.cpp:20
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:545
clang::clangd::ParseOptions
Definition: Compiler.h:38
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:155
clang::clangd::ClangdServer::formatOnType
llvm::Expected< std::vector< TextEdit > > formatOnType(StringRef Code, PathRef File, Position Pos, StringRef TriggerText)
Run formatting after TriggerText was typed at Pos in File with content Code.
Definition: ClangdServer.cpp:287
HeaderSourceSwitch.h
Action
llvm::unique_function< void()> Action
Definition: TUScheduler.cpp:234
clang::clangd::ParseInputs::Opts
ParseOptions Opts
Definition: Compiler.h:50
clang::clangd::Path
std::string Path
A typedef to represent a file path.
Definition: Path.h:20
clang::clangd::Context::current
static const Context & current()
Returns the context for the current thread, creating it if needed.
Definition: Context.cpp:27
clang::clangd::InputsAndAST::Inputs
const ParseInputs & Inputs
Definition: TUScheduler.h:35
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:39
clang::clangd::TUScheduler::getUsedBytesPerFile
std::vector< std::pair< Path, std::size_t > > getUsedBytesPerFile() const
Returns estimated memory usage for each of the currently open files.
Definition: TUScheduler.cpp:1020
clang::clangd::TUScheduler::runWithPreamble
void runWithPreamble(llvm::StringRef Name, PathRef File, PreambleConsistency Consistency, Callback< InputsAndPreamble > Action)
Schedule an async read of the preamble.
Definition: TUScheduler.cpp:954
clang::clangd::CodeCompleteOptions::RunParser
enum clang::clangd::CodeCompleteOptions::CodeCompletionParse RunParser
clang::clangd::InputsAndAST
Definition: TUScheduler.h:34
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:467
clang::clangd::ClangdServer::Options::UpdateDebounce
std::chrono::steady_clock::duration UpdateDebounce
Time to wait after a new file version before computing diagnostics.
Definition: ClangdServer.h:125
clang::clangd::getSemanticRanges
llvm::Expected< std::vector< Range > > getSemanticRanges(ParsedAST &AST, Position Pos)
Returns the list of all interesting ranges around the Position Pos.
Definition: SemanticSelection.cpp:29
clang::clangd::ClangdServer::dumpAST
void dumpAST(PathRef File, llvm::unique_function< void(std::string)> Callback)
Only for testing purposes.
Definition: ClangdServer.cpp:435
clang::clangd::getTokenRange
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
Definition: SourceCode.cpp:227
clang::clangd::ClangdServer::documentSymbols
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol >> CB)
Retrieve the symbols within the specified file.
Definition: ClangdServer.cpp:568
Pos
Position Pos
Definition: SourceCode.cpp:772
clang::clangd::findDocumentHighlights
std::vector< DocumentHighlight > findDocumentHighlights(ParsedAST &AST, Position Pos)
Returns highlights for all usages of a symbol at Pos.
Definition: XRefs.cpp:390
Format.h
SemanticSelection.h
clang::clangd::Tweak::Selection
Input to prepare and apply tweaks.
Definition: Tweak.h:49
clang::clangd::ClangdServer::getUsedBytesPerFile
std::vector< std::pair< Path, std::size_t > > getUsedBytesPerFile() const
Returns estimated memory usage for each of the currently open files.
Definition: ClangdServer.cpp:626
clang::clangd::getFormatStyleForFile
format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, llvm::vfs::FileSystem *FS)
Choose the clang-format style we should apply to a certain file.
Definition: SourceCode.cpp:693
clang::clangd::ClangdServer::enumerateTweaks
void enumerateTweaks(PathRef File, Range Sel, Callback< std::vector< TweakRef >> CB)
Enumerate the code tweaks available to the user at a specified point.
Definition: ClangdServer.cpp:388
clang::clangd::codeComplete
CodeCompleteResult codeComplete(PathRef FileName, const tooling::CompileCommand &Command, const PreambleData *Preamble, llvm::StringRef Contents, Position Pos, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, CodeCompleteOptions Opts, SpeculativeFuzzyFind *SpecFuzzyFind)
Definition: CodeComplete.cpp:1731
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:517
clang::clangd::ParseInputs::Index
const SymbolIndex * Index
Definition: Compiler.h:49
clang::clangd::DiagnosticsConsumer
Definition: ClangdServer.h:45
clang::clangd::CodeCompleteOptions::Index
const SymbolIndex * Index
If Index is set, it is used to augment the code completion results.
Definition: CodeComplete.h:103
Logger.h
clang::clangd::ClangdServer::formatRange
llvm::Expected< tooling::Replacements > formatRange(StringRef Code, PathRef File, Range Rng)
Run formatting for Rng inside File with content Code.
Definition: ClangdServer.cpp:270
Merge.h
clang::clangd::CodeCompleteOptions::AlwaysParse
Block until we can run the parser (e.g.
Definition: CodeComplete.h:125
clang::clangd::ParseInputs
Information required to run clang, e.g. to parse AST or do code completion.
Definition: Compiler.h:44
clang::clangd::getCorrespondingHeaderOrSource
llvm::Optional< Path > getCorrespondingHeaderOrSource(const Path &OriginalFile, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS)
Given a header file, returns the best matching source file, and vice visa.
Definition: HeaderSourceSwitch.cpp:19
clang::clangd::ClangdServer::Options::StorePreamblesInMemory
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
Definition: ClangdServer.h:92
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::timeoutSeconds
Deadline timeoutSeconds(llvm::Optional< double > Seconds)
Makes a deadline from a timeout in seconds. None means wait forever.
Definition: Threading.cpp:99
ParsedAST.h
clang::clangd::replacementToEdit
TextEdit replacementToEdit(llvm::StringRef Code, const tooling::Replacement &R)
Definition: SourceCode.cpp:606
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
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:269
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
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:768
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:180
clang::clangd::TUScheduler::runWithAST
void runWithAST(llvm::StringRef Name, PathRef File, Callback< InputsAndAST > Action)
Schedule an async read of the AST.
Definition: TUScheduler.cpp:941
clang::clangd::ClangdServer::prepareRename
void prepareRename(PathRef File, Position Pos, Callback< llvm::Optional< Range >> CB)
Test the validity of a rename operation.
Definition: ClangdServer.cpp:305
clang::clangd::getSemanticHighlightings
std::vector< HighlightingToken > getSemanticHighlightings(ParsedAST &AST)
Definition: SemanticHighlighting.cpp:339
clang::clangd::ClangdServer::getDocument
llvm::StringRef getDocument(PathRef File) const
Get the contents of File, which should have been added.
Definition: ClangdServer.cpp:182
E
const Expr * E
Definition: AvoidBindCheck.cpp:82
clang::clangd::ClangdServer::symbolInfo
void symbolInfo(PathRef File, Position Pos, Callback< std::vector< SymbolDetails >> CB)
Get symbol info for given position.
Definition: ClangdServer.cpp:591
DiagConsumer
IgnoreDiagnostics DiagConsumer
Definition: FindSymbolsTests.cpp:69
clang::clangd::ClangdServer::findReferences
void findReferences(PathRef File, Position Pos, uint32_t Limit, Callback< ReferencesResult > CB)
Retrieve locations for symbol references.
Definition: ClangdServer.cpp:579
clang::clangd::FileChangeType::Changed
The file got changed.
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:455
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:190
clang::clangd::ClangdServer::semanticRanges
void semanticRanges(PathRef File, Position Pos, Callback< std::vector< Range >> CB)
Get semantic ranges around a specified position in a file.
Definition: ClangdServer.cpp:603
clang::clangd::ClangdServer::rename
void rename(PathRef File, Position Pos, llvm::StringRef NewName, bool WantFormat, Callback< FileEdits > CB)
Rename all occurrences of the symbol at the Pos in File to NewName.
Definition: ClangdServer.cpp:340
clang::clangd::ParseInputs::FS
IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
Definition: Compiler.h:46
clang::clangd::PreambleData::Preamble
PrecompiledPreamble Preamble
Definition: Preamble.h:52
clang::tidy::ClangTidyOptions::getDefaults
static ClangTidyOptions getDefaults()
These options are used for all settings that haven&#39;t been overridden by the OptionsProvider.
Definition: ClangTidyOptions.cpp:104
FileIndex.h
Rename.h
clang::clangd::rename
llvm::Expected< FileEdits > rename(const RenameInputs &RInputs)
Renames all occurrences of the symbol.
Definition: Rename.cpp:427
clang::clangd::Range::end
Position end
The range&#39;s end position.
Definition: Protocol.h:161
clang::clangd::ClangdServer::Options
Definition: ClangdServer.h:82
clang::clangd::TUScheduler::getContents
llvm::StringRef getContents(PathRef File) const
Returns the current contents of the buffer for File, per last update().
Definition: TUScheduler.cpp:914
clang::clangd::PreambleData
The parsed preamble and associated data.
Definition: Preamble.h:45
clang::clangd::trace::Span
Records an event whose duration is the lifetime of the Span object.
Definition: Trace.h:81
clang::clangd::ClangdServer::Options::StaticIndex
SymbolIndex * StaticIndex
If set, use this index to augment code completion results.
Definition: ClangdServer.h:104
clang::clangd::CompletionItemKind::File
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:557
clang::clangd::ClangdServer::formatFile
llvm::Expected< tooling::Replacements > formatFile(StringRef Code, PathRef File)
Run formatting for the whole File with content Code.
Definition: ClangdServer.cpp:281
clang::clangd::ClangdServer::signatureHelp
void signatureHelp(PathRef File, Position Pos, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
Definition: ClangdServer.cpp:247
clang::clangd::Edit
A set of edits generated for a single file.
Definition: SourceCode.h:204
TUScheduler.h
clang::clangd::TUScheduler::Consistent
The preamble is generated from the current version of the file.
Definition: TUScheduler.h:206
clang::clangd::TUScheduler::getAllFileContents
llvm::StringMap< std::string > getAllFileContents() const
Returns a snapshot of all file buffer contents, per last update().
Definition: TUScheduler.cpp:923
XRefs.h
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:1057
clang::clangd::ClangdServer::Options::SemanticHighlighting
bool SemanticHighlighting
Enable semantic highlighting features.
Definition: ClangdServer.h:135
clang::clangd::TypeHierarchyDirection
TypeHierarchyDirection
Definition: Protocol.h:1121
clang::clangd::prepareTweaks
std::vector< std::unique_ptr< Tweak > > prepareTweaks(const Tweak::Selection &S, llvm::function_ref< bool(const Tweak &)> Filter)
Calls prepare() on all tweaks that satisfy the filter, returning those that can run on the selection...
Definition: Tweak.cpp:59
clang::clangd::TUScheduler::run
void run(llvm::StringRef Name, llvm::unique_function< void()> Action)
Schedule an async task with no dependencies.
Definition: TUScheduler.cpp:930
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::TypeHierarchyItem
Definition: Protocol.h:1136
clang::clangd::FileSystemProvider::getFileSystem
virtual llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > getFileSystem() const =0
Called by ClangdServer to obtain a vfs::FileSystem to be used for parsing.