@@ -9,10 +9,12 @@ use crate::{
9use futures_util::future;
9use futures_util::future;
11 path::{Path, PathBuf},
11 path::{Path, PathBuf},
12 sync::Arc,
13 sync::Arc,
16+use tokio::time::{sleep, Duration, Instant, Sleep};
16use slotmap::SlotMap;
18use slotmap::SlotMap;
18use anyhow::Error;
20use anyhow::Error;
@@ -24,6 +26,14 @@ use helix_core::Position;
25use serde::Deserialize;
27use serde::Deserialize;
29+fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error>
31+ D: serde::Deserializer<'de>,
33+ let millis = u64::deserialize(deserializer)?;
34+ Ok(Duration::from_millis(millis))
27#[derive(Debug, Clone, PartialEq, Deserialize)]
37#[derive(Debug, Clone, PartialEq, Deserialize)]
28#[serde(rename_all = "kebab-case", default)]
38#[serde(rename_all = "kebab-case", default)]
29pub struct Config {
39pub struct Config {
@@ -43,6 +53,9 @@ pub struct Config {
43 pub smart_case: bool,
53 pub smart_case: bool,
44 /// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true.
54 /// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true.
45 pub auto_pairs: bool,
55 pub auto_pairs: bool,
56+ /// Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. Defaults to 400ms.
57+ #[serde(skip_serializing, deserialize_with = "deserialize_duration_millis")]
58+ pub idle_timeout: Duration,
48#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
61#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
@@ -70,6 +83,7 @@ impl Default for Config {
70 middle_click_paste: true,
83 middle_click_paste: true,
71 smart_case: true,
84 smart_case: true,
72 auto_pairs: true,
85 auto_pairs: true,
86+ idle_timeout: Duration::from_millis(400),
@@ -91,6 +105,8 @@ pub struct Editor {
91 pub status_msg: Option<(String, Severity)>,
105 pub status_msg: Option<(String, Severity)>,
93 pub config: Config,
107 pub config: Config,
109+ pub idle_timer: Pin<Box<Sleep>>,
96#[derive(Debug, Copy, Clone)]
112#[derive(Debug, Copy, Clone)]
@@ -125,10 +141,24 @@ impl Editor {
125 registers: Registers::default(),
141 registers: Registers::default(),
126 clipboard_provider: get_clipboard_provider(),
142 clipboard_provider: get_clipboard_provider(),
127 status_msg: None,
143 status_msg: None,
144+ idle_timer: Box::pin(sleep(Duration::from_millis(500))),
149+ pub fn clear_idle_timer(&mut self) {
150+ // equivalent to internal Instant::far_future() (30 years)
153+ .reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
156+ pub fn reset_idle_timer(&mut self) {
159+ .reset(Instant::now() + Duration::from_millis(500));
132 pub fn clear_status(&mut self) {
162 pub fn clear_status(&mut self) {
133 self.status_msg = None;
163 self.status_msg = None;