aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands/lsp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands/lsp.rs')
-rw-r--r--helix-term/src/commands/lsp.rs80
1 files changed, 36 insertions, 44 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs
index 8c3fd13b..7cc2eaf8 100644
--- a/helix-term/src/commands/lsp.rs
+++ b/helix-term/src/commands/lsp.rs
@@ -240,44 +240,40 @@ type SymbolPicker = FilePicker<SymbolInformationItem>;
fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker {
// TODO: drop current_path comparison and instead use workspace: bool flag?
- FilePicker::new(
- symbols,
- current_path.clone(),
- move |cx, item, action| {
- let (view, doc) = current!(cx.editor);
- push_jump(view, doc);
-
- if current_path.as_ref() != Some(&item.symbol.location.uri) {
- let uri = &item.symbol.location.uri;
- let path = match uri.to_file_path() {
- Ok(path) => path,
- Err(_) => {
- let err = format!("unable to convert URI to filepath: {}", uri);
- 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);
+ FilePicker::new(symbols, current_path.clone(), move |cx, item, action| {
+ let (view, doc) = current!(cx.editor);
+ push_jump(view, doc);
+
+ if current_path.as_ref() != Some(&item.symbol.location.uri) {
+ let uri = &item.symbol.location.uri;
+ let path = match uri.to_file_path() {
+ Ok(path) => path,
+ Err(_) => {
+ let err = format!("unable to convert URI to filepath: {}", uri);
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);
- if let Some(range) =
- lsp_range_to_range(doc.text(), item.symbol.location.range, item.offset_encoding)
- {
- // we flip the range so that the cursor sits on the start of the symbol
- // (for example start of the function).
- doc.set_selection(view.id, Selection::single(range.head, range.anchor));
- align_view(doc, view, Align::Center);
- }
- },
- move |_editor, item| Some(location_to_file_location(&item.symbol.location)),
- )
+ if let Some(range) =
+ lsp_range_to_range(doc.text(), item.symbol.location.range, item.offset_encoding)
+ {
+ // we flip the range so that the cursor sits on the start of the symbol
+ // (for example start of the function).
+ doc.set_selection(view.id, Selection::single(range.head, range.anchor));
+ align_view(doc, view, Align::Center);
+ }
+ })
+ .with_preview(move |_editor, item| Some(location_to_file_location(&item.symbol.location)))
.truncate_start(false)
}
@@ -345,11 +341,11 @@ fn diag_picker(
align_view(doc, view, Align::Center);
}
},
- move |_editor, PickerDiagnostic { url, diag, .. }| {
- let location = lsp::Location::new(url.clone(), diag.range);
- Some(location_to_file_location(&location))
- },
)
+ .with_preview(move |_editor, PickerDiagnostic { url, diag, .. }| {
+ let location = lsp::Location::new(url.clone(), diag.range);
+ Some(location_to_file_location(&location))
+ })
.truncate_start(false)
}
@@ -1047,14 +1043,10 @@ fn goto_impl(
editor.set_error("No definition found.");
}
_locations => {
- let picker = FilePicker::new(
- locations,
- cwdir,
- move |cx, location, action| {
- jump_to_location(cx.editor, location, offset_encoding, action)
- },
- move |_editor, location| Some(location_to_file_location(location)),
- );
+ let picker = FilePicker::new(locations, cwdir, move |cx, location, action| {
+ jump_to_location(cx.editor, location, offset_encoding, action)
+ })
+ .with_preview(move |_editor, location| Some(location_to_file_location(location)));
compositor.push(Box::new(overlaid(picker)));
}
}