@@ -58,7 +58,7 @@ use helix_lsp::lsp;
58use url::Url;
58use url::Url;
60impl Document {
60impl Document {
61− fn new(state: State) -> Self {
61+ pub fn new(state: State) -> Self {
62 let changes = ChangeSet::new(&state.doc);
62 let changes = ChangeSet::new(&state.doc);
63 let old_state = None;
63 let old_state = None;
@@ -294,3 +294,83 @@ impl Document {
294 lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version)
294 lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version)
303+ fn changeset_to_changes() {
304+ use helix_core::{Rope, State, Transaction};
305+ // use helix_view::Document;
306+ use helix_lsp::{lsp, Client};
307+ let text = Rope::from("hello");
308+ let mut state = State::new(text);
309+ state.selection = Selection::single(5, 5);
310+ let mut doc = Document::new(state);
314+ let transaction = Transaction::insert(&doc.state, " world".into());
315+ let old_doc = doc.state.clone();
316+ let changes = Client::changeset_to_changes(&old_doc.doc, transaction.changes());
317+ doc.apply(&transaction);
321+ &[lsp::TextDocumentContentChangeEvent {
322+ range: Some(lsp::Range::new(
323+ lsp::Position::new(0, 5),
324+ lsp::Position::new(0, 5)
326+ text: " world".into(),
333+ let transaction = transaction.invert(&old_doc);
334+ let old_doc = doc.state.clone();
335+ let changes = Client::changeset_to_changes(&old_doc.doc, transaction.changes());
336+ doc.apply(&transaction);
339+ // col: 0-based, gaps between chars.
340+ // 0 1 2 3 4 5 6 7 8 9 0 1
341+ // |h|e|l|l|o| |w|o|r|l|d|
346+ &[lsp::TextDocumentContentChangeEvent {
347+ range: Some(lsp::Range::new(
348+ lsp::Position::new(0, 5),
349+ lsp::Position::new(0, 11)
358+ doc.state.selection = Selection::single(0, 5);
359+ let transaction = Transaction::change_by_selection(&doc.state, |range| {
360+ (range.from(), range.to(), Some("aeiou".into()))
362+ let changes = Client::changeset_to_changes(&doc.state.doc, transaction.changes());
366+ &[lsp::TextDocumentContentChangeEvent {
367+ range: Some(lsp::Range::new(
368+ lsp::Position::new(0, 0),
369+ lsp::Position::new(0, 5)
371+ text: "aeiou".into(),