diff options
author | Blaž Hrastnik | 2021-11-07 09:03:04 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-11-07 09:03:04 +0000 |
commit | 3b8d5102acfcd2aeacb7d8c88eaaf51f5be0cc7b (patch) | |
tree | b03dcfd930b045dd18a00e3b9d9086ec045eb808 | |
parent | 64bb1f75639136868d762b79daa9cc659bf601d0 (diff) |
Make picker take the whole context, not just editor
-rw-r--r-- | helix-term/src/commands.rs | 28 | ||||
-rw-r--r-- | helix-term/src/commands/dap.rs | 12 | ||||
-rw-r--r-- | helix-term/src/ui/mod.rs | 6 | ||||
-rw-r--r-- | helix-term/src/ui/picker.rs | 12 |
4 files changed, 28 insertions, 30 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3616d6a8..0b617dc8 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1458,11 +1458,11 @@ fn global_search(cx: &mut Context) { relative_path.into() } }, - move |editor: &mut Editor, (line_num, path), action| { - match editor.open(path.into(), action) { + move |cx, (line_num, path), action| { + match cx.editor.open(path.into(), action) { Ok(_) => {} Err(e) => { - editor.set_error(format!( + cx.editor.set_error(format!( "Failed to open file '{}': {}", path.display(), e @@ -1472,7 +1472,7 @@ fn global_search(cx: &mut Context) { } let line_num = *line_num; - let (view, doc) = current!(editor); + let (view, doc) = current!(cx.editor); let text = doc.text(); let start = text.line_to_char(line_num); let end = text.line_to_char((line_num + 1).min(text.len_lines())); @@ -2717,8 +2717,8 @@ fn buffer_picker(cx: &mut Context) { None => "[scratch buffer]".into(), } }, - |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| { - editor.switch(*id, Action::Replace); + |cx, (id, _path): &(DocumentId, Option<PathBuf>), _action| { + cx.editor.switch(*id, Action::Replace); }, |editor, (id, path)| { let doc = &editor.documents.get(id)?; @@ -2785,9 +2785,9 @@ fn symbol_picker(cx: &mut Context) { let picker = FilePicker::new( symbols, |symbol| (&symbol.name).into(), - move |editor: &mut Editor, symbol, _action| { - push_jump(editor); - let (view, doc) = current!(editor); + move |cx, symbol, _action| { + push_jump(cx.editor); + let (view, doc) = current!(cx.editor); if let Some(range) = lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding) @@ -2845,15 +2845,15 @@ pub fn code_action(cx: &mut Context) { } lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(), }, - move |editor, code_action, _action| match code_action { + move |cx, code_action, _action| match code_action { lsp::CodeActionOrCommand::Command(command) => { log::debug!("code action command: {:?}", command); - editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183")); + cx.editor.set_error(String::from("Handling code action command is not implemented yet, see https://github.com/helix-editor/helix/issues/183")); } lsp::CodeActionOrCommand::CodeAction(code_action) => { log::debug!("code action: {:?}", code_action); if let Some(ref workspace_edit) = code_action.edit { - apply_workspace_edit(editor, offset_encoding, workspace_edit) + apply_workspace_edit(cx.editor, offset_encoding, workspace_edit) } } }, @@ -3267,9 +3267,7 @@ fn goto_impl( let line = location.range.start.line; format!("{}:{}", file, line).into() }, - move |editor: &mut Editor, location, action| { - jump_to(editor, location, offset_encoding, action) - }, + move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action), |_editor, location| { let path = location.uri.to_file_path().unwrap(); let line = Some(( diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index e7f9c214..43931f73 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -128,7 +128,7 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa ) .into() }, - move |editor, thread, _action| callback_fn(editor, thread), + move |cx, thread, _action| callback_fn(cx.editor, thread), move |_editor, thread| { if let Some(frame) = frames.get(&thread.id).and_then(|bt| bt.get(0)) { frame @@ -323,9 +323,9 @@ pub fn dap_launch(cx: &mut Context) { true, config.templates, |template| template.name.as_str().into(), - |editor, template, _action| { + |cx, template, _action| { let completions = template.completion.clone(); - editor.debug_config_completions = completions; + cx.editor.debug_config_completions = completions; // TODO: need some way to manipulate the compositor to push a new prompt here }, ))); // TODO: wrap in popup with fixed size @@ -755,8 +755,8 @@ pub fn dap_switch_stack_frame(cx: &mut Context) { let picker = FilePicker::new( frames, |frame| frame.name.clone().into(), // TODO: include thread_states in the label - move |editor, frame, _action| { - let debugger = match &mut editor.debugger { + move |cx, frame, _action| { + let debugger = match &mut cx.editor.debugger { Some(debugger) => debugger, None => return, }; @@ -770,7 +770,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) { .get(pos.unwrap_or(0)) .cloned(); if let Some(frame) = &frame { - jump_to_stack_frame(editor, frame); + jump_to_stack_frame(cx.editor, frame); } }, move |_editor, frame| { diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 00c70cea..d634bc4a 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -21,7 +21,7 @@ pub use text::Text; use helix_core::regex::Regex; use helix_core::regex::RegexBuilder; -use helix_view::{Document, Editor, View}; +use helix_view::{Document, View}; use std::path::PathBuf; @@ -151,8 +151,8 @@ pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> { .unwrap() .into() }, - move |editor: &mut Editor, path: &PathBuf, action| { - editor + move |cx, path: &PathBuf, action| { + cx.editor .open(path.into(), action) .expect("editor.open failed"); }, diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 3e805fac..01e5f6c3 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -84,7 +84,7 @@ impl<T> FilePicker<T> { pub fn new( options: Vec<T>, format_fn: impl Fn(&T) -> Cow<str> + 'static, - callback_fn: impl Fn(&mut Editor, &T, Action) + 'static, + callback_fn: impl Fn(&mut Context, &T, Action) + 'static, preview_fn: impl Fn(&Editor, &T) -> Option<FileLocation> + 'static, ) -> Self { Self { @@ -278,7 +278,7 @@ pub struct Picker<T> { render_centered: bool, format_fn: Box<dyn Fn(&T) -> Cow<str>>, - callback_fn: Box<dyn Fn(&mut Editor, &T, Action)>, + callback_fn: Box<dyn Fn(&mut Context, &T, Action)>, } impl<T> Picker<T> { @@ -286,7 +286,7 @@ impl<T> Picker<T> { render_centered: bool, options: Vec<T>, format_fn: impl Fn(&T) -> Cow<str> + 'static, - callback_fn: impl Fn(&mut Editor, &T, Action) + 'static, + callback_fn: impl Fn(&mut Context, &T, Action) + 'static, ) -> Self { let prompt = Prompt::new( "".into(), @@ -452,7 +452,7 @@ impl<T: 'static> Component for Picker<T> { .. } => { if let Some(option) = self.selection() { - (self.callback_fn)(&mut cx.editor, option, Action::Replace); + (self.callback_fn)(cx, option, Action::Replace); } return close_fn; } @@ -461,7 +461,7 @@ impl<T: 'static> Component for Picker<T> { modifiers: KeyModifiers::CONTROL, } => { if let Some(option) = self.selection() { - (self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit); + (self.callback_fn)(cx, option, Action::HorizontalSplit); } return close_fn; } @@ -470,7 +470,7 @@ impl<T: 'static> Component for Picker<T> { modifiers: KeyModifiers::CONTROL, } => { if let Some(option) = self.selection() { - (self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit); + (self.callback_fn)(cx, option, Action::VerticalSplit); } return close_fn; } |