diff options
author | Blaž Hrastnik | 2022-06-02 04:58:46 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-06-02 05:07:19 +0000 |
commit | 6de6a3edbbdb1b9c87051d535e2b55635aa368e7 (patch) | |
tree | 6af4ec8eb787df75cbe5850cbaa2b16358d6c2a8 /helix-term | |
parent | 3d91c99c3e64460d292e0393e89d723feefe10aa (diff) |
fix: lsp: be more defensive about URI conversions
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands/lsp.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index bf62fd3c..761a387b 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -46,10 +46,16 @@ fn jump_to_location( offset_encoding: OffsetEncoding, action: Action, ) { - let path = location - .uri - .to_file_path() - .expect("unable to convert URI to filepath"); + let path = match location.uri.to_file_path() { + Ok(path) => path, + Err(_) => { + editor.set_error(format!( + "unable to convert URI to filepath: {}", + location.uri + )); + return; + } + }; let _id = editor.open(path, action).expect("editor.open failed"); let (view, doc) = current!(editor); let definition_pos = location.range.start; @@ -344,9 +350,15 @@ pub fn apply_workspace_edit( workspace_edit: &lsp::WorkspaceEdit, ) { let mut apply_edits = |uri: &helix_lsp::Url, text_edits: Vec<lsp::TextEdit>| { - let path = uri - .to_file_path() - .expect("unable to convert URI to filepath"); + let path = match uri.to_file_path() { + Ok(path) => path, + Err(_) => { + let err = format!("unable to convert URI to filepath: {}", uri); + log::error!("{}", err); + editor.set_error(err); + return; + } + }; let current_view_id = view!(editor).id; let doc_id = editor.open(path, Action::Load).unwrap(); @@ -381,7 +393,7 @@ pub fn apply_workspace_edit( log::debug!("workspace changes: {:?}", changes); for (uri, text_edits) in changes { let text_edits = text_edits.to_vec(); - apply_edits(uri, text_edits); + apply_edits(uri, text_edits) } return; // Not sure if it works properly, it'll be safer to just panic here to avoid breaking some parts of code on which code actions will be used |