12 #include "llvm/ADT/None.h" 13 #include "llvm/ADT/Optional.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/Support/Errc.h" 16 #include "llvm/Support/Path.h" 21 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
24 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> MemFS(
26 MemFS->setCurrentWorkingDirectory(
testRoot());
27 for (
auto &FileAndContents : Files) {
28 llvm::StringRef File = FileAndContents.first();
30 File, Timestamps.lookup(File),
31 llvm::MemoryBuffer::getMemBufferCopy(FileAndContents.second, File));
37 llvm::StringRef RelPathPrefix)
38 : ExtraClangFlags({
"-ffreestanding"}), Directory(Directory),
39 RelPathPrefix(RelPathPrefix) {
43 llvm::Optional<ProjectInfo>
48 llvm::Optional<tooling::CompileCommand>
53 auto FileName = llvm::sys::path::filename(File);
58 if (RelPathPrefix.empty()) {
63 llvm::SmallString<32> RelativeFilePath(RelPathPrefix);
64 llvm::sys::path::append(RelativeFilePath,
FileName);
68 return {tooling::CompileCommand(Directory != llvm::StringRef()
70 : llvm::sys::path::parent_path(File),
76 return "C:\\clangd-test";
78 return "/clangd-test";
83 assert(llvm::sys::path::is_relative(File) &&
"FileName should be relative");
85 llvm::SmallString<32> NativeFile =
File;
86 llvm::sys::path::native(NativeFile);
87 llvm::SmallString<32>
Path;
88 llvm::sys::path::append(Path,
testRoot(), NativeFile);
99 llvm::Expected<std::string>
101 llvm::StringRef HintPath)
const override {
102 if (!HintPath.startswith(
testRoot()))
103 return llvm::make_error<llvm::StringError>(
104 "Hint path doesn't start with test root: " + HintPath,
105 llvm::inconvertibleErrorCode());
106 if (!Body.consume_front(
"/"))
107 return llvm::make_error<llvm::StringError>(
108 "Body of an unittest: URI must start with '/'",
109 llvm::inconvertibleErrorCode());
110 llvm::SmallString<16>
Path(Body.begin(), Body.end());
111 llvm::sys::path::native(
Path);
117 llvm::StringRef Body = AbsolutePath;
118 if (!Body.consume_front(
testRoot()))
119 return llvm::make_error<llvm::StringError>(
120 AbsolutePath +
"does not start with " +
testRoot(),
121 llvm::inconvertibleErrorCode());
123 return URI(Scheme,
"",
124 llvm::sys::path::convert_to_slash(Body));
128 const char *TestScheme::Scheme =
"unittest";
130 static URISchemeRegistry::Add<TestScheme>
X(TestScheme::Scheme,
"Test schema");
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...
std::vector< std::string > ExtraClangFlags
URIScheme is an extension point for teaching clangd to recognize a custom URI scheme.
llvm::IntrusiveRefCntPtr< llvm::vfs::InMemoryFileSystem > InMemoryFileSystem
llvm::StringRef PathRef
A typedef to represent a ref to file path.
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...
Documents should not be synced at all.
llvm::Expected< URI > uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override
std::vector< llvm::StringRef > CommandLine
llvm::Optional< ProjectInfo > getProjectInfo(PathRef File) const override
Finds the closest project to File.
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > buildTestFS(llvm::StringMap< std::string > const &Files, llvm::StringMap< time_t > const &Timestamps)
std::string testPath(PathRef File)
llvm::Optional< tooling::CompileCommand > getCompileCommand(PathRef File) const override
If there are any known-good commands for building this file, returns one.
std::string Path
A typedef to represent a file path.
llvm::StringRef Directory
llvm::StringMap< time_t > Timestamps
volatile int UnittestSchemeAnchorSource
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static URISchemeRegistry::Add< TestScheme > X(TestScheme::Scheme, "Test schema")
A URI describes the location of a source file.
llvm::StringMap< std::string > Files
static const char * Scheme