aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/ui/completion.rs46
1 files changed, 36 insertions, 10 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index a24da20a..6897305d 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -119,7 +119,9 @@ impl Completion {
start_offset: usize,
trigger_offset: usize,
) -> Transaction {
- let transaction = if let Some(edit) = &item.text_edit {
+ use helix_lsp::snippet;
+
+ if let Some(edit) = &item.text_edit {
let edit = match edit {
lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
lsp::CompletionTextEdit::InsertAndReplace(item) => {
@@ -128,12 +130,38 @@ impl Completion {
}
};
- util::generate_transaction_from_completion_edit(
- doc.text(),
- doc.selection(view_id),
- edit,
- offset_encoding, // TODO: should probably transcode in Client
- )
+ if matches!(item.kind, Some(lsp::CompletionItemKind::SNIPPET))
+ || matches!(
+ item.insert_text_format,
+ Some(lsp::InsertTextFormat::SNIPPET)
+ )
+ {
+ match snippet::parse(&edit.new_text) {
+ Ok(snippet) => snippet::into_transaction(
+ snippet,
+ doc.text(),
+ doc.selection(view_id),
+ &edit,
+ doc.line_ending.as_str(),
+ offset_encoding,
+ ),
+ Err(err) => {
+ log::error!(
+ "Failed to parse snippet: {:?}, remaining output: {}",
+ &edit.new_text,
+ err
+ );
+ Transaction::new(doc.text())
+ }
+ }
+ } else {
+ util::generate_transaction_from_completion_edit(
+ doc.text(),
+ doc.selection(view_id),
+ edit,
+ offset_encoding, // TODO: should probably transcode in Client
+ )
+ }
} else {
let text = item.insert_text.as_ref().unwrap_or(&item.label);
// Some LSPs just give you an insertText with no offset ¯\_(ツ)_/¯
@@ -157,9 +185,7 @@ impl Completion {
(cursor, cursor, Some(text.into()))
})
- };
-
- transaction
+ }
}
fn completion_changes(transaction: &Transaction, trigger_offset: usize) -> Vec<Change> {