Reduce State use a bit further

This is a legacy type that should be fully removed.
pull/658/head
Blaž Hrastnik 3 years ago
parent 44a0512d95
commit 9d4c301563

@ -1,6 +1,5 @@
use crate::{Rope, Selection};
/// A state represents the current editor state of a single buffer.
#[derive(Debug, Clone)]
pub struct State {
pub doc: Rope,
@ -15,27 +14,4 @@ impl State {
selection: Selection::point(0),
}
}
// update/transact:
// update(desc) => transaction ? transaction.doc() for applied doc
// transaction.apply(doc)
// doc.transact(fn -> ... end)
// replaceSelection (transaction that replaces selection)
// changeByRange
// changes
// slice
//
// getters:
// tabSize
// indentUnit
// languageDataAt()
//
// config:
// indentation
// tabSize
// lineUnit
// syntax
// foldable
// changeFilter/transactionFilter
}

@ -1828,15 +1828,14 @@ mod test {
#[test]
fn test_input_edits() {
use crate::State;
use tree_sitter::InputEdit;
let state = State::new("hello world!\ntest 123".into());
let doc = Rope::from("hello world!\ntest 123");
let transaction = Transaction::change(
&state.doc,
&doc,
vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
);
let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
let edits = LanguageLayer::generate_edits(doc.slice(..), transaction.changes());
// transaction.apply(&mut state);
assert_eq!(
@ -1862,13 +1861,13 @@ mod test {
);
// Testing with the official example from tree-sitter
let mut state = State::new("fn test() {}".into());
let mut doc = Rope::from("fn test() {}");
let transaction =
Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
transaction.apply(&mut state.doc);
Transaction::change(&doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
let edits = LanguageLayer::generate_edits(doc.slice(..), transaction.changes());
transaction.apply(&mut doc);
assert_eq!(state.doc, "fn test(a: u32) {}");
assert_eq!(doc, "fn test(a: u32) {}");
assert_eq!(
edits,
&[InputEdit {

@ -689,21 +689,21 @@ mod test {
#[test]
fn transaction_change() {
let mut state = State::new("hello world!\ntest 123".into());
let mut doc = Rope::from("hello world!\ntest 123".into());
let transaction = Transaction::change(
&state.doc,
// (1, 1, None) is a useless 0-width delete
vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
);
transaction.apply(&mut state.doc);
assert_eq!(state.doc, Rope::from_str("hello void! 123"));
transaction.apply(&mut doc);
assert_eq!(doc, Rope::from_str("hello void! 123"));
}
#[test]
fn changes_iter() {
let state = State::new("hello world!\ntest 123".into());
let doc = Rope::from("hello world!\ntest 123".into());
let changes = vec![(6, 11, Some("void".into())), (12, 17, None)];
let transaction = Transaction::change(&state.doc, changes.clone().into_iter());
let transaction = Transaction::change(&doc, changes.clone().into_iter());
assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
}

Loading…
Cancel
Save