mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user