Adjust LSP changeset generation too: insert now always preceedes delete.

pull/8/head
Blaž Hrastnik 4 years ago
parent b4312c9492
commit 0541fbb85f

@ -268,7 +268,7 @@ impl Client {
Delete(i) | Retain(i) => *i,
Insert(_) => 0,
};
let old_end = old_pos + len;
let mut old_end = old_pos + len;
match change {
Retain(_) => {}
@ -276,31 +276,32 @@ impl Client {
let start = pos_to_lsp_pos(&old_text, old_pos);
let end = pos_to_lsp_pos(&old_text, old_end);
// a subsequent ins means a replace, consume it
if let Some(Insert(s)) = iter.peek() {
// deletion
changes.push(lsp::TextDocumentContentChangeEvent {
range: Some(lsp::Range::new(start, end)),
text: "".to_string(),
range_length: None,
});
}
Insert(s) => {
let start = pos_to_lsp_pos(&old_text, old_pos);
// a subsequent delete means a replace, consume it
let end = if let Some(Delete(len)) = iter.peek() {
old_end = old_pos + len;
let end = pos_to_lsp_pos(&old_text, old_end);
iter.next();
// replacement
changes.push(lsp::TextDocumentContentChangeEvent {
range: Some(lsp::Range::new(start, end)),
text: s.into(),
range_length: None,
});
end
} else {
// deletion
changes.push(lsp::TextDocumentContentChangeEvent {
range: Some(lsp::Range::new(start, end)),
text: "".to_string(),
range_length: None,
});
// insert
start
};
}
Insert(s) => {
let start = pos_to_lsp_pos(&old_text, old_pos);
// insert
changes.push(lsp::TextDocumentContentChangeEvent {
range: Some(lsp::Range::new(start, start)),
range: Some(lsp::Range::new(start, end)),
text: s.into(),
range_length: None,
});

Loading…
Cancel
Save