From 5db7c8642beb1cd4c09359c3f3266d67557a30f9 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Fri, 7 Feb 2020 12:30:29 +0100 Subject: Don't crash when recieving unkown file for cargo diagnostic. --- crates/ra_lsp_server/src/main_loop.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 12961ba37..fcae37bb7 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -635,12 +635,16 @@ fn on_check_task( CheckTask::AddDiagnostic { url, diagnostic, fixes } => { let path = url.to_file_path().map_err(|()| format!("invalid uri: {}", url))?; - let file_id = world_state - .vfs - .read() - .path2file(&path) - .map(|it| FileId(it.0)) - .ok_or_else(|| format!("unknown file: {}", path.to_string_lossy()))?; + let file_id = match world_state.vfs.read().path2file(&path) { + Some(file) => FileId(file.0), + None => { + log::error!( + "File with cargo diagnostic not found in VFS: {}", + path.to_string_lossy() + ); + return Ok(()); + } + }; task_sender .send(Task::Diagnostic(DiagnosticTask::AddCheck(file_id, diagnostic, fixes)))?; -- cgit v1.2.3 From 137a878461662b7bf7f1acf3855b166c1c19fc2f Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Fri, 7 Feb 2020 12:35:36 +0100 Subject: to_string_lossy() -> display() --- crates/ra_lsp_server/src/main_loop.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index fcae37bb7..ceff82fda 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -638,10 +638,7 @@ fn on_check_task( let file_id = match world_state.vfs.read().path2file(&path) { Some(file) => FileId(file.0), None => { - log::error!( - "File with cargo diagnostic not found in VFS: {}", - path.to_string_lossy() - ); + log::error!("File with cargo diagnostic not found in VFS: {}", path.display()); return Ok(()); } }; -- cgit v1.2.3