fix: lsp: be more defensive about URI conversions

imgbot
Blaž Hrastnik 3 years ago
parent 3d91c99c3e
commit 6de6a3edbb
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640

@ -46,10 +46,16 @@ fn jump_to_location(
offset_encoding: OffsetEncoding, offset_encoding: OffsetEncoding,
action: Action, action: Action,
) { ) {
let path = location let path = match location.uri.to_file_path() {
.uri Ok(path) => path,
.to_file_path() Err(_) => {
.expect("unable to convert URI to filepath"); editor.set_error(format!(
"unable to convert URI to filepath: {}",
location.uri
));
return;
}
};
let _id = editor.open(path, action).expect("editor.open failed"); let _id = editor.open(path, action).expect("editor.open failed");
let (view, doc) = current!(editor); let (view, doc) = current!(editor);
let definition_pos = location.range.start; let definition_pos = location.range.start;
@ -344,9 +350,15 @@ pub fn apply_workspace_edit(
workspace_edit: &lsp::WorkspaceEdit, workspace_edit: &lsp::WorkspaceEdit,
) { ) {
let mut apply_edits = |uri: &helix_lsp::Url, text_edits: Vec<lsp::TextEdit>| { let mut apply_edits = |uri: &helix_lsp::Url, text_edits: Vec<lsp::TextEdit>| {
let path = uri let path = match uri.to_file_path() {
.to_file_path() Ok(path) => path,
.expect("unable to convert URI to filepath"); 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 current_view_id = view!(editor).id;
let doc_id = editor.open(path, Action::Load).unwrap(); let doc_id = editor.open(path, Action::Load).unwrap();
@ -381,7 +393,7 @@ pub fn apply_workspace_edit(
log::debug!("workspace changes: {:?}", changes); log::debug!("workspace changes: {:?}", changes);
for (uri, text_edits) in changes { for (uri, text_edits) in changes {
let text_edits = text_edits.to_vec(); let text_edits = text_edits.to_vec();
apply_edits(uri, text_edits); apply_edits(uri, text_edits)
} }
return; 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 // 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

Loading…
Cancel
Save