diff options
author | Blaž Hrastnik | 2022-06-02 05:06:58 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-06-02 05:07:19 +0000 |
commit | 378f438fb033561831cd6e0f94845feaf82bbbcb (patch) | |
tree | 14dc39cbb6a8247fb2b174cbd0b41fe249bef494 /helix-term | |
parent | 6de6a3edbbdb1b9c87051d535e2b55635aa368e7 (diff) |
fix: lsp: be more defensive about URI conversions
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands/lsp.rs | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 761a387b..bfedb209 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -49,10 +49,8 @@ fn jump_to_location( let path = match location.uri.to_file_path() { Ok(path) => path, Err(_) => { - editor.set_error(format!( - "unable to convert URI to filepath: {}", - location.uri - )); + let err = format!("unable to convert URI to filepath: {}", location.uri); + editor.set_error(err); return; } }; @@ -83,19 +81,37 @@ fn sym_picker( if current_path.as_ref() == Some(&symbol.location.uri) { symbol.name.as_str().into() } else { - let path = symbol.location.uri.to_file_path().unwrap(); - let relative_path = helix_core::path::get_relative_path(path.as_path()) - .to_string_lossy() - .into_owned(); - format!("{} ({})", &symbol.name, relative_path).into() + match symbol.location.uri.to_file_path() { + Ok(path) => { + let relative_path = helix_core::path::get_relative_path(path.as_path()) + .to_string_lossy() + .into_owned(); + format!("{} ({})", &symbol.name, relative_path).into() + } + Err(_) => format!("{} ({})", &symbol.name, &symbol.location.uri).into(), + } } }, move |cx, symbol, action| { if current_path2.as_ref() == Some(&symbol.location.uri) { push_jump(cx.editor); } else { - let path = symbol.location.uri.to_file_path().unwrap(); - cx.editor.open(path, action).expect("editor.open failed"); + let uri = &symbol.location.uri; + let path = match uri.to_file_path() { + Ok(path) => path, + Err(_) => { + let err = format!("unable to convert URI to filepath: {}", uri); + log::error!("{}", err); + cx.editor.set_error(err); + return; + } + }; + if let Err(err) = cx.editor.open(path, action) { + let err = format!("failed to open document: {}: {}", uri, err); + log::error!("{}", err); + cx.editor.set_error(err); + return; + } } let (view, doc) = current!(cx.editor); @@ -361,7 +377,16 @@ pub fn apply_workspace_edit( }; let current_view_id = view!(editor).id; - let doc_id = editor.open(path, Action::Load).unwrap(); + let doc_id = match editor.open(path, Action::Load) { + Ok(doc_id) => doc_id, + Err(err) => { + let err = format!("failed to open document: {}: {}", uri, err); + log::error!("{}", err); + editor.set_error(err); + return; + } + }; + let doc = editor .document_mut(doc_id) .expect("Document for document_changes not found"); |