clang-tools 23.0.0git
ProjectModules.cpp
Go to the documentation of this file.
1//===------------------ ProjectModules.cpp --------- ------------*- 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 "ProjectModules.h"
10#include "Compiler.h"
11#include "support/Logger.h"
12#include "clang/DependencyScanning/DependencyScanningService.h"
13#include "clang/Tooling/DependencyScanningTool.h"
14#include "clang/Tooling/Tooling.h"
15#include "llvm/ADT/SmallString.h"
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/StringSet.h"
18#include "llvm/Support/CommandLine.h"
19#include "llvm/Support/Path.h"
20#include "llvm/TargetParser/Host.h"
21
22namespace clang::clangd {
23namespace {
24
25llvm::SmallString<128> normalizePath(PathRef Path) {
26 llvm::SmallString<128> Result(Path);
27 llvm::sys::path::remove_dots(Result, /*remove_dot_dot=*/true);
28 llvm::sys::path::native(Result, llvm::sys::path::Style::posix);
29 return Result;
30}
31
32std::string normalizePath(PathRef Path, PathRef WorkingDir) {
33 if (Path.empty())
34 return {};
35
36 llvm::SmallString<128> Result;
37 if (llvm::sys::path::is_absolute(Path) || WorkingDir.empty())
38 Result = Path;
39 else {
40 Result = WorkingDir;
41 llvm::sys::path::append(Result, Path);
42 }
43
44 return normalizePath(Result).str().str();
45}
46
47/// The information related to modules parsed from compile commands.
48/// Including the source file, the module file it produces (if it is a
49/// producer), and the module and the corresponding module files it
50/// requires (if it is a consumer)
51struct ParsedCompileCommandInfo {
52 std::string SourceFile;
53 std::optional<std::string> OutputModuleFile;
54 // Map from required module name to the module file path.
55 llvm::StringMap<std::string> RequiredModuleFiles;
56};
57
58/// Get ParsedCompileCommandInfo by looking at the '--precompile',
59/// '-fmodule-file=' and '-fmodule-file=' commands in the compile command.
60std::optional<ParsedCompileCommandInfo>
61parseCompileCommandInfo(tooling::CompileCommand Cmd, const ThreadsafeFS &TFS) {
62 auto FS = TFS.view(std::nullopt);
63 auto Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
64 ? llvm::cl::TokenizeWindowsCommandLine
65 : llvm::cl::TokenizeGNUCommandLine;
66 tooling::addExpandedResponseFiles(Cmd.CommandLine, Cmd.Directory, Tokenizer,
67 *FS);
68
69 ParsedCompileCommandInfo Result;
70 Result.SourceFile = normalizePath(Cmd.Filename, Cmd.Directory);
71
72 bool SawPrecompile = false;
73 for (size_t I = 1; I < Cmd.CommandLine.size(); ++I) {
74 llvm::StringRef Arg = Cmd.CommandLine[I];
75 if (Arg == "--precompile") {
76 SawPrecompile = true;
77 continue;
78 }
79
80 if (Arg.consume_front("-fmodule-output=")) {
81 Result.OutputModuleFile = normalizePath(Arg, Cmd.Directory);
82 continue;
83 }
84 if (Arg == "-fmodule-output" && I + 1 < Cmd.CommandLine.size()) {
85 Result.OutputModuleFile =
86 normalizePath(Cmd.CommandLine[++I], Cmd.Directory);
87 continue;
88 }
89 if (SawPrecompile && Arg == "-o" && I + 1 < Cmd.CommandLine.size()) {
90 Result.OutputModuleFile =
91 normalizePath(Cmd.CommandLine[++I], Cmd.Directory);
92 continue;
93 }
94 if (SawPrecompile && Arg.starts_with("-o") && Arg.size() > 2) {
95 Result.OutputModuleFile = normalizePath(Arg.drop_front(2), Cmd.Directory);
96 continue;
97 }
98
99 if (!Arg.consume_front("-fmodule-file="))
100 continue;
101
102 auto Sep = Arg.find('=');
103 if (Sep == llvm::StringRef::npos || Sep == 0 || Sep + 1 == Arg.size())
104 continue;
105
106 Result.RequiredModuleFiles[Arg.take_front(Sep)] =
107 normalizePath(Arg.drop_front(Sep + 1), Cmd.Directory);
108 }
109
110 return Result;
111}
112
113std::optional<tooling::CompileCommand>
114getCompileCommandForFile(const clang::tooling::CompilationDatabase &CDB,
115 PathRef FilePath,
116 const ProjectModules::CommandMangler &Mangler) {
117 auto Candidates = CDB.getCompileCommands(FilePath);
118 if (Candidates.empty())
119 return std::nullopt;
120
121 // Choose the first candidates as the compile commands as the file.
122 // Following the same logic with
123 // DirectoryBasedGlobalCompilationDatabase::getCompileCommand.
124 tooling::CompileCommand Cmd = std::move(Candidates.front());
125
126 if (Mangler)
127 Mangler(Cmd, FilePath);
128
129 return Cmd;
130}
131
132/// A scanner to query the dependency information for C++20 Modules.
133///
134/// The scanner can scan a single file with `scan(PathRef)` member function
135/// or scan the whole project with `globalScan(vector<PathRef>)` member
136/// function. See the comments of `globalScan` to see the details.
137///
138/// The ModuleDependencyScanner can get the directly required module names for a
139/// specific source file. Also the ModuleDependencyScanner can get the source
140/// file declaring the primary module interface for a specific module name.
141///
142/// IMPORTANT NOTE: we assume that every module unit is only declared once in a
143/// source file in the project. But the assumption is not strictly true even
144/// besides the invalid projects. The language specification requires that every
145/// module unit should be unique in a valid program. But a project can contain
146/// multiple programs. Then it is valid that we can have multiple source files
147/// declaring the same module in a project as long as these source files don't
148/// interfere with each other.
149class ModuleDependencyScanner {
150public:
151 ModuleDependencyScanner(
152 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
153 const ThreadsafeFS &TFS)
154 : CDB(CDB), Service([&TFS] {
155 dependencies::DependencyScanningServiceOptions Opts;
156 Opts.MakeVFS = [&] { return TFS.view(std::nullopt); };
157 Opts.Mode = dependencies::ScanningMode::CanonicalPreprocessing;
158 Opts.Format = dependencies::ScanningOutputFormat::P1689;
159 return Opts;
160 }()) {}
161
162 /// The scanned modules dependency information for a specific source file.
163 struct ModuleDependencyInfo {
164 /// The name of the module if the file is a module unit.
165 std::optional<std::string> ModuleName;
166 /// A list of names for the modules that the file directly depends.
167 std::vector<std::string> RequiredModules;
168 };
169
170 /// Scanning the single file specified by \param FilePath.
171 std::optional<ModuleDependencyInfo>
172 scan(PathRef FilePath, const ProjectModules::CommandMangler &Mangler);
173
174 /// Scanning every source file in the current project to get the
175 /// <module-name> to <module-unit-source> map.
176 /// TODO: We should find an efficient method to get the <module-name>
177 /// to <module-unit-source> map. We can make it either by providing
178 /// a global module dependency scanner to monitor every file. Or we
179 /// can simply require the build systems (or even the end users)
180 /// to provide the map.
181 void globalScan(const ProjectModules::CommandMangler &Mangler);
182
183 /// Get the source file from the module name. Note that the language
184 /// guarantees all the module names are unique in a valid program.
185 /// This function should only be called after globalScan.
186 ///
187 /// TODO: We should handle the case that there are multiple source files
188 /// declaring the same module.
189 PathRef getSourceForModuleName(llvm::StringRef ModuleName) const;
190
191 /// Return the direct required modules. Indirect required modules are not
192 /// included.
193 std::vector<std::string>
194 getRequiredModules(PathRef File,
195 const ProjectModules::CommandMangler &Mangler);
196
197private:
198 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB;
199
200 // Whether the scanner has scanned the project globally.
201 bool GlobalScanned = false;
202
203 clang::dependencies::DependencyScanningService Service;
204
205 // TODO: Add a scanning cache.
206
207 // Map module name to source file path.
208 llvm::StringMap<std::string> ModuleNameToSource;
209};
210
211std::optional<ModuleDependencyScanner::ModuleDependencyInfo>
212ModuleDependencyScanner::scan(PathRef FilePath,
213 const ProjectModules::CommandMangler &Mangler) {
214 auto Cmd = getCompileCommandForFile(*CDB, FilePath, Mangler);
215 if (!Cmd)
216 return std::nullopt;
217
218 using namespace clang::tooling;
219
220 DependencyScanningTool ScanningTool(Service);
221
222 std::string S;
223 llvm::raw_string_ostream OS(S);
224 DiagnosticOptions DiagOpts;
225 DiagOpts.ShowCarets = false;
226 TextDiagnosticPrinter DiagConsumer(OS, DiagOpts);
227
228 std::optional<P1689Rule> ScanningResult =
229 ScanningTool.getP1689ModuleDependencyFile(*Cmd, Cmd->Directory,
230 DiagConsumer);
231
232 if (!ScanningResult) {
233 elog("Scanning modules dependencies for {0} failed: {1}", FilePath, S);
234 std::string Cmdline;
235 for (auto &Arg : Cmd->CommandLine)
236 Cmdline += Arg + " ";
237 elog("The command line the scanning tool use is: {0}", Cmdline);
238 return std::nullopt;
239 }
240
241 ModuleDependencyInfo Result;
242
243 if (ScanningResult->Provides) {
244 Result.ModuleName = ScanningResult->Provides->ModuleName;
245
246 auto [Iter, Inserted] = ModuleNameToSource.try_emplace(
247 ScanningResult->Provides->ModuleName, FilePath);
248
249 if (!Inserted && Iter->second != FilePath) {
250 elog("Detected multiple source files ({0}, {1}) declaring the same "
251 "module: '{2}'. "
252 "Now clangd may find the wrong source in such case.",
253 Iter->second, FilePath, ScanningResult->Provides->ModuleName);
254 }
255 }
256
257 for (auto &Required : ScanningResult->Requires)
258 Result.RequiredModules.push_back(Required.ModuleName);
259
260 return Result;
261}
262
263void ModuleDependencyScanner::globalScan(
264 const ProjectModules::CommandMangler &Mangler) {
265 if (GlobalScanned)
266 return;
267
268 for (auto &File : CDB->getAllFiles())
269 scan(File, Mangler);
270
271 GlobalScanned = true;
272}
273
274PathRef ModuleDependencyScanner::getSourceForModuleName(
275 llvm::StringRef ModuleName) const {
276 assert(
277 GlobalScanned &&
278 "We should only call getSourceForModuleName after calling globalScan()");
279
280 if (auto It = ModuleNameToSource.find(ModuleName);
281 It != ModuleNameToSource.end())
282 return It->second;
283
284 return {};
285}
286
287std::vector<std::string> ModuleDependencyScanner::getRequiredModules(
289 auto ScanningResult = scan(File, Mangler);
290 if (!ScanningResult)
291 return {};
292
293 return ScanningResult->RequiredModules;
294}
295} // namespace
296
297/// TODO: The existing `ScanningAllProjectModules` is not efficient. See the
298/// comments in ModuleDependencyScanner for detail.
299///
300/// In the future, we wish the build system can provide a well design
301/// compilation database for modules then we can query that new compilation
302/// database directly. Or we need to have a global long-live scanner to detect
303/// the state of each file.
305public:
307 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
308 const ThreadsafeFS &TFS)
309 : Scanner(CDB, TFS) {}
310
311 ~ScanningAllProjectModules() override = default;
312
313 std::vector<std::string> getRequiredModules(PathRef File) override {
314 return Scanner.getRequiredModules(File, Mangler);
315 }
316
317 void setCommandMangler(CommandMangler Mangler) override {
318 this->Mangler = std::move(Mangler);
319 }
320
321 /// RequiredSourceFile is not used intentionally. See the comments of
322 /// ModuleDependencyScanner for detail.
323 std::string getSourceForModuleName(llvm::StringRef ModuleName,
324 PathRef RequiredSourceFile) override {
325 Scanner.globalScan(Mangler);
326 return Scanner.getSourceForModuleName(ModuleName).str();
327 }
328
329 std::string getModuleNameForSource(PathRef File) override {
330 auto ScanningResult = Scanner.scan(File, Mangler);
331 if (!ScanningResult || !ScanningResult->ModuleName)
332 return {};
333
334 return *ScanningResult->ModuleName;
335 }
336
337 // Determining Unique/Multiple needs a global scan; return Unknown for cost
338 // reasons. We will have other ProjectModules implementations can determine
339 // this more efficiently.
340 ModuleNameState getModuleNameState(llvm::StringRef /*ModuleName*/) override {
342 }
343
344private:
345 ModuleDependencyScanner Scanner;
346 CommandMangler Mangler;
347};
348
349/// Reads project module information directly from compile commands.
350///
351/// The key observation is that compile commands may already encode the mapping
352/// between a TU, the module names it imports, and the BMI paths it uses:
353/// - producers may spell the BMI path with `--precompile -o <bmi>` or
354/// `-fmodule-output=<bmi>`
355/// - consumers may spell the mapping from module name to BMI path with
356/// `-fmodule-file=<module>=<bmi>`
357///
358/// When that information is present, we can answer
359/// `getSourceForModuleName(ModuleName, RequiredSourceFile)` by first looking up
360/// the BMI path the consumer TU uses for `ModuleName`, and then mapping that
361/// BMI path back to the module unit source that produced it. This avoids the
362/// older scanning-only approach of guessing the module unit from the module
363/// name alone.
364///
365/// One subtle point is that producer commands alone do not reliably tell us the
366/// module name associated with a BMI path. In practice this backend learns that
367/// association from consumer `-fmodule-file=` entries, and then uses the BMI
368/// path to recover the producer source file. That is why indexing is built from
369/// both producer and consumer commands.
370///
371/// Note that compilation database can be stale, so results from this backend
372/// should be treated as preferred hints rather than unquestionable truth.
373/// The compound layer below validates or falls back when needed.
375public:
377 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
378 const ThreadsafeFS &TFS)
379 : CDB(std::move(CDB)), TFS(TFS) {}
380
381 std::vector<std::string> getRequiredModules(PathRef File) override {
382 auto Parsed = parseFileCommand(File);
383 if (!Parsed)
384 return {};
385
386 std::vector<std::string> Result;
387 Result.reserve(Parsed->RequiredModuleFiles.size());
388 for (const auto &Required : Parsed->RequiredModuleFiles)
389 Result.push_back(Required.getKey().str());
390 return Result;
391 }
392
393 std::string getModuleNameForSource(PathRef File) override {
394 indexProducerCommands();
395 auto It = SourceToModuleName.find(
396 maybeCaseFoldPath(normalizePath(File, /*WorkingDir=*/{})));
397 if (It == SourceToModuleName.end() || It->second.Ambiguous)
398 return {};
399 return It->second.Name;
400 }
401
402 ModuleNameState getModuleNameState(llvm::StringRef ModuleName) override {
403 indexProducerCommands();
404 auto It = ModuleNameToDistinctSources.find(ModuleName);
405 if (It == ModuleNameToDistinctSources.end())
407 return It->second.size() > 1 ? ModuleNameState::Multiple
409 }
410
411 std::string getSourceForModuleName(llvm::StringRef ModuleName,
412 PathRef RequiredSourceFile) override {
413 auto Parsed = parseFileCommand(RequiredSourceFile);
414 if (!Parsed)
415 return {};
416
417 auto It = Parsed->RequiredModuleFiles.find(ModuleName);
418 if (It == Parsed->RequiredModuleFiles.end())
419 return {};
420
421 indexProducerCommands();
422 auto SourceIt = PCMToSource.find(maybeCaseFoldPath(It->second));
423 if (SourceIt == PCMToSource.end())
424 return {};
425
426 return SourceIt->second;
427 }
428
429 void setCommandMangler(CommandMangler Mangler) override {
430 this->Mangler = std::move(Mangler);
431 ProducerCommandsIndexed = false;
432 PCMToSource.clear();
433 ModuleNameToDistinctSources.clear();
434 SourceToModuleName.clear();
435 }
436
437private:
438 /// Parses the compile command for \p File into the module information
439 /// encoded in the command line.
440 std::optional<ParsedCompileCommandInfo> parseFileCommand(PathRef File) const {
441 auto Cmd = getCompileCommandForFile(*CDB, File, Mangler);
442 if (!Cmd)
443 return std::nullopt;
444 return parseCompileCommandInfo(std::move(*Cmd), TFS);
445 }
446
447 /// Builds indexes from producer and consumer compile commands.
448 ///
449 /// Compile commands are parsed once up front. The first pass records which
450 /// source file produces each BMI path. The second pass walks consumer
451 /// commands, uses `-fmodule-file=` information to associate module names with
452 /// those BMI paths, and then records which producer source files are
453 /// referenced for each module name.
454 void indexProducerCommands() {
455 if (ProducerCommandsIndexed)
456 return;
457
458 std::vector<ParsedCompileCommandInfo> ParsedCommands;
459 auto AllFiles = CDB->getAllFiles();
460 ParsedCommands.reserve(AllFiles.size());
461 for (const auto &File : AllFiles) {
462 auto Parsed = parseFileCommand(File);
463 if (!Parsed)
464 continue;
465
466 if (Parsed->OutputModuleFile)
467 PCMToSource[maybeCaseFoldPath(*Parsed->OutputModuleFile)] =
468 Parsed->SourceFile;
469
470 ParsedCommands.push_back(std::move(*Parsed));
471 }
472
473 for (const auto &Parsed : ParsedCommands) {
474 for (const auto &Required : Parsed.RequiredModuleFiles) {
475 auto SourceIt =
476 PCMToSource.find(maybeCaseFoldPath(Required.getValue()));
477 if (SourceIt == PCMToSource.end())
478 continue;
479 ModuleNameToDistinctSources[Required.getKey()].insert(
480 maybeCaseFoldPath(SourceIt->second));
481
482 auto &Recovered =
483 SourceToModuleName[maybeCaseFoldPath(SourceIt->second)];
484 if (Recovered.Name.empty())
485 Recovered.Name = Required.getKey().str();
486 else if (Recovered.Name != Required.getKey()) {
487 if (!Recovered.Ambiguous) {
488 elog("Detected conflicting module names ('{0}' and '{1}') for "
489 "the same module file {2} produced by source {3}",
490 Recovered.Name, Required.getKey(), Required.getValue(),
491 SourceIt->second);
492 }
493 Recovered.Ambiguous = true;
494 }
495 }
496 }
497
498 ProducerCommandsIndexed = true;
499 }
500
501 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB;
502 const ThreadsafeFS &TFS;
503 CommandMangler Mangler;
504 bool ProducerCommandsIndexed = false;
505
506 llvm::StringMap<std::string> PCMToSource;
507
508 using DistinctSourceSet = llvm::StringSet<>;
509 llvm::StringMap<DistinctSourceSet> ModuleNameToDistinctSources;
510
511 struct RecoveredModuleName {
512 std::string Name;
513 bool Ambiguous = false;
514 };
515 llvm::StringMap<RecoveredModuleName> SourceToModuleName;
516};
517
518/// Combines the compile-commands backend with the scanning backend.
519///
520/// For getSourceForModuleName, it prefers compile-command-derived results when
521/// available to avoid scanning the whole project, but validates them against
522/// scanning results to avoid returning stale information. For other queries,
523/// it returns scanning results directly as scanning information is update to
524/// date.
526public:
528 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
529 const ThreadsafeFS &TFS)
530 : CompileCommands(
531 std::make_unique<CompileCommandsProjectModules>(CDB, TFS)),
532 Scanning(
533 std::make_unique<ScanningAllProjectModules>(std::move(CDB), TFS)) {}
534
535 std::vector<std::string> getRequiredModules(PathRef File) override {
536 // Return scanning results directly as it is fast enough and up to date.
537 return Scanning->getRequiredModules(File);
538 }
539
540 std::string getModuleNameForSource(PathRef File) override {
541 // Return scanning results directly as it is fast enough and up to date.
542 return Scanning->getModuleNameForSource(File);
543 }
544
545 std::string getSourceForModuleName(llvm::StringRef ModuleName,
546 PathRef RequiredSourceFile) override {
547 auto FromCompileCommands =
548 CompileCommands->getSourceForModuleName(ModuleName, RequiredSourceFile);
549 // Check if the source still declares the module.
550 // This is to validate compile-command-derived results may be stale and
551 // scan a single file is fast enough. We just don't want to scan the project
552 // entirely.
553 if (!FromCompileCommands.empty() &&
554 Scanning->getModuleNameForSource(FromCompileCommands) == ModuleName)
555 return FromCompileCommands;
556
557 return Scanning->getSourceForModuleName(ModuleName, RequiredSourceFile);
558 }
559
560 ModuleNameState getModuleNameState(llvm::StringRef ModuleName) override {
561 auto FromCompileCommands = CompileCommands->getModuleNameState(ModuleName);
562 if (FromCompileCommands != ModuleNameState::Unknown)
563 return FromCompileCommands;
564 return Scanning->getModuleNameState(ModuleName);
565 }
566
567 void setCommandMangler(CommandMangler Mangler) override {
568 this->Mangler = std::move(Mangler);
569 auto ForwardMangler = [this](tooling::CompileCommand &Command,
570 PathRef CommandPath) {
571 if (this->Mangler)
572 this->Mangler(Command, CommandPath);
573 };
574 CompileCommands->setCommandMangler(ForwardMangler);
575 Scanning->setCommandMangler(std::move(ForwardMangler));
576 }
577
578private:
579 std::unique_ptr<CompileCommandsProjectModules> CompileCommands;
580 std::unique_ptr<ScanningAllProjectModules> Scanning;
581 CommandMangler Mangler;
582};
583
584/// Creates the project-modules facade used by clangd.
585///
586/// The implementation is intentionally layered:
587///
588/// CompoundProjectModules
589/// / \
590/// v v
591/// CompileCommands ScanningAllProjectModules
592/// ProjectModules |
593/// | v
594/// | ModuleDependencyScanner
595/// |
596/// +-- preferred specifically for recovering the source file for a module
597/// | name in the context of a consumer TU, because compile commands
598/// | encode `module name -> BMI -> producer source`
599/// |
600/// +-- scanning remains fallback/validation for stale or missing data
601///
602/// - `CompileCommandsProjectModules` reads module relationships that the build
603/// system already made explicit in compile commands. In particular, it uses
604/// producer-side BMI output paths together with consumer-side
605/// `-fmodule-file=<module>=<bmi>` entries to recover the module unit source a
606/// TU actually depends on. This is the preferred source because it can
607/// distinguish different module producers for the same module name when
608/// different translation units reference different BMIs.
609/// - `ScanningAllProjectModules` derives module information by scanning source
610/// files. It is more expensive, but it can still answer queries that are not
611/// present in compile commands and validate compile-command-derived results.
612/// - `CompoundProjectModules` arbitrates between the two backends on a
613/// per-query basis. Compile commands are especially valuable for
614/// `getSourceForModuleName()` because they preserve the consumer TU's actual
615/// `module name -> BMI` choice. Other queries may still fall back to, or be
616/// validated by, scanning because compile-command information may be
617/// incomplete or stale.
618///
619/// This split keeps the logic simple: compile commands provide precision when
620/// available, while scanning preserves compatibility with projects that have
621/// incomplete module information in their compilation database.
622std::unique_ptr<ProjectModules> getProjectModules(
623 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
624 const ThreadsafeFS &TFS) {
625 return std::make_unique<CompoundProjectModules>(std::move(CDB), TFS);
626}
627
628} // namespace clang::clangd
void elog(const char *Fmt, Ts &&... Vals)
Definition Logger.h:61
Reads project module information directly from compile commands.
CompileCommandsProjectModules(std::shared_ptr< const clang::tooling::CompilationDatabase > CDB, const ThreadsafeFS &TFS)
std::string getModuleNameForSource(PathRef File) override
void setCommandMangler(CommandMangler Mangler) override
std::string getSourceForModuleName(llvm::StringRef ModuleName, PathRef RequiredSourceFile) override
ModuleNameState getModuleNameState(llvm::StringRef ModuleName) override
std::vector< std::string > getRequiredModules(PathRef File) override
std::vector< std::string > getRequiredModules(PathRef File) override
ModuleNameState getModuleNameState(llvm::StringRef ModuleName) override
std::string getModuleNameForSource(PathRef File) override
void setCommandMangler(CommandMangler Mangler) override
std::string getSourceForModuleName(llvm::StringRef ModuleName, PathRef RequiredSourceFile) override
CompoundProjectModules(std::shared_ptr< const clang::tooling::CompilationDatabase > CDB, const ThreadsafeFS &TFS)
An interface to query the modules information in the project.
llvm::unique_function< void(tooling::CompileCommand &, PathRef) const > CommandMangler
TODO: The existing ScanningAllProjectModules is not efficient.
void setCommandMangler(CommandMangler Mangler) override
ScanningAllProjectModules(std::shared_ptr< const clang::tooling::CompilationDatabase > CDB, const ThreadsafeFS &TFS)
std::string getModuleNameForSource(PathRef File) override
std::vector< std::string > getRequiredModules(PathRef File) override
ModuleNameState getModuleNameState(llvm::StringRef) override
std::string getSourceForModuleName(llvm::StringRef ModuleName, PathRef RequiredSourceFile) override
RequiredSourceFile is not used intentionally.
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition AST.cpp:44
std::string maybeCaseFoldPath(PathRef Path)
Definition Path.cpp:18
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition Path.h:29
std::string Path
A typedef to represent a file path.
Definition Path.h:26
std::unique_ptr< ProjectModules > getProjectModules(std::shared_ptr< const clang::tooling::CompilationDatabase > CDB, const ThreadsafeFS &TFS)
Creates the project-modules facade used by clangd.