on master help sign in
Delete snippet placeholders when accepting completion
ba24cfePascal Kuthe
helix-lsp/src/snippet.rs+9−4
@@ -64,6 +64,7 @@ pub fn into_transaction<'a>(
64 edit: &lsp_types::TextEdit,
64 edit: &lsp_types::TextEdit,
65 line_ending: &str,
65 line_ending: &str,
66 offset_encoding: OffsetEncoding,
66 offset_encoding: OffsetEncoding,
67+ include_placeholer: bool,
67) -> helix_core::Transaction {
68) -> helix_core::Transaction {
68 use helix_core::{smallvec, Range, Selection, Transaction};
69 use helix_core::{smallvec, Range, Selection, Transaction};
69 use SnippetElement::*;
70 use SnippetElement::*;
@@ -119,10 +120,14 @@ pub fn into_transaction<'a>(
119 // https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html
120 // https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html
120 // would make this a bit nicer
121 // would make this a bit nicer
121 Text(text) => {
122 Text(text) => {
123+ if include_placeholer {
122− let len_chars = text.chars().count();
124+ let len_chars = text.chars().count();
123− tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1)));
125+ tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1)));
124− offset += len_chars;
126+ offset += len_chars;
125− insert.push_str(text);
127+ insert.push_str(text);
128+ } else {
129+ tabstops.push((tabstop, Range::point(offset)));
130+ }
126 }
131 }
127 other => {
132 other => {
128 log::error!(
133 log::error!(
helix-term/src/ui/completion.rs+4
@@ -118,6 +118,7 @@ impl Completion {
118 offset_encoding: helix_lsp::OffsetEncoding,
118 offset_encoding: helix_lsp::OffsetEncoding,
119 start_offset: usize,
119 start_offset: usize,
120 trigger_offset: usize,
120 trigger_offset: usize,
121+ include_placeholder: bool,
121 ) -> Transaction {
122 ) -> Transaction {
122 use helix_lsp::snippet;
123 use helix_lsp::snippet;
123
124
@@ -144,6 +145,7 @@ impl Completion {
144 &edit,
145 &edit,
145 doc.line_ending.as_str(),
146 doc.line_ending.as_str(),
146 offset_encoding,
147 offset_encoding,
148+ include_placeholder,
147 ),
149 ),
148 Err(err) => {
150 Err(err) => {
149 log::error!(
151 log::error!(
@@ -216,6 +218,7 @@ impl Completion {
216 offset_encoding,
218 offset_encoding,
217 start_offset,
219 start_offset,
218 trigger_offset,
220 trigger_offset,
221+ true,
219 );
222 );
220
223
221 // initialize a savepoint
224 // initialize a savepoint
@@ -238,6 +241,7 @@ impl Completion {
238 offset_encoding,
241 offset_encoding,
239 start_offset,
242 start_offset,
240 trigger_offset,
243 trigger_offset,
244+ false,
241 );
245 );
242
246
243 doc.apply(&transaction, view.id);
247 doc.apply(&transaction, view.id);