aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-17 07:35:34 +0000
committerBlaž Hrastnik2021-05-17 07:35:34 +0000
commit8949347e2c5d523b7045440f1f51c42a769392dd (patch)
treedb24fa1085dcba0f7de651021e0c0ddd8d8797f8
parent54de768915d6c4cde339261712a3188be20a62ff (diff)
Completion: apply additionalTextEdits.
Used for adding imports to the file when completing.
-rw-r--r--helix-term/src/ui/completion.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 6fc7967a..719daa0f 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -82,16 +82,6 @@ impl Completion {
// 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
- );
- }
- }
-
// if more text was entered, remove it
let cursor = doc.selection(view.id).cursor();
if trigger_offset < cursor {
@@ -109,6 +99,19 @@ impl Completion {
offset_encoding, // TODO: should probably transcode in Client
);
doc.apply(&transaction, view.id);
+
+ // TODO: merge edit with additional_text_edits
+ if let Some(additional_edits) = &item.additional_text_edits {
+ // gopls uses this to add extra imports
+ if !additional_edits.is_empty() {
+ let transaction = util::generate_transaction_from_edits(
+ doc.text(),
+ additional_edits.clone(),
+ offset_encoding, // TODO: should probably transcode in Client
+ );
+ doc.apply(&transaction, view.id);
+ }
+ }
}
_ => (),
};