on master help sign in
Extract a helper function for lsp::Location
commitc06155ace4ef4aa65b680093da920bded320b8f0 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 18 Feb 2022, 14:01 (5 years ago) parent504d5ce
3 files changed+14−20
helix-term/src/commands/lsp.rs+12−18 helix-term/src/ui/mod.rs+1−1 helix-term/src/ui/picker.rs+1−1
helix-term/src/commands/lsp.rs+12−18
@@ -11,11 +11,20 @@ use helix_view::editor::Action;
1111
1212use crate::{
1313 compositor::{self, Compositor},
14− ui::{self, overlay::overlayed, FilePicker, Popup, Prompt, PromptEvent},
14+ ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, Prompt, PromptEvent},
1515};
1616
1717use std::borrow::Cow;
1818
19+fn location_to_file_location(location: &lsp::Location) -> FileLocation {
20+ let path = location.uri.to_file_path().unwrap();
21+ let line = Some((
22+ location.range.start.line as usize,
23+ location.range.end.line as usize,
24+ ));
25+ (path, line)
26+}
27+
1928fn sym_picker(
2029 symbols: Vec<lsp::SymbolInformation>,
2130 current_path: Option<lsp::Url>,
@@ -55,14 +64,7 @@ fn sym_picker(
5564 align_view(doc, view, Align::Center);
5665 }
5766 },
58− move |_editor, symbol| {
59− let path = symbol.location.uri.to_file_path().unwrap();
60− let line = Some((
61− symbol.location.range.start.line as usize,
62− symbol.location.range.end.line as usize,
63− ));
64− Some((path, line))
65− },
67+ move |_editor, symbol| Some(location_to_file_location(&symbol.location)),
6668 );
6769 picker.truncate_start = false;
6870 picker
@@ -465,15 +467,7 @@ fn goto_impl(
465467 format!("{}:{}", file, line).into()
466468 },
467469 move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
468− |_editor, location| {
469− // TODO: share code for symbol.location and location
470− let path = location.uri.to_file_path().unwrap();
471− let line = Some((
472− location.range.start.line as usize,
473− location.range.end.line as usize,
474− ));
475− Some((path, line))
476− },
470+ move |_editor, location| Some(location_to_file_location(location)),
477471 );
478472 compositor.push(Box::new(overlayed(picker)));
479473 }
helix-term/src/ui/mod.rs+1−1
@@ -14,7 +14,7 @@ pub use completion::Completion;
1414pub use editor::EditorView;
1515pub use markdown::Markdown;
1616pub use menu::Menu;
17−pub use picker::{FilePicker, Picker};
17+pub use picker::{FileLocation, FilePicker, Picker};
1818pub use popup::Popup;
1919pub use prompt::{Prompt, PromptEvent};
2020pub use spinner::{ProgressSpinners, Spinner};
helix-term/src/ui/picker.rs+1−1
@@ -33,7 +33,7 @@ pub const MIN_AREA_WIDTH_FOR_PREVIEW: u16 = 72;
3333pub const MAX_FILE_SIZE_FOR_PREVIEW: u64 = 10 * 1024 * 1024;
3434
3535/// File path and range of lines (used to align and highlight lines)
36−type FileLocation = (PathBuf, Option<(usize, usize)>);
36+pub type FileLocation = (PathBuf, Option<(usize, usize)>);
3737
3838pub struct FilePicker<T> {
3939 picker: Picker<T>,