on master help sign in
Completion: apply additionalTextEdits.
8949347Blaž Hrastnik
helix-term/src/ui/completion.rs+13−10
@@ -82,16 +82,6 @@ impl Completion {
82 // and we insert at position.
82 // and we insert at position.
83 };
83 };
84
84
85− // TODO: merge edit with additional_text_edits
86− if let Some(additional_edits) = &item.additional_text_edits {
87− if !additional_edits.is_empty() {
88− unimplemented!(
89− "completion: additional_text_edits: {:?}",
90− additional_edits
91− );
92− }
93− }
94−
95 // if more text was entered, remove it
85 // if more text was entered, remove it
96 let cursor = doc.selection(view.id).cursor();
86 let cursor = doc.selection(view.id).cursor();
97 if trigger_offset < cursor {
87 if trigger_offset < cursor {
@@ -109,6 +99,19 @@ impl Completion {
109 offset_encoding, // TODO: should probably transcode in Client
99 offset_encoding, // TODO: should probably transcode in Client
110 );
100 );
111 doc.apply(&transaction, view.id);
101 doc.apply(&transaction, view.id);
102+
103+ // TODO: merge edit with additional_text_edits
104+ if let Some(additional_edits) = &item.additional_text_edits {
105+ // gopls uses this to add extra imports
106+ if !additional_edits.is_empty() {
107+ let transaction = util::generate_transaction_from_edits(
108+ doc.text(),
109+ additional_edits.clone(),
110+ offset_encoding, // TODO: should probably transcode in Client
111+ );
112+ doc.apply(&transaction, view.id);
113+ }
114+ }
112 }
115 }
113 _ => (),
116 _ => (),
114 };
117 };