Skip to content

Commit 243ba33

Browse files
Merge #6785
6785: Fix "no value set for FileTextQuery(FileId(..))" r=jonas-schievink a=jonas-schievink Fixes #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 <[email protected]>
2 parents 99118ee + 6857989 commit 243ba33

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn load(
7373
}
7474
vfs::loader::Message::Loaded { files } => {
7575
for (path, contents) in files {
76-
vfs.set_file_contents(path.into(), contents)
76+
vfs.set_file_contents(path.into(), contents);
7777
}
7878
}
7979
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl GlobalState {
255255
for (path, contents) in files {
256256
let path = VfsPath::from(path);
257257
if !self.mem_docs.contains_key(&path) {
258-
vfs.set_file_contents(path, contents)
258+
vfs.set_file_contents(path, contents);
259259
}
260260
}
261261
}
@@ -503,11 +503,21 @@ impl GlobalState {
503503
{
504504
log::error!("duplicate DidOpenTextDocument: {}", path)
505505
}
506-
this.vfs
506+
let changed = this
507+
.vfs
507508
.write()
508509
.0
509510
.set_file_contents(path, Some(params.text_document.text.into_bytes()));
510-
this.maybe_update_diagnostics();
511+
512+
// If the VFS contents are unchanged, update diagnostics, since `handle_event`
513+
// won't see any changes. This avoids missing diagnostics when opening a file.
514+
//
515+
// If the file *was* changed, `handle_event` will already recompute and send
516+
// diagnostics. We can't do it here, since the *current* file contents might be
517+
// unset in salsa, since the VFS change hasn't been applied to the database yet.
518+
if !changed {
519+
this.maybe_update_diagnostics();
520+
}
511521
}
512522
Ok(())
513523
})?

crates/vfs/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,19 @@ impl Vfs {
103103
(file_id, path)
104104
})
105105
}
106-
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) {
106+
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) -> bool {
107107
let file_id = self.alloc_file_id(path);
108108
let change_kind = match (&self.get(file_id), &contents) {
109-
(None, None) => return,
109+
(None, None) => return false,
110110
(None, Some(_)) => ChangeKind::Create,
111111
(Some(_), None) => ChangeKind::Delete,
112-
(Some(old), Some(new)) if old == new => return,
112+
(Some(old), Some(new)) if old == new => return false,
113113
(Some(_), Some(_)) => ChangeKind::Modify,
114114
};
115115

116116
*self.get_mut(file_id) = contents;
117-
self.changes.push(ChangedFile { file_id, change_kind })
117+
self.changes.push(ChangedFile { file_id, change_kind });
118+
true
118119
}
119120
pub fn has_changes(&self) -> bool {
120121
!self.changes.is_empty()

0 commit comments

Comments
 (0)