6785: Fix "no value set for FileTextQuery(FileId(..))" r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6622

Let's hope I got it right this time, but I feel like I slowly begin to understand the main loop logic.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2020-12-09 16:32:03 +00:00 committed by GitHub
commit 243ba330dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View file

@ -103,18 +103,19 @@ impl Vfs {
(file_id, path)
})
}
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) {
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) -> bool {
let file_id = self.alloc_file_id(path);
let change_kind = match (&self.get(file_id), &contents) {
(None, None) => return,
(None, None) => return false,
(None, Some(_)) => ChangeKind::Create,
(Some(_), None) => ChangeKind::Delete,
(Some(old), Some(new)) if old == new => return,
(Some(old), Some(new)) if old == new => return false,
(Some(_), Some(_)) => ChangeKind::Modify,
};
*self.get_mut(file_id) = contents;
self.changes.push(ChangedFile { file_id, change_kind })
self.changes.push(ChangedFile { file_id, change_kind });
true
}
pub fn has_changes(&self) -> bool {
!self.changes.is_empty()