1 //===------------------ ProjectModules.h -------------------------*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
12 #include "support/Function.h"
13 #include "support/Path.h"
14 #include "support/ThreadsafeFS.h"
15 #include "clang/Tooling/CompilationDatabase.h"
22 /// An interface to query the modules information in the project.
23 /// Users should get instances of `ProjectModules` from
24 /// `GlobalCompilationDatabase::getProjectModules(PathRef)`.
26 /// Currently, the modules information includes:
27 /// - Given a source file, what are the required modules.
28 /// - Given a module name and a required source file, what is
29 /// the corresponding source file.
31 /// Note that there can be multiple source files declaring the same module
32 /// in a valid project. Although the language specification requires that
33 /// every module unit's name must be unique in valid program, there can be
34 /// multiple program in a project. And it is technically valid if these program
35 /// doesn't interfere with each other.
37 /// A module name should be in the format:
38 /// `<primary-module-name>[:partition-name]`. So module names covers partitions.
39 class ProjectModules
{
41 using CommandMangler
=
42 llvm::unique_function
<void(tooling::CompileCommand
&, PathRef
) const>;
44 virtual std::vector
<std::string
> getRequiredModules(PathRef File
) = 0;
46 getSourceForModuleName(llvm::StringRef ModuleName
,
47 PathRef RequiredSrcFile
= PathRef()) = 0;
49 virtual void setCommandMangler(CommandMangler Mangler
) {}
51 virtual ~ProjectModules() = default;