fix: lsp: be more defensive about URI conversions

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

@ -49,10 +49,8 @@ fn jump_to_location(
let path = match location.uri.to_file_path() { let path = match location.uri.to_file_path() {
Ok(path) => path, Ok(path) => path,
Err(_) => { Err(_) => {
editor.set_error(format!( let err = format!("unable to convert URI to filepath: {}", location.uri);
"unable to convert URI to filepath: {}", editor.set_error(err);
location.uri
));
return; return;
} }
}; };
@ -83,19 +81,37 @@ fn sym_picker(
if current_path.as_ref() == Some(&symbol.location.uri) { if current_path.as_ref() == Some(&symbol.location.uri) {
symbol.name.as_str().into() symbol.name.as_str().into()
} else { } else {
let path = symbol.location.uri.to_file_path().unwrap(); match symbol.location.uri.to_file_path() {
Ok(path) => {
let relative_path = helix_core::path::get_relative_path(path.as_path()) let relative_path = helix_core::path::get_relative_path(path.as_path())
.to_string_lossy() .to_string_lossy()
.into_owned(); .into_owned();
format!("{} ({})", &symbol.name, relative_path).into() format!("{} ({})", &symbol.name, relative_path).into()
} }
Err(_) => format!("{} ({})", &symbol.name, &symbol.location.uri).into(),
}
}
}, },
move |cx, symbol, action| { move |cx, symbol, action| {
if current_path2.as_ref() == Some(&symbol.location.uri) { if current_path2.as_ref() == Some(&symbol.location.uri) {
push_jump(cx.editor); push_jump(cx.editor);
} else { } else {
let path = symbol.location.uri.to_file_path().unwrap(); let uri = &symbol.location.uri;
cx.editor.open(path, action).expect("editor.open failed"); 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); let (view, doc) = current!(cx.editor);
@ -361,7 +377,16 @@ pub fn apply_workspace_edit(
}; };
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 = 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 let doc = editor
.document_mut(doc_id) .document_mut(doc_id)
.expect("Document for document_changes not found"); .expect("Document for document_changes not found");

Loading…
Cancel
Save