diff options
author | Wojciech Kępka | 2021-06-07 17:01:07 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-08 00:38:53 +0000 |
commit | 6fc0e0b5fbe29e1b3ace2d1a0abc5a5b3d8380f8 (patch) | |
tree | 9bf1537cad07bb1c6108e37f0a5733e61bc44c6f /helix-term/src | |
parent | 0201ef920516db0fd4a4e6939f87bd0d7e4cf5dd (diff) |
completion: Fix unimplemented autocomplete
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/ui/completion.rs | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index a24a0757..00ecce03 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -108,20 +108,6 @@ impl Completion { let item = item.unwrap(); use helix_lsp::{lsp, util}; - // determine what to insert: text_edit | insert_text | label - let edit = if let Some(edit) = &item.text_edit { - match edit { - lsp::CompletionTextEdit::Edit(edit) => edit.clone(), - lsp::CompletionTextEdit::InsertAndReplace(item) => { - unimplemented!("completion: insert_and_replace {:?}", item) - } - } - } else { - item.insert_text.as_ref().unwrap_or(&item.label); - unimplemented!(); - // lsp::TextEdit::new(); TODO: calculate a TextEdit from insert_text - // and we insert at position. - }; // if more text was entered, remove it let cursor = doc.selection(view.id).cursor(); @@ -134,11 +120,27 @@ impl Completion { } use helix_lsp::OffsetEncoding; - let transaction = util::generate_transaction_from_edits( - doc.text(), - vec![edit], - offset_encoding, // TODO: should probably transcode in Client - ); + let transaction = if let Some(edit) = &item.text_edit { + let edit = match edit { + lsp::CompletionTextEdit::Edit(edit) => edit.clone(), + lsp::CompletionTextEdit::InsertAndReplace(item) => { + unimplemented!("completion: insert_and_replace {:?}", item) + } + }; + util::generate_transaction_from_edits( + doc.text(), + vec![edit], + offset_encoding, // TODO: should probably transcode in Client + ) + } else { + let text = item.insert_text.as_ref().unwrap_or(&item.label); + let cursor = doc.selection(view.id).cursor(); + Transaction::change( + doc.text(), + vec![(cursor, cursor, Some(text.as_str().into()))].into_iter(), + ) + }; + doc.apply(&transaction, view.id); // TODO: merge edit with additional_text_edits |