Skip to content

Commit 5db7c86

Browse files
committed
Don't crash when recieving unkown file for cargo diagnostic.
1 parent 5aba5a7 commit 5db7c86

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/ra_lsp_server/src/main_loop.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,16 @@ fn on_check_task(
635635

636636
CheckTask::AddDiagnostic { url, diagnostic, fixes } => {
637637
let path = url.to_file_path().map_err(|()| format!("invalid uri: {}", url))?;
638-
let file_id = world_state
639-
.vfs
640-
.read()
641-
.path2file(&path)
642-
.map(|it| FileId(it.0))
643-
.ok_or_else(|| format!("unknown file: {}", path.to_string_lossy()))?;
638+
let file_id = match world_state.vfs.read().path2file(&path) {
639+
Some(file) => FileId(file.0),
640+
None => {
641+
log::error!(
642+
"File with cargo diagnostic not found in VFS: {}",
643+
path.to_string_lossy()
644+
);
645+
return Ok(());
646+
}
647+
};
644648

645649
task_sender
646650
.send(Task::Diagnostic(DiagnosticTask::AddCheck(file_id, diagnostic, fixes)))?;

0 commit comments

Comments
 (0)