9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
17#include "clang/Tooling/ArgumentsAdjusters.h"
18#include "clang/Tooling/CompilationDatabase.h"
19#include "llvm/ADT/FunctionExtras.h"
20#include "llvm/ADT/StringMap.h"
44 virtual std::optional<tooling::CompileCommand>
53 virtual std::unique_ptr<ProjectModules>
86 std::unique_ptr<GlobalCompilationDatabase> Base,
89 std::optional<tooling::CompileCommand>
94 std::unique_ptr<ProjectModules>
103 std::unique_ptr<GlobalCompilationDatabase> BaseOwner;
104 CommandChanged::Subscription BaseChanged;
118 std::chrono::seconds(5);
122 std::chrono::seconds(30);
142 std::optional<tooling::CompileCommand>
149 std::unique_ptr<ProjectModules>
160 mutable llvm::StringMap<DirectoryCache> DirCaches;
161 mutable std::mutex DirCachesMutex;
163 std::vector<DirectoryCache *>
164 getDirectoryCaches(llvm::ArrayRef<llvm::StringRef> Dirs)
const;
166 struct CDBLookupRequest {
169 bool ShouldBroadcast =
false;
172 std::chrono::steady_clock::time_point FreshTime;
173 std::chrono::steady_clock::time_point FreshTimeMissing;
175 struct CDBLookupResult {
176 std::shared_ptr<const tooling::CompilationDatabase> CDB;
179 std::optional<CDBLookupResult> lookupCDB(CDBLookupRequest Request)
const;
181 class BroadcastThread;
182 std::unique_ptr<BroadcastThread> Broadcaster;
185 void broadcastCDB(CDBLookupResult Res)
const;
195 tooling::CompileCommand &, llvm::StringRef)
const>;
206 StringRef
File)
const>;
213 std::vector<std::string> FallbackFlags = {},
217 std::optional<tooling::CompileCommand>
226 std::optional<tooling::CompileCommand> CompilationCommand);
228 std::unique_ptr<ProjectModules>
232 mutable std::mutex Mutex;
233 llvm::StringMap<tooling::CompileCommand>
Commands;
235 std::vector<std::string> FallbackFlags;
static cl::list< std::string > Commands("c", cl::desc("Specify command to run"), cl::value_desc("command"), cl::cat(ClangQueryCategory))
A context is an immutable container for per-request data that must be propagated through layers that ...
A point in time we can wait for.
tooling::CompileCommand getFallbackCommand(PathRef File) const override
Makes a guess at how to build a file.
DelegatingCDB(const GlobalCompilationDatabase *Base, std::optional< std::string > FallbackWorkingDirectory=std::nullopt)
std::optional< tooling::CompileCommand > getCompileCommand(PathRef File) const override
If there are any known-good commands for building this file, returns one.
bool blockUntilIdle(Deadline D) const override
If the CDB does any asynchronous work, wait for it to complete.
std::optional< ProjectInfo > getProjectInfo(PathRef File) const override
Finds the closest project to File.
std::unique_ptr< ProjectModules > getProjectModules(PathRef File) const override
Get the modules in the closest project to File.
bool blockUntilIdle(Deadline Timeout) const override
If the CDB does any asynchronous work, wait for it to complete.
friend class DirectoryBasedGlobalCompilationDatabaseCacheTest
std::unique_ptr< ProjectModules > getProjectModules(PathRef File) const override
Get the modules in the closest project to File.
DirectoryBasedGlobalCompilationDatabase(const Options &Opts)
~DirectoryBasedGlobalCompilationDatabase() override
std::optional< tooling::CompileCommand > getCompileCommand(PathRef File) const override
Scans File's parents looking for compilation databases.
std::optional< ProjectInfo > getProjectInfo(PathRef File) const override
Returns the path to first directory containing a compilation database in File's parents.
An Event<T> allows events of type T to be broadcast to listeners.
std::function< void(const std::vector< std::string > &)> Listener
Provides compilation arguments used for parsing C and C++ files.
std::optional< std::string > FallbackWorkingDirectory
CommandChanged::Subscription watch(CommandChanged::Listener L) const
The callback is notified when files may have new compile commands.
virtual tooling::CompileCommand getFallbackCommand(PathRef File) const
Makes a guess at how to build a file.
GlobalCompilationDatabase(std::optional< std::string > FallbackWorkingDirectory=std::nullopt)
virtual std::optional< ProjectInfo > getProjectInfo(PathRef File) const
Finds the closest project to File.
virtual std::unique_ptr< ProjectModules > getProjectModules(PathRef File) const
Get the modules in the closest project to File.
virtual bool blockUntilIdle(Deadline D) const
If the CDB does any asynchronous work, wait for it to complete.
virtual std::optional< tooling::CompileCommand > getCompileCommand(PathRef File) const =0
If there are any known-good commands for building this file, returns one.
Event< std::vector< std::string > > CommandChanged
CommandChanged OnCommandChanged
virtual ~GlobalCompilationDatabase()=default
llvm::unique_function< void(tooling::CompileCommand &, StringRef File) const > CommandMangler
bool setCompileCommand(PathRef File, std::optional< tooling::CompileCommand > CompilationCommand)
Sets or clears the compilation command for a particular file.
tooling::CompileCommand getFallbackCommand(PathRef File) const override
Makes a guess at how to build a file.
std::optional< tooling::CompileCommand > getCompileCommand(PathRef File) const override
If there are any known-good commands for building this file, returns one.
std::unique_ptr< ProjectModules > getProjectModules(PathRef File) const override
Get the modules in the closest project to File.
OverlayCDB(const GlobalCompilationDatabase *Base, std::vector< std::string > FallbackFlags={}, CommandMangler Mangler=nullptr, std::optional< std::string > FallbackWorkingDirectory=std::nullopt)
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
SystemIncludeExtractorFn getSystemIncludeExtractor(llvm::ArrayRef< std::string > QueryDriverGlobs)
llvm::unique_function< void( tooling::CompileCommand &, llvm::StringRef) const > SystemIncludeExtractorFn
Extracts system include search path from drivers matching QueryDriverGlobs and adds them to the compi...
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void applyFallbackWorkingDirectory(std::optional< std::string > FallbackWorkingDirectory)
std::chrono::steady_clock::duration RevalidateAfter
std::chrono::steady_clock::duration RevalidateMissingAfter
std::function< Context(llvm::StringRef)> ContextProvider
std::optional< Path > CompileCommandsDir
Options(const ThreadsafeFS &TFS)
std::optional< std::string > FallbackWorkingDirectory