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.
pull/5465/merge
Pascal Kuthe 1 year ago committed by Blaž Hrastnik
parent ded4381728
commit ba24cfe912

@ -64,6 +64,7 @@ pub fn into_transaction<'a>(
edit: &lsp_types::TextEdit, edit: &lsp_types::TextEdit,
line_ending: &str, line_ending: &str,
offset_encoding: OffsetEncoding, offset_encoding: OffsetEncoding,
include_placeholer: bool,
) -> helix_core::Transaction { ) -> helix_core::Transaction {
use helix_core::{smallvec, Range, Selection, Transaction}; use helix_core::{smallvec, Range, Selection, Transaction};
use SnippetElement::*; use SnippetElement::*;
@ -119,10 +120,14 @@ pub fn into_transaction<'a>(
// https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html // https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html
// would make this a bit nicer // would make this a bit nicer
Text(text) => { Text(text) => {
if include_placeholer {
let len_chars = text.chars().count(); let len_chars = text.chars().count();
tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1))); tabstops.push((tabstop, Range::new(offset, offset + len_chars + 1)));
offset += len_chars; offset += len_chars;
insert.push_str(text); insert.push_str(text);
} else {
tabstops.push((tabstop, Range::point(offset)));
}
} }
other => { other => {
log::error!( log::error!(

@ -118,6 +118,7 @@ impl Completion {
offset_encoding: helix_lsp::OffsetEncoding, offset_encoding: helix_lsp::OffsetEncoding,
start_offset: usize, start_offset: usize,
trigger_offset: usize, trigger_offset: usize,
include_placeholder: bool,
) -> Transaction { ) -> Transaction {
use helix_lsp::snippet; use helix_lsp::snippet;
@ -144,6 +145,7 @@ impl Completion {
&edit, &edit,
doc.line_ending.as_str(), doc.line_ending.as_str(),
offset_encoding, offset_encoding,
include_placeholder,
), ),
Err(err) => { Err(err) => {
log::error!( log::error!(
@ -216,6 +218,7 @@ impl Completion {
offset_encoding, offset_encoding,
start_offset, start_offset,
trigger_offset, trigger_offset,
true,
); );
// initialize a savepoint // initialize a savepoint
@ -238,6 +241,7 @@ impl Completion {
offset_encoding, offset_encoding,
start_offset, start_offset,
trigger_offset, trigger_offset,
false,
); );
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);

Loading…
Cancel
Save