on master help sign in
Experiment with autocompletion on idle
commit40abec80e1062503d70055ed9e968cd4b31411a7 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 26 Aug 2021, 11:14 (5 years ago) parentf99bea4
3 files changed+38−4
helix-term/src/application.rs+36−2 helix-term/src/commands.rs+1−1 helix-term/src/ui/editor.rs+1−1
helix-term/src/application.rs+36−2
@@ -200,9 +200,9 @@ impl Application {
200200 self.render();
201201 }
202202 _ = &mut self.editor.idle_timer => {
203+ // idle timeout
203204 self.editor.clear_idle_timer();
204− println!("idle!")
205− // idle timeout
205+ self.handle_idle_timeout();
206206 }
207207 }
208208 }
@@ -233,6 +233,40 @@ impl Application {
233233 }
234234 }
235235
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+
236270 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
237271 let mut cx = crate::compositor::Context {
238272 editor: &mut self.editor,
helix-term/src/commands.rs+1−1
@@ -4045,7 +4045,7 @@ fn remove_primary_selection(cx: &mut Context) {
40454045 doc.set_selection(view.id, selection);
40464046}
40474047
4048−fn completion(cx: &mut Context) {
4048+pub fn completion(cx: &mut Context) {
40494049 // trigger on trigger char, or if user calls it
40504050 // (or on word char typing??)
40514051 // 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 {
3333 keymaps: Keymaps,
3434 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
3535 last_insert: (commands::Command, Vec<KeyEvent>),
36− completion: Option<Completion>,
36+ pub(crate) completion: Option<Completion>,
3737 spinners: ProgressSpinners,
3838 autoinfo: Option<Info>,
3939}