on master help sign in
Extract a helper function for lsp::Location
c06155aBlaž Hrastnik
helix-term/src/commands/lsp.rs+12−18
@@ -11,11 +11,20 @@ use helix_view::editor::Action;
11
11
12use crate::{
12use crate::{
13 compositor::{self, Compositor},
13 compositor::{self, Compositor},
14− ui::{self, overlay::overlayed, FilePicker, Popup, Prompt, PromptEvent},
14+ ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, Prompt, PromptEvent},
15};
15};
16
16
17use std::borrow::Cow;
17use std::borrow::Cow;
18
18
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+
19fn sym_picker(
28fn sym_picker(
20 symbols: Vec<lsp::SymbolInformation>,
29 symbols: Vec<lsp::SymbolInformation>,
21 current_path: Option<lsp::Url>,
30 current_path: Option<lsp::Url>,
@@ -55,14 +64,7 @@ fn sym_picker(
55 align_view(doc, view, Align::Center);
64 align_view(doc, view, Align::Center);
56 }
65 }
57 },
66 },
58− move |_editor, symbol| {
67+ move |_editor, symbol| Some(location_to_file_location(&symbol.location)),
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− },
66 );
68 );
67 picker.truncate_start = false;
69 picker.truncate_start = false;
68 picker
70 picker
@@ -465,15 +467,7 @@ fn goto_impl(
465 format!("{}:{}", file, line).into()
467 format!("{}:{}", file, line).into()
466 },
468 },
467 move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
469 move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
468− |_editor, location| {
470+ move |_editor, location| Some(location_to_file_location(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− },
477 );
471 );
478 compositor.push(Box::new(overlayed(picker)));
472 compositor.push(Box::new(overlayed(picker)));
479 }
473 }
helix-term/src/ui/mod.rs+1−1
@@ -14,7 +14,7 @@ pub use completion::Completion;
14pub use editor::EditorView;
14pub use editor::EditorView;
15pub use markdown::Markdown;
15pub use markdown::Markdown;
16pub use menu::Menu;
16pub use menu::Menu;
17−pub use picker::{FilePicker, Picker};
17+pub use picker::{FileLocation, FilePicker, Picker};
18pub use popup::Popup;
18pub use popup::Popup;
19pub use prompt::{Prompt, PromptEvent};
19pub use prompt::{Prompt, PromptEvent};
20pub use spinner::{ProgressSpinners, Spinner};
20pub 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;
33pub const MAX_FILE_SIZE_FOR_PREVIEW: u64 = 10 * 1024 * 1024;
33pub const MAX_FILE_SIZE_FOR_PREVIEW: u64 = 10 * 1024 * 1024;
34
34
35/// File path and range of lines (used to align and highlight lines)
35/// 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)>);
37
37
38pub struct FilePicker<T> {
38pub struct FilePicker<T> {
39 picker: Picker<T>,
39 picker: Picker<T>,