Skip to content

Commit 4d0d113

Browse files
bors[bot]kiljacken
andauthored
Merge #3044
3044: Don't crash when recieving unkown file for cargo diagnostic. r=matklad a=kiljacken Fixes #3014 Co-authored-by: Emil Lauridsen <[email protected]>
2 parents 1479dd6 + 137a878 commit 4d0d113

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/ra_lsp_server/src/main_loop.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,13 @@ 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!("File with cargo diagnostic not found in VFS: {}", path.display());
642+
return Ok(());
643+
}
644+
};
644645

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

0 commit comments

Comments
 (0)