on master help sign in
fix: lsp: be more defensive about URI conversions
378f438Blaž Hrastnik
helix-term/src/commands/lsp.rs+37−12
@@ -49,10 +49,8 @@ fn jump_to_location(
49 let path = match location.uri.to_file_path() {
49 let path = match location.uri.to_file_path() {
50 Ok(path) => path,
50 Ok(path) => path,
51 Err(_) => {
51 Err(_) => {
52− editor.set_error(format!(
53− "unable to convert URI to filepath: {}",
52+ let err = format!("unable to convert URI to filepath: {}", location.uri);
54− location.uri
53+ editor.set_error(err);
55− ));
56 return;
54 return;
57 }
55 }
58 };
56 };
@@ -83,19 +81,37 @@ fn sym_picker(
83 if current_path.as_ref() == Some(&symbol.location.uri) {
81 if current_path.as_ref() == Some(&symbol.location.uri) {
84 symbol.name.as_str().into()
82 symbol.name.as_str().into()
85 } else {
83 } else {
86− let path = symbol.location.uri.to_file_path().unwrap();
84+ match symbol.location.uri.to_file_path() {
85+ Ok(path) => {
87− let relative_path = helix_core::path::get_relative_path(path.as_path())
86+ let relative_path = helix_core::path::get_relative_path(path.as_path())
88− .to_string_lossy()
87+ .to_string_lossy()
89− .into_owned();
88+ .into_owned();
90− format!("{} ({})", &symbol.name, relative_path).into()
89+ format!("{} ({})", &symbol.name, relative_path).into()
90+ }
91+ Err(_) => format!("{} ({})", &symbol.name, &symbol.location.uri).into(),
92+ }
91 }
93 }
92 },
94 },
93 move |cx, symbol, action| {
95 move |cx, symbol, action| {
94 if current_path2.as_ref() == Some(&symbol.location.uri) {
96 if current_path2.as_ref() == Some(&symbol.location.uri) {
95 push_jump(cx.editor);
97 push_jump(cx.editor);
96 } else {
98 } else {
97− let path = symbol.location.uri.to_file_path().unwrap();
99+ let uri = &symbol.location.uri;
100+ let path = match uri.to_file_path() {
101+ Ok(path) => path,
102+ Err(_) => {
103+ let err = format!("unable to convert URI to filepath: {}", uri);
104+ log::error!("{}", err);
105+ cx.editor.set_error(err);
106+ return;
107+ }
108+ };
98− cx.editor.open(path, action).expect("editor.open failed");
109+ if let Err(err) = cx.editor.open(path, action) {
110+ let err = format!("failed to open document: {}: {}", uri, err);
111+ log::error!("{}", err);
112+ cx.editor.set_error(err);
113+ return;
114+ }
99 }
115 }
100
116
101 let (view, doc) = current!(cx.editor);
117 let (view, doc) = current!(cx.editor);
@@ -361,7 +377,16 @@ pub fn apply_workspace_edit(
361 };
377 };
362
378
363 let current_view_id = view!(editor).id;
379 let current_view_id = view!(editor).id;
364− let doc_id = editor.open(path, Action::Load).unwrap();
380+ let doc_id = match editor.open(path, Action::Load) {
381+ Ok(doc_id) => doc_id,
382+ Err(err) => {
383+ let err = format!("failed to open document: {}: {}", uri, err);
384+ log::error!("{}", err);
385+ editor.set_error(err);
386+ return;
387+ }
388+ };
389+
365 let doc = editor
390 let doc = editor
366 .document_mut(doc_id)
391 .document_mut(doc_id)
367 .expect("Document for document_changes not found");
392 .expect("Document for document_changes not found");