Move storage for VFS into editor document

The invocation options are not an appropriate place to put this state,
since it can change between requests. This moves it to the editor
document, allowing us to change the specific VFS instance without
causing a rebuild (unless the contents/timestamps for a dependency
change).
This commit is contained in:
Ben Langmuir
2019-06-25 14:27:56 -07:00
committed by Marc Rasi
parent 78a7d95f07
commit 205371c886
9 changed files with 205 additions and 132 deletions

View File

@@ -942,24 +942,38 @@ void SwiftLangSupport::setFileSystemProvider(
assert(Result.second && "tried to set existing FileSystemProvider");
}
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> SwiftLangSupport::getFileSystem(const Optional<VFSOptions> &vfsOptions, std::string &error) {
if (!vfsOptions)
return llvm::vfs::getRealFileSystem();
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
SwiftLangSupport::getFileSystem(const Optional<VFSOptions> &vfsOptions,
Optional<StringRef> primaryFile,
std::string &error) {
// First, try the specified vfsOptions.
if (vfsOptions) {
auto provider = getFileSystemProvider(vfsOptions->name);
if (!provider) {
error = "unknown virtual filesystem '" + vfsOptions->name + "'";
return nullptr;
}
auto provider = getFileSystemProvider(vfsOptions->name);
if (!provider) {
error = "unknown virtual filesystem '" + vfsOptions->name + "'";
return nullptr;
SmallString<0> smallError;
auto fileSystem =
provider->getFileSystem(vfsOptions->arguments, smallError);
if (!fileSystem) {
error = smallError.str();
return nullptr;
}
return fileSystem;
}
SmallString<0> smallError;
auto fileSystem = provider->getFileSystem(vfsOptions->arguments, smallError);
if (!fileSystem) {
error = smallError.str();
return nullptr;
// Otherwise, try to find an open document with a filesystem.
if (primaryFile) {
if (auto doc = EditorDocuments->getByUnresolvedName(*primaryFile)) {
return doc->getFileSystem();
}
}
return fileSystem;
// Fallback to the real filesystem.
return llvm::vfs::getRealFileSystem();
}
CloseClangModuleFiles::~CloseClangModuleFiles() {