on master help sign in
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.

commitba24cfe9125eda97346e3ceee42686fb9f46046f authorPascal Kuthe <pascal.kuthe@semimod.de> dateSat 11 Feb 2023, 14:20 (4 years ago) parentded4381
2 files changed+13−4
helix-lsp/src/snippet.rs+9−4 helix-term/src/ui/completion.rs+4
helix-lsp/src/snippet.rs+9−4
@@ -64,6 +64,7 @@ pub fn into_transaction<'a>(
6464 edit: &lsp_types::TextEdit,
6565 line_ending: &str,
6666 offset_encoding: OffsetEncoding,
67+ include_placeholer: bool,
6768) -> helix_core::Transaction {
6869 use helix_core::{smallvec, Range, Selection, Transaction};
6970 use SnippetElement::*;
@@ -119,10 +120,14 @@ pub fn into_transaction<'a>(
119120 // https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html
120121 // would make this a bit nicer
121122 Text(text) => {
122− let len_chars = text.chars().count();
123− tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1)));
124− offset += len_chars;
125− insert.push_str(text);
123+ if include_placeholer {
124+ let len_chars = text.chars().count();
125+ tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1)));
126+ offset += len_chars;
127+ insert.push_str(text);
128+ } else {
129+ tabstops.push((tabstop, Range::point(offset)));
130+ }
126131 }
127132 other => {
128133 log::error!(
helix-term/src/ui/completion.rs+4
@@ -118,6 +118,7 @@ impl Completion {
118118 offset_encoding: helix_lsp::OffsetEncoding,
119119 start_offset: usize,
120120 trigger_offset: usize,
121+ include_placeholder: bool,
121122 ) -> Transaction {
122123 use helix_lsp::snippet;
123124
@@ -144,6 +145,7 @@ impl Completion {
144145 &edit,
145146 doc.line_ending.as_str(),
146147 offset_encoding,
148+ include_placeholder,
147149 ),
148150 Err(err) => {
149151 log::error!(
@@ -216,6 +218,7 @@ impl Completion {
216218 offset_encoding,
217219 start_offset,
218220 trigger_offset,
221+ true,
219222 );
220223
221224 // initialize a savepoint
@@ -238,6 +241,7 @@ impl Completion {
238241 offset_encoding,
239242 start_offset,
240243 trigger_offset,
244+ false,
241245 );
242246
243247 doc.apply(&transaction, view.id);