Allow passing key.sourcetext to provide in-memory-vfs contents

For testing, passing `-vfs-files=source=@target` with an '@' on the
target file will pass it as source text.
This commit is contained in:
Ben Langmuir
2019-06-26 09:15:19 -07:00
committed by Marc Rasi
parent 8784a7b96d
commit 6e2a7e5a3a
6 changed files with 47 additions and 19 deletions

View File

@@ -208,6 +208,7 @@ class InMemoryFileSystemProvider: public SourceKit::FileSystemProvider {
static UIdent KeyFiles("key.files");
static UIdent KeyName("key.name");
static UIdent KeySourceFile("key.sourcefile");
static UIdent KeySourceText("key.sourcetext");
bool failed = options.forEach(KeyFiles, [&](OptionsDictionary &file) {
StringRef name;
if (!file.valueForOption(KeyName, name)) {
@@ -215,9 +216,16 @@ class InMemoryFileSystemProvider: public SourceKit::FileSystemProvider {
return true;
}
StringRef content;
if (file.valueForOption(KeySourceText, content)) {
auto buffer = llvm::MemoryBuffer::getMemBufferCopy(content, name);
InMemoryFS->addFile(name, 0, std::move(buffer));
return false;
}
StringRef mappedPath;
if (!file.valueForOption(KeySourceFile, mappedPath)) {
error = "missing 'key.sourcefile'";
error = "missing 'key.sourcefile' or 'key.sourcetext'";
return true;
}