clang-tools 23.0.0git
ProjectModules.h
Go to the documentation of this file.
1//===------------------ ProjectModules.h -------------------------*- 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#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
11
12#include "support/Function.h"
13#include "support/Path.h"
15#include "clang/Tooling/CompilationDatabase.h"
16
17#include <memory>
18
19namespace clang {
20namespace clangd {
21
22/// An interface to query the modules information in the project.
23/// Users should get instances of `ProjectModules` from
24/// `GlobalCompilationDatabase::getProjectModules(PathRef)`.
25///
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.
30///
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.
36///
37/// A module name should be in the format:
38/// `<primary-module-name>[:partition-name]`. So module names covers partitions.
40public:
46
48 llvm::unique_function<void(tooling::CompileCommand &, PathRef) const>;
49
50 virtual std::vector<std::string> getRequiredModules(PathRef File) = 0;
51 virtual std::string getModuleNameForSource(PathRef File) = 0;
52 virtual std::string getSourceForModuleName(llvm::StringRef ModuleName,
53 PathRef RequiredSrcFile) = 0;
54 virtual ModuleNameState getModuleNameState(llvm::StringRef ModuleName) {
56 }
57
58 virtual void setCommandMangler(CommandMangler Mangler) {}
59
60 virtual ~ProjectModules() = default;
61};
62
63/// Providing modules information for the project by scanning every file.
64std::unique_ptr<ProjectModules> getProjectModules(
65 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
66 const ThreadsafeFS &TFS);
67
68} // namespace clangd
69} // namespace clang
70
71#endif
An interface to query the modules information in the project.
virtual std::string getModuleNameForSource(PathRef File)=0
virtual ModuleNameState getModuleNameState(llvm::StringRef ModuleName)
virtual void setCommandMangler(CommandMangler Mangler)
virtual std::string getSourceForModuleName(llvm::StringRef ModuleName, PathRef RequiredSrcFile)=0
llvm::unique_function< void(tooling::CompileCommand &, PathRef) const > CommandMangler
virtual ~ProjectModules()=default
virtual std::vector< std::string > getRequiredModules(PathRef File)=0
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
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition Path.h:29
std::unique_ptr< ProjectModules > getProjectModules(std::shared_ptr< const clang::tooling::CompilationDatabase > CDB, const ThreadsafeFS &TFS)
Creates the project-modules facade used by clangd.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//