Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an editor option for keeping completion placeholders. #7480

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Its settings will be merged with the configuration directory `config.toml` and t
| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` |
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` |
| `completion-keep-placeholders` | Set to `true` to keep snippet placeholders when accepting completions. | `false` |
| `auto-info` | Whether to display info boxes | `true` |
| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` |
| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` |
Expand Down
4 changes: 3 additions & 1 deletion helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ impl Completion {
) -> Self {
let preview_completion_insert = editor.config().preview_completion_insert;
let replace_mode = editor.config().completion_replace;
let keep_placeholders = editor.config().completion_keep_placeholders;

// Sort completion items according to their preselect status (given by the LSP server)
items.sort_by_key(|item| !item.item.preselect.unwrap_or(false));

Expand Down Expand Up @@ -298,7 +300,7 @@ impl Completion {
&item.item,
offset_encoding,
trigger_offset,
false,
keep_placeholders,
replace_mode,
);
doc.apply(&transaction, view.id);
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ pub struct Config {
/// Whether to instruct the LSP to replace the entire word when applying a completion
/// or to only insert new text
pub completion_replace: bool,
/// Keep snippet placeholders when accepting completions. Defaults to `false`.
pub completion_keep_placeholders: bool,
/// Whether to display infoboxes. Defaults to true.
pub auto_info: bool,
pub file_picker: FilePickerConfig,
Expand Down Expand Up @@ -797,6 +799,7 @@ impl Default for Config {
idle_timeout: Duration::from_millis(400),
preview_completion_insert: true,
completion_trigger_len: 2,
completion_keep_placeholders: false,
auto_info: true,
file_picker: FilePickerConfig::default(),
statusline: StatusLineConfig::default(),
Expand Down