Remove Buffer::apply_lsp_edits

Always use `edits_from_lsp`.
This commit is contained in:
Max Brunsfeld 2022-02-11 16:18:06 -08:00
parent d4b9d9e820
commit d84fc3beec
2 changed files with 7 additions and 42 deletions

View file

@ -1561,46 +1561,6 @@ impl Buffer {
})
}
pub fn apply_lsp_edits<I, T>(
&mut self,
edits: I,
version: Option<i32>,
cx: &mut ModelContext<Self>,
) -> Result<()>
where
I: IntoIterator<IntoIter = T>,
T: DoubleEndedIterator<Item = lsp::TextEdit>,
{
let mut anchored_edits = Vec::new();
let snapshot =
if let Some((version, language_server)) = version.zip(self.language_server.as_mut()) {
language_server.snapshot_for_version(version as usize)?
} else {
self.deref()
};
for edit in edits {
let range = range_from_lsp(edit.range);
if snapshot.clip_point_utf16(range.start, Bias::Left) != range.start
|| snapshot.clip_point_utf16(range.end, Bias::Left) != range.end
{
return Err(anyhow!(
"invalid formatting edits received from language server"
));
} else {
let start = snapshot.anchor_before(range.start);
let end = snapshot.anchor_before(range.end);
anchored_edits.push((start..end, edit.new_text));
}
}
self.start_transaction();
for (range, new_text) in anchored_edits.into_iter().rev() {
self.edit([range], new_text, cx);
}
self.end_transaction(cx);
Ok(())
}
fn did_edit(
&mut self,
old_version: &clock::Global,

View file

@ -1404,11 +1404,16 @@ impl Project {
let resolved_completion = lang_server
.request::<lsp::request::ResolveCompletionItem>(completion.lsp_completion)
.await?;
if let Some(additional_edits) = resolved_completion.additional_text_edits {
if let Some(edits) = resolved_completion.additional_text_edits {
let edits = buffer_handle
.update(&mut cx, |buffer, cx| buffer.edits_from_lsp(edits, None, cx))
.await?;
buffer_handle.update(&mut cx, |buffer, cx| {
buffer.finalize_last_transaction();
buffer.start_transaction();
buffer.apply_lsp_edits(additional_edits, None, cx).log_err();
for (range, text) in edits {
buffer.edit([range], text, cx);
}
let transaction = if buffer.end_transaction(cx).is_some() {
let transaction = buffer.finalize_last_transaction().unwrap().clone();
if !push_to_history {