diff options
author | Pascal Kuthe | 2023-02-11 13:20:49 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-03-08 01:48:35 +0000 |
commit | ba24cfe9125eda97346e3ceee42686fb9f46046f (patch) | |
tree | 7acf4d19af99187e153773ee900fc33a37f52c33 | |
parent | ded4381728bcbbcee3d3fec1b861038229b806d3 (diff) |
Delete snippet placeholders when accepting completion
When accepting a snippet completion we automatically delete the
placeholders for now as doing so manual is quite cumbersome. In the
future we should keep these as a mark + virtual text that is
automatically removed once the cursor moves there.
-rw-r--r-- | helix-lsp/src/snippet.rs | 13 | ||||
-rw-r--r-- | helix-term/src/ui/completion.rs | 4 |
2 files changed, 13 insertions, 4 deletions
diff --git a/helix-lsp/src/snippet.rs b/helix-lsp/src/snippet.rs index 87c839f9..441c419f 100644 --- a/helix-lsp/src/snippet.rs +++ b/helix-lsp/src/snippet.rs @@ -64,6 +64,7 @@ pub fn into_transaction<'a>( edit: &lsp_types::TextEdit, line_ending: &str, offset_encoding: OffsetEncoding, + include_placeholer: bool, ) -> helix_core::Transaction { use helix_core::{smallvec, Range, Selection, Transaction}; use SnippetElement::*; @@ -119,10 +120,14 @@ pub fn into_transaction<'a>( // https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html // would make this a bit nicer Text(text) => { - let len_chars = text.chars().count(); - tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1))); - offset += len_chars; - insert.push_str(text); + if include_placeholer { + let len_chars = text.chars().count(); + tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1))); + offset += len_chars; + insert.push_str(text); + } else { + tabstops.push((tabstop, Range::point(offset))); + } } other => { log::error!( diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 6897305d..c7955a3d 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -118,6 +118,7 @@ impl Completion { offset_encoding: helix_lsp::OffsetEncoding, start_offset: usize, trigger_offset: usize, + include_placeholder: bool, ) -> Transaction { use helix_lsp::snippet; @@ -144,6 +145,7 @@ impl Completion { &edit, doc.line_ending.as_str(), offset_encoding, + include_placeholder, ), Err(err) => { log::error!( @@ -216,6 +218,7 @@ impl Completion { offset_encoding, start_offset, trigger_offset, + true, ); // initialize a savepoint @@ -238,6 +241,7 @@ impl Completion { offset_encoding, start_offset, trigger_offset, + false, ); doc.apply(&transaction, view.id); |