Apply additional edits for completion when the buffer is remote

This commit is contained in:
Antonio Scandurra 2022-02-02 16:22:38 +01:00
parent 91e5c2dfac
commit d765e75bad
12 changed files with 342 additions and 77 deletions

View file

@ -1,4 +1,4 @@
use crate::{diagnostic_set::DiagnosticEntry, Diagnostic, Operation};
use crate::{diagnostic_set::DiagnosticEntry, Completion, Diagnostic, Operation};
use anyhow::{anyhow, Result};
use clock::ReplicaId;
use collections::HashSet;
@ -377,3 +377,28 @@ pub fn deserialize_anchor(anchor: proto::Anchor) -> Option<Anchor> {
},
})
}
pub fn serialize_completion(completion: &Completion<Anchor>) -> proto::Completion {
proto::Completion {
old_start: Some(serialize_anchor(&completion.old_range.start)),
old_end: Some(serialize_anchor(&completion.old_range.end)),
new_text: completion.new_text.clone(),
lsp_completion: serde_json::to_vec(&completion.lsp_completion).unwrap(),
}
}
pub fn deserialize_completion(completion: proto::Completion) -> Result<Completion<Anchor>> {
let old_start = completion
.old_start
.and_then(deserialize_anchor)
.ok_or_else(|| anyhow!("invalid old start"))?;
let old_end = completion
.old_end
.and_then(deserialize_anchor)
.ok_or_else(|| anyhow!("invalid old end"))?;
Ok(Completion {
old_range: old_start..old_end,
new_text: completion.new_text,
lsp_completion: serde_json::from_slice(&completion.lsp_completion)?,
})
}