on master help sign in
Experiment with autocompletion on idle
40abec8Blaž Hrastnik
helix-term/src/application.rs+36−2
@@ -200,9 +200,9 @@ impl Application {
200 self.render();
200 self.render();
201 }
201 }
202 _ = &mut self.editor.idle_timer => {
202 _ = &mut self.editor.idle_timer => {
203+ // idle timeout
203 self.editor.clear_idle_timer();
204 self.editor.clear_idle_timer();
204− println!("idle!")
205+ self.handle_idle_timeout();
205− // idle timeout
206 }
206 }
207 }
207 }
208 }
208 }
@@ -233,6 +233,40 @@ impl Application {
233 }
233 }
234 }
234 }
235
235
236+ pub fn handle_idle_timeout(&mut self) {
237+ use helix_view::document::Mode;
238+ use crate::commands::{Context, completion};
239+
240+
241+ if doc_mut!(self.editor).mode != Mode::Insert {
242+ return;
243+ }
244+ let editor_view = self
245+ .compositor
246+ .find(std::any::type_name::<ui::EditorView>())
247+ .expect("expected at least one EditorView");
248+ let editor_view = editor_view
249+ .as_any_mut()
250+ .downcast_mut::<ui::EditorView>()
251+ .unwrap();
252+
253+ if editor_view.completion.is_some() {
254+ return;
255+ }
256+
257+ let mut cx = Context {
258+ selected_register: helix_view::RegisterSelection::default(),
259+ editor: &mut self.editor,
260+ jobs: &mut self.jobs,
261+ count: None,
262+ callback: None,
263+ on_next_key_callback: None,
264+ };
265+ completion(&mut cx);
266+ // TODO: scan backwards for trigger and filter the box
267+ self.render();
268+ }
269+
236 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
270 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
237 let mut cx = crate::compositor::Context {
271 let mut cx = crate::compositor::Context {
238 editor: &mut self.editor,
272 editor: &mut self.editor,
helix-term/src/commands.rs+1−1
@@ -4045,7 +4045,7 @@ fn remove_primary_selection(cx: &mut Context) {
4045 doc.set_selection(view.id, selection);
4045 doc.set_selection(view.id, selection);
4046}
4046}
4047
4047
4048−fn completion(cx: &mut Context) {
4048+pub fn completion(cx: &mut Context) {
4049 // trigger on trigger char, or if user calls it
4049 // trigger on trigger char, or if user calls it
4050 // (or on word char typing??)
4050 // (or on word char typing??)
4051 // after it's triggered, if response marked is_incomplete, update on every subsequent keypress
4051 // after it's triggered, if response marked is_incomplete, update on every subsequent keypress
helix-term/src/ui/editor.rs+1−1
@@ -33,7 +33,7 @@ pub struct EditorView {
33 keymaps: Keymaps,
33 keymaps: Keymaps,
34 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
34 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
35 last_insert: (commands::Command, Vec<KeyEvent>),
35 last_insert: (commands::Command, Vec<KeyEvent>),
36− completion: Option<Completion>,
36+ pub(crate) completion: Option<Completion>,
37 spinners: ProgressSpinners,
37 spinners: ProgressSpinners,
38 autoinfo: Option<Info>,
38 autoinfo: Option<Info>,
39}
39}