on master help sign in
lsp: buggy insert completion.
8b95c33Blaž Hrastnik
helix-term/src/commands.rs+28−5
@@ -864,11 +864,34 @@ pub fn completion(cx: &mut Context) {
864 // TODO: use item.filter_text for filtering
864 // TODO: use item.filter_text for filtering
865 },
865 },
866 |editor: &mut Editor, item| {
866 |editor: &mut Editor, item| {
867− // if item.text_edit is Some we use that, else
867+ use helix_lsp::{lsp, util};
868+ // determine what to insert: text_edit | insert_text | label
869+ let edit = if let Some(edit) = &item.text_edit {
870+ match edit {
871+ lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
872+ lsp::CompletionTextEdit::InsertAndReplace(item) => {
873+ unimplemented!("completion: insert_and_replace {:?}", item)
874+ }
875+ }
876+ } else {
868− // let insert_text = &item.insert_text.unwrap_or(item.label);
877+ item.insert_text.as_ref().unwrap_or(&item.label);
878+ unimplemented!();
879+ // lsp::TextEdit::new(); TODO: calculate a TextEdit from insert_text
869− // and we insert at position.
880+ // and we insert at position.
870− //
881+ };
882+
871− // merge this with additional_text_edits
883+ // TODO: merge edit with additional_text_edits
884+ if let Some(additional_edits) = &item.additional_text_edits {
885+ if !additional_edits.is_empty() {
886+ unimplemented!("completion: additional_text_edits: {:?}", additional_edits);
887+ }
888+ }
889+
890+ let view = editor.view_mut().unwrap();
891+ let transaction =
892+ util::generate_transaction_from_edits(&view.doc.state, vec![edit]);
893+ view.doc.apply(&transaction);
894+ // TODO: append_changes_to_history(cx); if not in insert mode?
872 },
895 },
873 );
896 );
874
897