clang-tools 22.0.0git
Check.cpp
Go to the documentation of this file.
1//===--- Check.cpp - clangd self-diagnostics ------------------------------===//
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// Many basic problems can occur processing a file in clangd, e.g.:
10// - system includes are not found
11// - crash when indexing its AST
12// clangd --check provides a simplified, isolated way to reproduce these,
13// with no editor, LSP, threads, background indexing etc to contend with.
14//
15// One important use case is gathering information for bug reports.
16// Another is reproducing crashes, and checking which setting prevent them.
17//
18// It simulates opening a file (determining compile command, parsing, indexing)
19// and then running features at many locations.
20//
21// Currently it adds some basic logging of progress and results.
22// We should consider extending it to also recognize common symptoms and
23// recommend solutions (e.g. standard library installation issues).
24//
25//===----------------------------------------------------------------------===//
26
27#include "../clang-tidy/ClangTidyModule.h"
28#include "../clang-tidy/ClangTidyModuleRegistry.h"
29#include "../clang-tidy/ClangTidyOptions.h"
30#include "../clang-tidy/GlobList.h"
31#include "ClangdLSPServer.h"
32#include "ClangdServer.h"
33#include "CodeComplete.h"
34#include "CompileCommands.h"
35#include "Compiler.h"
36#include "Config.h"
37#include "ConfigFragment.h"
38#include "ConfigProvider.h"
39#include "Diagnostics.h"
40#include "Feature.h"
42#include "Hover.h"
43#include "InlayHints.h"
44#include "ParsedAST.h"
45#include "Preamble.h"
46#include "Protocol.h"
47#include "Selection.h"
49#include "SourceCode.h"
50#include "TidyProvider.h"
51#include "XRefs.h"
52#include "clang-include-cleaner/Record.h"
53#include "index/FileIndex.h"
54#include "refactor/Tweak.h"
55#include "support/Context.h"
56#include "support/Logger.h"
58#include "support/Trace.h"
59#include "clang/AST/ASTContext.h"
60#include "clang/Basic/Diagnostic.h"
61#include "clang/Basic/LLVM.h"
62#include "clang/Format/Format.h"
63#include "clang/Frontend/CompilerInvocation.h"
64#include "clang/Tooling/CompilationDatabase.h"
65#include "llvm/ADT/ArrayRef.h"
66#include "llvm/ADT/STLExtras.h"
67#include "llvm/ADT/SmallString.h"
68#include "llvm/Support/Chrono.h"
69#include "llvm/Support/CommandLine.h"
70#include "llvm/Support/Path.h"
71#include "llvm/Support/Process.h"
72#include <array>
73#include <chrono>
74#include <cstdint>
75#include <limits>
76#include <memory>
77#include <optional>
78#include <utility>
79#include <vector>
80
81namespace clang {
82namespace clangd {
83namespace {
84
85// These will never be shown in --help, ClangdMain doesn't list the category.
86llvm::cl::opt<std::string> CheckTidyTime{
87 "check-tidy-time",
88 llvm::cl::desc("Print the overhead of checks matching this glob"),
89 llvm::cl::init("")};
90llvm::cl::opt<std::string> CheckFileLines{
91 "check-lines",
92 llvm::cl::desc(
93 "Limits the range of tokens in -check file on which "
94 "various features are tested. Example --check-lines=3-7 restricts "
95 "testing to lines 3 to 7 (inclusive) or --check-lines=5 to restrict "
96 "to one line. Default is testing entire file."),
97 llvm::cl::init("")};
98llvm::cl::opt<bool> CheckLocations{
99 "check-locations",
100 llvm::cl::desc(
101 "Runs certain features (e.g. hover) at each point in the file. "
102 "Somewhat slow."),
103 llvm::cl::init(true)};
104llvm::cl::opt<bool> CheckCompletion{
105 "check-completion",
106 llvm::cl::desc("Run code-completion at each point (slow)"),
107 llvm::cl::init(false)};
108llvm::cl::opt<bool> CheckWarnings{
109 "check-warnings",
110 llvm::cl::desc("Print warnings as well as errors"),
111 llvm::cl::init(false)};
112
113// Print the diagnostics meeting severity threshold, and return count of errors.
114unsigned showErrors(llvm::ArrayRef<Diag> Diags) {
115 unsigned ErrCount = 0;
116 for (const auto &D : Diags) {
117 if (D.Severity >= DiagnosticsEngine::Error || CheckWarnings)
118 elog("[{0}] Line {1}: {2}", D.Name, D.Range.start.line + 1, D.Message);
119 if (D.Severity >= DiagnosticsEngine::Error)
120 ++ErrCount;
121 }
122 return ErrCount;
123}
124
125std::vector<std::string> listTidyChecks(llvm::StringRef Glob) {
126 tidy::GlobList G(Glob);
127 tidy::ClangTidyCheckFactories CTFactories;
128 for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
129 E.instantiate()->addCheckFactories(CTFactories);
130 std::vector<std::string> Result;
131 for (const auto &E : CTFactories)
132 if (G.contains(E.getKey()))
133 Result.push_back(E.getKey().str());
134 llvm::sort(Result);
135 return Result;
136}
137
138// This class is just a linear pipeline whose functions get called in sequence.
139// Each exercises part of clangd's logic on our test file and logs results.
140// Later steps depend on state built in earlier ones (such as the AST).
141// Many steps can fatally fail (return false), then subsequent ones cannot run.
142// Nonfatal failures are logged and tracked in ErrCount.
143class Checker {
144 // from constructor
145 std::string File;
146 ClangdLSPServer::Options Opts;
147 // from buildCommand
148 tooling::CompileCommand Cmd;
149 std::unique_ptr<GlobalCompilationDatabase> BaseCDB;
150 std::unique_ptr<GlobalCompilationDatabase> CDB;
151 // from buildInvocation
152 ParseInputs Inputs;
153 std::unique_ptr<CompilerInvocation> Invocation;
154 format::FormatStyle Style;
155 std::optional<ModulesBuilder> ModulesManager;
156 // from buildAST
157 std::shared_ptr<const PreambleData> Preamble;
158 std::optional<ParsedAST> AST;
159 FileIndex Index;
160
161public:
162 // Number of non-fatal errors seen.
163 unsigned ErrCount = 0;
164
165 Checker(llvm::StringRef File, const ClangdLSPServer::Options &Opts)
166 : File(File), Opts(Opts), Index(/*SupportContainedRefs=*/true) {}
167
168 // Read compilation database and choose a compile command for the file.
169 bool buildCommand(const ThreadsafeFS &TFS) {
170 log("Loading compilation database...");
171 DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
172 if (Opts.StrongWorkspaceMode)
173 CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
174 CDBOpts.CompileCommandsDir =
176 BaseCDB =
177 std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
178 auto Mangler = CommandMangler::detect();
179 Mangler.SystemIncludeExtractor =
180 getSystemIncludeExtractor(llvm::ArrayRef(Opts.QueryDriverGlobs));
181 if (Opts.ResourceDir)
182 Mangler.ResourceDir = *Opts.ResourceDir;
183
184 CDB = std::make_unique<OverlayCDB>(
185 BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler),
186 CDBOpts.FallbackWorkingDirectory);
187
188 if (auto TrueCmd = CDB->getCompileCommand(File)) {
189 Cmd = std::move(*TrueCmd);
190 log("Compile command {0} is: [{1}] {2}",
191 Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic, Cmd.Directory,
192 printArgv(Cmd.CommandLine));
193 } else {
194 Cmd = CDB->getFallbackCommand(File);
195 log("Generic fallback command is: [{0}] {1}", Cmd.Directory,
196 printArgv(Cmd.CommandLine));
197 }
198
199 return true;
200 }
201
202 // Prepare inputs and build CompilerInvocation (parsed compile command).
203 bool buildInvocation(const ThreadsafeFS &TFS,
204 std::optional<std::string> Contents) {
205 StoreDiags CaptureInvocationDiags;
206 std::vector<std::string> CC1Args;
207 Inputs.CompileCommand = Cmd;
208 Inputs.TFS = &TFS;
209 Inputs.ClangTidyProvider = Opts.ClangTidyProvider;
210 Inputs.Opts.PreambleParseForwardingFunctions =
211 Opts.PreambleParseForwardingFunctions;
212 if (Contents) {
213 Inputs.Contents = *Contents;
214 log("Imaginary source file contents:\n{0}", Inputs.Contents);
215 } else {
216 if (auto Contents = TFS.view(std::nullopt)->getBufferForFile(File)) {
217 Inputs.Contents = Contents->get()->getBuffer().str();
218 } else {
219 elog("Couldn't read {0}: {1}", File, Contents.getError().message());
220 return false;
221 }
222 }
223 if (Opts.EnableExperimentalModulesSupport) {
224 if (!ModulesManager)
225 ModulesManager.emplace(*CDB);
226 Inputs.ModulesManager = &*ModulesManager;
227 }
228 log("Parsing command...");
229 Invocation =
230 buildCompilerInvocation(Inputs, CaptureInvocationDiags, &CC1Args);
231 auto InvocationDiags = CaptureInvocationDiags.take();
232 ErrCount += showErrors(InvocationDiags);
233 log("internal (cc1) args are: {0}", printArgv(CC1Args));
234 if (!Invocation) {
235 elog("Failed to parse command line");
236 return false;
237 }
238
239 // FIXME: Check that resource-dir/built-in-headers exist?
240
241 Style = getFormatStyleForFile(File, Inputs.Contents, TFS, false);
242
243 return true;
244 }
245
246 // Build preamble and AST, and index them.
247 bool buildAST() {
248 log("Building preamble...");
249 Preamble = buildPreamble(
250 File, *Invocation, Inputs, /*StoreInMemory=*/true,
251 [&](CapturedASTCtx Ctx,
252 std::shared_ptr<const include_cleaner::PragmaIncludes> PI) {
253 if (!Opts.BuildDynamicSymbolIndex)
254 return;
255 log("Indexing headers...");
256 Index.updatePreamble(File, /*Version=*/"null", Ctx.getASTContext(),
257 Ctx.getPreprocessor(), *PI);
258 });
259 if (!Preamble) {
260 elog("Failed to build preamble");
261 return false;
262 }
263 ErrCount += showErrors(Preamble->Diags);
264
265 log("Building AST...");
266 AST = ParsedAST::build(File, Inputs, std::move(Invocation),
267 /*InvocationDiags=*/std::vector<Diag>{}, Preamble);
268 if (!AST) {
269 elog("Failed to build AST");
270 return false;
271 }
272 ErrCount +=
273 showErrors(AST->getDiagnostics().drop_front(Preamble->Diags.size()));
274
275 if (Opts.BuildDynamicSymbolIndex) {
276 log("Indexing AST...");
277 Index.updateMain(File, *AST);
278 }
279
280 if (!CheckTidyTime.empty()) {
281 if (!CLANGD_TIDY_CHECKS) {
282 elog("-{0} requires -DCLANGD_TIDY_CHECKS!", CheckTidyTime.ArgStr);
283 return false;
284 }
285 #ifndef NDEBUG
286 elog("Timing clang-tidy checks in asserts-mode is not representative!");
287 #endif
288 checkTidyTimes();
289 }
290
291 return true;
292 }
293
294 // For each check foo, we want to build with checks=-* and checks=-*,foo.
295 // (We do a full build rather than just AST matchers to meausre PPCallbacks).
296 //
297 // However, performance has both random noise and systematic changes, such as
298 // step-function slowdowns due to CPU scaling.
299 // We take the median of 5 measurements, and after every check discard the
300 // measurement if the baseline changed by >3%.
301 void checkTidyTimes() {
302 double Stability = 0.03;
303 log("Timing AST build with individual clang-tidy checks (target accuracy "
304 "{0:P0})",
305 Stability);
306
307 using Duration = std::chrono::nanoseconds;
308 // Measure time elapsed by a block of code. Currently: user CPU time.
309 auto Time = [&](auto &&Run) -> Duration {
310 llvm::sys::TimePoint<> Elapsed;
311 std::chrono::nanoseconds UserBegin, UserEnd, System;
312 llvm::sys::Process::GetTimeUsage(Elapsed, UserBegin, System);
313 Run();
314 llvm::sys::Process::GetTimeUsage(Elapsed, UserEnd, System);
315 return UserEnd - UserBegin;
316 };
317 auto Change = [&](Duration Exp, Duration Base) -> double {
318 return (double)(Exp.count() - Base.count()) / Base.count();
319 };
320 // Build ParsedAST with a fixed check glob, and return the time taken.
321 auto Build = [&](llvm::StringRef Checks) -> Duration {
322 TidyProvider CTProvider = [&](tidy::ClangTidyOptions &Opts,
323 llvm::StringRef) {
324 Opts.Checks = Checks.str();
325 };
326 Inputs.ClangTidyProvider = CTProvider;
327 // Sigh, can't reuse the CompilerInvocation.
328 IgnoringDiagConsumer IgnoreDiags;
329 auto Invocation = buildCompilerInvocation(Inputs, IgnoreDiags);
330 Duration Val = Time([&] {
331 ParsedAST::build(File, Inputs, std::move(Invocation), {}, Preamble);
332 });
333 vlog(" Measured {0} ==> {1}", Checks, Val);
334 return Val;
335 };
336 // Measure several times, return the median.
337 auto MedianTime = [&](llvm::StringRef Checks) -> Duration {
338 std::array<Duration, 5> Measurements;
339 for (auto &M : Measurements)
340 M = Build(Checks);
341 llvm::sort(Measurements);
342 return Measurements[Measurements.size() / 2];
343 };
344 Duration Baseline = MedianTime("-*");
345 log(" Baseline = {0}", Baseline);
346 // Attempt to time a check, may update Baseline if it is unstable.
347 auto Measure = [&](llvm::StringRef Check) -> double {
348 for (;;) {
349 Duration Median = MedianTime(("-*," + Check).str());
350 Duration NewBase = MedianTime("-*");
351
352 // Value only usable if baseline is fairly consistent before/after.
353 double DeltaFraction = Change(NewBase, Baseline);
354 Baseline = NewBase;
355 vlog(" Baseline = {0}", Baseline);
356 if (DeltaFraction < -Stability || DeltaFraction > Stability) {
357 elog(" Speed unstable, discarding measurement.");
358 continue;
359 }
360 return Change(Median, Baseline);
361 }
362 };
363
364 for (const auto& Check : listTidyChecks(CheckTidyTime)) {
365 // vlog the check name in case we crash!
366 vlog(" Timing {0}", Check);
367 double Fraction = Measure(Check);
368 log(" {0} = {1:P0}", Check, Fraction);
369 }
370 log("Finished individual clang-tidy checks");
371
372 // Restore old options.
373 Inputs.ClangTidyProvider = Opts.ClangTidyProvider;
374 }
375
376 // Build Inlay Hints for the entire AST or the specified range
377 void buildInlayHints(std::optional<Range> LineRange) {
378 log("Building inlay hints");
379 auto Hints = inlayHints(*AST, LineRange);
380
381 for (const auto &Hint : Hints) {
382 vlog(" {0} {1} [{2}]", Hint.kind, Hint.position, [&] {
383 return llvm::join(llvm::map_range(Hint.label,
384 [&](auto &L) {
385 return llvm::formatv("{{{0}}", L);
386 }),
387 ", ");
388 }());
389 }
390 }
391
392 void buildSemanticHighlighting(std::optional<Range> LineRange) {
393 log("Building semantic highlighting");
394 auto Highlights =
395 getSemanticHighlightings(*AST, /*IncludeInactiveRegionTokens=*/true);
396 for (const auto HL : Highlights)
397 if (!LineRange || LineRange->contains(HL.R))
398 vlog(" {0} {1} {2}", HL.R, HL.Kind, HL.Modifiers);
399 }
400
401 // Run AST-based features at each token in the file.
402 void testLocationFeatures(std::optional<Range> LineRange) {
403 trace::Span Trace("testLocationFeatures");
404 log("Testing features at each token (may be slow in large files)");
405 auto &SM = AST->getSourceManager();
406 auto SpelledTokens = AST->getTokens().spelledTokens(SM.getMainFileID());
407
408 CodeCompleteOptions CCOpts = Opts.CodeComplete;
409 CCOpts.Index = &Index;
410
411 for (const auto &Tok : SpelledTokens) {
412 unsigned Start = AST->getSourceManager().getFileOffset(Tok.location());
413 unsigned End = Start + Tok.length();
414 Position Pos = offsetToPosition(Inputs.Contents, Start);
415
416 if (LineRange && !LineRange->contains(Pos))
417 continue;
418
419 trace::Span Trace("Token");
420 SPAN_ATTACH(Trace, "pos", Pos);
421 SPAN_ATTACH(Trace, "text", Tok.text(AST->getSourceManager()));
422
423 // FIXME: dumping the tokens may leak sensitive code into bug reports.
424 // Add an option to turn this off, once we decide how options work.
425 vlog(" {0} {1}", Pos, Tok.text(AST->getSourceManager()));
426 auto Tree = SelectionTree::createRight(AST->getASTContext(),
427 AST->getTokens(), Start, End);
428 Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree),
429 nullptr);
430 // FS is only populated when applying a tweak, not during prepare as
431 // prepare should not do any I/O to be fast.
432 auto Tweaks =
433 prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);
434 Selection.FS =
435 &AST->getSourceManager().getFileManager().getVirtualFileSystem();
436 for (const auto &T : Tweaks) {
437 auto Result = T->apply(Selection);
438 if (!Result) {
439 elog(" tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());
440 ++ErrCount;
441 } else {
442 vlog(" tweak: {0}", T->id());
443 }
444 }
445 unsigned Definitions = locateSymbolAt(*AST, Pos, &Index).size();
446 vlog(" definition: {0}", Definitions);
447
448 auto Hover = getHover(*AST, Pos, Style, &Index);
449 vlog(" hover: {0}", Hover.has_value());
450
451 unsigned DocHighlights = findDocumentHighlights(*AST, Pos).size();
452 vlog(" documentHighlight: {0}", DocHighlights);
453
454 if (CheckCompletion) {
455 Position EndPos = offsetToPosition(Inputs.Contents, End);
456 auto CC = codeComplete(File, EndPos, Preamble.get(), Inputs, CCOpts);
457 vlog(" code completion: {0}",
458 CC.Completions.empty() ? "<empty>" : CC.Completions[0].Name);
459 }
460 }
461 }
462};
463
464} // namespace
465
466bool check(llvm::StringRef File, const ThreadsafeFS &TFS,
467 const ClangdLSPServer::Options &Opts) {
468 std::optional<Range> LineRange;
469 if (!CheckFileLines.empty()) {
470 uint32_t Begin = 0, End = std::numeric_limits<uint32_t>::max();
471 StringRef RangeStr(CheckFileLines);
472 bool ParseError = RangeStr.consumeInteger(0, Begin);
473 if (RangeStr.empty()) {
474 End = Begin;
475 } else {
476 ParseError |= !RangeStr.consume_front("-");
477 ParseError |= RangeStr.consumeInteger(0, End);
478 }
479 if (ParseError || !RangeStr.empty() || Begin <= 0 || End < Begin) {
480 elog("Invalid --check-lines specified. Use Begin-End format, e.g. 3-17");
481 return false;
482 }
483 LineRange = Range{Position{static_cast<int>(Begin - 1), 0},
484 Position{static_cast<int>(End), 0}};
485 }
486
487 llvm::SmallString<0> FakeFile;
488 std::optional<std::string> Contents;
489 if (File.empty()) {
490 llvm::sys::path::system_temp_directory(false, FakeFile);
491 llvm::sys::path::append(FakeFile, "test.cc");
492 File = FakeFile;
493 Contents = R"cpp(
494 #include <stddef.h>
495 #include <string>
496
497 size_t N = 50;
498 auto xxx = std::string(N, 'x');
499 )cpp";
500 }
501 log("Testing on source file {0}", File);
502
503 class OverrideConfigProvider : public config::Provider {
504 std::vector<config::CompiledFragment>
505 getFragments(const config::Params &,
506 config::DiagnosticCallback Diag) const override {
508 // If we're timing clang-tidy checks, implicitly disabling the slow ones
509 // is counterproductive!
510 if (CheckTidyTime.getNumOccurrences())
511 F.Diagnostics.ClangTidy.FastCheckFilter.emplace("None");
512 return {std::move(F).compile(Diag)};
513 }
514 } OverrideConfig;
515 auto ConfigProvider =
516 config::Provider::combine({Opts.ConfigProvider, &OverrideConfig});
517
519 ConfigProvider.get(), nullptr);
520 WithContext Ctx(ContextProvider(
521 FakeFile.empty()
522 ? File
523 : /*Don't turn on local configs for an arbitrary temp path.*/ ""));
524 Checker C(File, Opts);
525 if (!C.buildCommand(TFS) || !C.buildInvocation(TFS, Contents) ||
526 !C.buildAST())
527 return false;
528 C.buildInlayHints(LineRange);
529 C.buildSemanticHighlighting(LineRange);
530 if (CheckLocations)
531 C.testLocationFeatures(LineRange);
532
533 log("All checks completed, {0} errors", C.ErrCount);
534 return C.ErrCount == 0;
535}
536
537} // namespace clangd
538} // namespace clang
static cl::opt< std::string > Checks("checks", desc(R"( Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
void elog(const char *Fmt, Ts &&... Vals)
Definition Logger.h:61
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
Definition Trace.h:164
static std::function< Context(PathRef)> createConfiguredContextProvider(const config::Provider *Provider, ClangdServer::Callbacks *)
Creates a context provider that loads and installs config.
static std::optional< ParsedAST > build(llvm::StringRef Filename, const ParseInputs &Inputs, std::unique_ptr< clang::CompilerInvocation > CI, llvm::ArrayRef< Diag > CompilerInvocationDiags, std::shared_ptr< const PreambleData > Preamble)
Attempts to run Clang and store the parsed AST.
static SelectionTree createRight(ASTContext &AST, const syntax::TokenBuffer &Tokens, unsigned Begin, unsigned End)
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
WithContext replaces Context::current() with a provided scope.
Definition Context.h:185
A source of configuration fragments.
static std::unique_ptr< Provider > combine(std::vector< const Provider * >)
A provider that includes fragments from all the supplied providers.
Records an event whose duration is the lifetime of the Span object.
Definition Trace.h:143
llvm::function_ref< void(const llvm::SMDiagnostic &)> DiagnosticCallback
Used to report problems in parsing or interpreting a config.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition AST.cpp:45
llvm::unique_function< void(tidy::ClangTidyOptions &, llvm::StringRef) const > TidyProvider
A factory to modify a tidy::ClangTidyOptions.
std::vector< HighlightingToken > getSemanticHighlightings(ParsedAST &AST, bool IncludeInactiveRegionTokens)
SystemIncludeExtractorFn getSystemIncludeExtractor(llvm::ArrayRef< std::string > QueryDriverGlobs)
Position offsetToPosition(llvm::StringRef Code, size_t Offset)
Turn an offset in Code into a [line, column] pair.
std::vector< DocumentHighlight > findDocumentHighlights(ParsedAST &AST, Position Pos)
Returns highlights for all usages of a symbol at Pos.
Definition XRefs.cpp:1282
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, std::vector< std::string > *CC1Args)
Builds compiler invocation that could be used to build AST or preamble.
Definition Compiler.cpp:96
void vlog(const char *Fmt, Ts &&... Vals)
Definition Logger.h:72
std::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:1252
std::vector< LocatedSymbol > locateSymbolAt(ParsedAST &AST, Position Pos, const SymbolIndex *Index)
Get definition of symbol at a specified Pos.
Definition XRefs.cpp:779
std::shared_ptr< const PreambleData > buildPreamble(PathRef FileName, CompilerInvocation CI, const ParseInputs &Inputs, bool StoreInMemory, PreambleParsedCallback PreambleCallback, PreambleBuildStats *Stats)
Build a preamble for the new inputs unless an old one can be reused.
Definition Preamble.cpp:591
void log(const char *Fmt, Ts &&... Vals)
Definition Logger.h:67
std::string printArgv(llvm::ArrayRef< llvm::StringRef > Args)
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:72
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.
bool check(llvm::StringRef File, const ThreadsafeFS &TFS, const ClangdLSPServer::Options &Opts)
Definition Check.cpp:466
void elog(const char *Fmt, Ts &&... Vals)
Definition Logger.h:61
std::vector< InlayHint > inlayHints(ParsedAST &AST, std::optional< Range > RestrictRange, InlayHintOptions HintOptions)
Compute and return inlay hints for a file.
format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, const ThreadsafeFS &TFS, bool FormatFile)
Choose the clang-format style we should apply to a certain file.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
config::Provider * ConfigProvider
Supplies configuration (overrides ClangdServer::ContextProvider).
static CommandMangler detect()
std::optional< std::string > FixedCDBPath
Definition Config.h:59
struct clang::clangd::Config::@347104204155140144054042115114221214347344026246 CompileFlags
Controls how the compile command for the current file is determined.
static const Config & current()
Returns the Config of the current Context, or an empty configuration.
Definition Config.cpp:17
CDBSearchSpec CDBSearch
Where to search for compilation databases for this file's flags.
Definition Config.h:69
A top-level diagnostic that may have Notes and Fixes.
Definition Diagnostics.h:98
Input to prepare and apply tweaks.
Definition Tweak.h:49
std::optional< Located< std::string > > FastCheckFilter
Whether to run checks that may slow down clangd.
A chunk of configuration obtained from a config file, LSP, or elsewhere.
Describes the context used to evaluate configuration fragments.