aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-01-06 05:30:33 +0000
committerBlaž Hrastnik2021-01-06 05:30:33 +0000
commit8b95c3353b9e467dd094f737e56ebe40baffcd02 (patch)
treea9626ac245a88520e816a88634be31605af1362c
parent3bf4e1e8fa1c7ffbc6866c00beb6bd9d637d44ff (diff)
lsp: buggy insert completion.
-rw-r--r--helix-term/src/commands.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 1a851413..5ced5ad0 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -864,11 +864,34 @@ pub fn completion(cx: &mut Context) {
// TODO: use item.filter_text for filtering
},
|editor: &mut Editor, item| {
- // if item.text_edit is Some we use that, else
- // let insert_text = &item.insert_text.unwrap_or(item.label);
- // and we insert at position.
- //
- // merge this with additional_text_edits
+ 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.
+ };
+
+ // TODO: merge edit with additional_text_edits
+ if let Some(additional_edits) = &item.additional_text_edits {
+ if !additional_edits.is_empty() {
+ unimplemented!("completion: additional_text_edits: {:?}", additional_edits);
+ }
+ }
+
+ let view = editor.view_mut().unwrap();
+ let transaction =
+ util::generate_transaction_from_edits(&view.doc.state, vec![edit]);
+ view.doc.apply(&transaction);
+ // TODO: append_changes_to_history(cx); if not in insert mode?
},
);