Skip to content

Commit

Permalink
fix: lsp: be more defensive about URI conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Jun 2, 2022
1 parent 6de6a3e commit 378f438
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 378f438

Please sign in to comment.