13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/Path.h"
27 Path =
Path.drop_front(Prefix.size());
32llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
34 llvm::StringMap<time_t>
const &Timestamps) {
35 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> MemFS(
36 new llvm::vfs::InMemoryFileSystem);
37 MemFS->setCurrentWorkingDirectory(
testRoot());
38 for (
auto &FileAndContents : Files) {
39 llvm::StringRef
File = FileAndContents.first();
42 llvm::MemoryBuffer::getMemBufferCopy(FileAndContents.second,
File));
48 llvm::StringRef RelPathPrefix)
50 RelPathPrefix(RelPathPrefix) {
54std::optional<ProjectInfo>
59std::optional<tooling::CompileCommand>
75 llvm::sys::path::append(RelativeFilePath,
FileName);
76 CommandLine.push_back(std::string(RelativeFilePath.str()));
79 return {tooling::CompileCommand(
Directory != llvm::StringRef()
81 : llvm::sys::path::parent_path(
File),
87 return "C:\\clangd-test";
89 return "/clangd-test";
94 assert(llvm::sys::path::is_relative(
File) &&
"FileName should be relative");
96 llvm::SmallString<32> NativeFile =
File;
97 llvm::sys::path::native(NativeFile, Style);
98 llvm::SmallString<32>
Path;
99 llvm::sys::path::append(
Path, Style,
testRoot(), NativeFile);
100 return std::string(
Path.str());
110 llvm::Expected<std::string>
112 llvm::StringRef HintPath)
const override {
114 return error(
"Hint path is not empty and doesn't start with {0}: {1}",
116 if (!Body.consume_front(
"/"))
117 return error(
"Body of an unittest: URI must start with '/'");
118 llvm::SmallString<16>
Path(Body.begin(), Body.end());
119 llvm::sys::path::native(
Path);
125 if (!pathConsumeFront(AbsolutePath,
testRoot()))
126 return error(
"{0} does not start with {1}", AbsolutePath,
testRoot());
128 return URI(Scheme,
"",
129 llvm::sys::path::convert_to_slash(AbsolutePath));
133const char *TestScheme::Scheme =
"unittest";
135static URISchemeRegistry::Add<TestScheme>
X(TestScheme::Scheme,
"Test schema");
std::vector< llvm::StringRef > CommandLine
llvm::StringRef Directory
std::optional< tooling::CompileCommand > getCompileCommand(PathRef File) const override
If there are any known-good commands for building this file, returns one.
MockCompilationDatabase(StringRef Directory=StringRef(), StringRef RelPathPrefix=StringRef())
If Directory is not empty, use that as the Directory field of the CompileCommand, and as project Sour...
std::vector< std::string > ExtraClangFlags
std::optional< ProjectInfo > getProjectInfo(PathRef File) const override
Finds the closest project to File.
static const char * Scheme
llvm::Expected< std::string > getAbsolutePath(llvm::StringRef, llvm::StringRef Body, llvm::StringRef HintPath) const override
Returns the absolute path of the file corresponding to the URI authority+body in the file system.
llvm::Expected< URI > uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override
URIScheme is an extension point for teaching clangd to recognize a custom URI scheme.
A URI describes the location of a source file.
std::string Path
A typedef to represent a file path.
bool pathStartsWith(PathRef Ancestor, PathRef Path, llvm::sys::path::Style Style)
Checks if Ancestor is a proper ancestor of Path.
llvm::Error error(std::error_code EC, const char *Fmt, Ts &&... Vals)
std::string testPath(PathRef File, llvm::sys::path::Style Style)
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > buildTestFS(llvm::StringMap< std::string > const &Files, llvm::StringMap< time_t > const &Timestamps)
volatile int UnittestSchemeAnchorSource
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//