Use CompletionTextEdit::InsertAndReplace if supported by the client

This commit is contained in:
Lukas Wirth
2021-04-08 14:22:54 +02:00
parent 3191a93185
commit 8fa3011908
5 changed files with 50 additions and 20 deletions

View File

@@ -150,8 +150,16 @@ pub(crate) fn all_edits_are_disjoint(
edit_ranges.push(edit.range);
}
Some(lsp_types::CompletionTextEdit::InsertAndReplace(edit)) => {
edit_ranges.push(edit.insert);
edit_ranges.push(edit.replace);
let replace = edit.replace;
let insert = edit.insert;
if replace.start != insert.start
|| insert.start > insert.end
|| insert.end > replace.end
{
// insert has to be a prefix of replace but it is not
return false;
}
edit_ranges.push(replace);
}
None => {}
}
@@ -310,18 +318,6 @@ mod tests {
"Completion with disjoint edits fails the validation even with empty extra edits"
);
completion_with_joint_edits.text_edit =
Some(CompletionTextEdit::InsertAndReplace(InsertReplaceEdit {
new_text: "new_text".to_string(),
insert: disjoint_edit.range,
replace: joint_edit.range,
}));
completion_with_joint_edits.additional_text_edits = None;
assert!(
!all_edits_are_disjoint(&completion_with_joint_edits, &[]),
"Completion with disjoint edits fails the validation even with empty extra edits"
);
completion_with_joint_edits.text_edit =
Some(CompletionTextEdit::InsertAndReplace(InsertReplaceEdit {
new_text: "new_text".to_string(),