aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-02-17 08:28:55 +0000
committerBlaž Hrastnik2021-02-17 08:28:55 +0000
commitd5f9622e2ee82887904ff5d5d433438075228cd1 (patch)
treed2d10ab7301c4c9feaff9fc4ce39ebd63a91f91e /helix-view
parent9cac44c7c0f5696c8749fd8fdd32b8174723ab5d (diff)
lsp: edit events change ranges need to affect each other.
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/document.rs55
1 files changed, 41 insertions, 14 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index dbe71c80..72a2710d 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -183,6 +183,7 @@ impl Document {
let notify = language_server.text_document_did_change(
self.versioned_identifier(),
&old_doc,
+ self.text(),
transaction.changes(),
);
@@ -301,8 +302,8 @@ mod test {
let transaction = Transaction::insert(&doc.state, " world".into());
let old_doc = doc.state.clone();
- let changes = Client::changeset_to_changes(&old_doc.doc, transaction.changes());
doc.apply(&transaction);
+ let changes = Client::changeset_to_changes(&old_doc.doc, doc.text(), transaction.changes());
assert_eq!(
changes,
@@ -320,8 +321,8 @@ mod test {
let transaction = transaction.invert(&old_doc);
let old_doc = doc.state.clone();
- let changes = Client::changeset_to_changes(&old_doc.doc, transaction.changes());
doc.apply(&transaction);
+ let changes = Client::changeset_to_changes(&old_doc.doc, doc.text(), transaction.changes());
// line: 0-based.
// col: 0-based, gaps between chars.
@@ -343,22 +344,48 @@ mod test {
// replace
+ // also tests that changes are layered, positions depend on previous changes.
+
doc.state.selection = Selection::single(0, 5);
- let transaction = Transaction::change_by_selection(&doc.state, |range| {
- (range.from(), range.to(), Some("aeiou".into()))
- });
- let changes = Client::changeset_to_changes(&doc.state.doc, transaction.changes());
+ let transaction = Transaction::change(
+ &doc.state,
+ vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
+ );
+ // aeilou
+ doc.apply(&transaction);
+ let changes =
+ Client::changeset_to_changes(&doc.state.doc, doc.text(), transaction.changes());
assert_eq!(
changes,
- &[lsp::TextDocumentContentChangeEvent {
- range: Some(lsp::Range::new(
- lsp::Position::new(0, 0),
- lsp::Position::new(0, 5)
- )),
- text: "aeiou".into(),
- range_length: None,
- }]
+ &[
+ // 0 1 2 3 4 5
+ // |h|e|l|l|o|
+ // ----
+ //
+ // aeillo
+ lsp::TextDocumentContentChangeEvent {
+ range: Some(lsp::Range::new(
+ lsp::Position::new(0, 0),
+ lsp::Position::new(0, 2)
+ )),
+ text: "aei".into(),
+ range_length: None,
+ },
+ // 0 1 2 3 4 5 6
+ // |a|e|i|l|l|o|
+ // -----
+ //
+ // aeilou
+ lsp::TextDocumentContentChangeEvent {
+ range: Some(lsp::Range::new(
+ lsp::Position::new(0, 4),
+ lsp::Position::new(0, 6)
+ )),
+ text: "ou".into(),
+ range_length: None,
+ }
+ ]
);
}
}