From cc47616ed696eb3701d7f699b9360abd205d9ff2 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 12 Oct 2022 15:30:48 +0200 Subject: [PATCH] Add completion trigger chars --- README.md | 1 + book/src/configuration.md | 1 + helix-term/src/commands.rs | 2 ++ helix-view/src/editor.rs | 2 ++ 4 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 0e78963e..ebde32c7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ And others I forgot about... - Added a `--show-explorer` cli flag to open the file explorer on startup (useful for embedded explorer mode) - Added a `delete` (aliases `rm`, `del`) command to delete the file associated with the current buffer - Changed keybind ` E` to close the explorer instead of toggling the recursion one +- Added a completion chars setting that triggers autocomplete when typing one of those chars - - - diff --git a/book/src/configuration.md b/book/src/configuration.md index 6da5b29d..82ff9a19 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -51,6 +51,7 @@ on unix operating systems. | `auto-format` | Enable automatic formatting on save. | `true` | | `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` | | `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` | +| `completion-trigger-chars` | The chars that trigger completion (additional to all word chars) | `['.', ':']` | | `auto-info` | Whether to display infoboxes | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 2f77501a..4b4fbaca 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2942,9 +2942,11 @@ pub mod insert { use helix_core::chars::char_is_word; let mut iter = text.chars_at(cursor); iter.reverse(); + for _ in 0..config.completion_trigger_len { match iter.next() { Some(c) if char_is_word(c) => {} + Some(c) if config.completion_trigger_chars.contains(&c) => {} _ => return, } } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c073d6fc..9d30f6fa 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -197,6 +197,7 @@ pub struct Config { )] pub idle_timeout: Duration, pub completion_trigger_len: u8, + pub completion_trigger_chars: Vec, /// Whether to display infoboxes. Defaults to true. pub auto_info: bool, pub file_picker: FilePickerConfig, @@ -670,6 +671,7 @@ impl Default for Config { indent_guides: IndentGuidesConfig::default(), color_modes: true, explorer: ExplorerConfig::default(), + completion_trigger_chars: vec![':', '.'], } } }