summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-02-16 02:08:06 +0000
committerBlaž Hrastnik2021-02-16 02:08:06 +0000
commit0541fbb85f06a20d9cdec03c999ec805575be83e (patch)
tree42d516ca5506f33e19a73c69701f0de4c735bb6c
parentb4312c9492445a6a3e3baabebbc4451f89b8bd0e (diff)
Adjust LSP changeset generation too: insert now always preceedes delete.
-rw-r--r--helix-lsp/src/client.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index 0cb09d76..ebfdafe7 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -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,
});