on master help sign in
Reduce State use a bit further

This is a legacy type that should be fully removed.

commit9d4c3015632abba2ae6713874907825f6335b71a authorBlaž Hrastnik <blaz@mxxn.io> dateTue 24 Aug 2021, 23:43 (5 years ago) parent44a0512
3 files changed+13−38
helix-core/src/state.rs−24 helix-core/src/syntax.rs+8−9 helix-core/src/transaction.rs+5−5
helix-core/src/state.rs−24
@@ -1,6 +1,5 @@
11use crate::{Rope, Selection};
22
3−/// A state represents the current editor state of a single buffer.
43#[derive(Debug, Clone)]
54pub struct State {
65 pub doc: Rope,
@@ -15,27 +14,4 @@ impl State {
1514 selection: Selection::point(0),
1615 }
1716 }
18−
19− // update/transact:
20− // update(desc) => transaction ? transaction.doc() for applied doc
21− // transaction.apply(doc)
22− // doc.transact(fn -> ... end)
23−
24− // replaceSelection (transaction that replaces selection)
25− // changeByRange
26− // changes
27− // slice
28− //
29− // getters:
30− // tabSize
31− // indentUnit
32− // languageDataAt()
33− //
34− // config:
35− // indentation
36− // tabSize
37− // lineUnit
38− // syntax
39− // foldable
40− // changeFilter/transactionFilter
4117}
helix-core/src/syntax.rs+8−9
@@ -1828,15 +1828,14 @@ mod test {
18281828
18291829 #[test]
18301830 fn test_input_edits() {
1831− use crate::State;
18321831 use tree_sitter::InputEdit;
18331832
1834− let state = State::new("hello world!\ntest 123".into());
1833+ let doc = Rope::from("hello world!\ntest 123");
18351834 let transaction = Transaction::change(
1836− &state.doc,
1835+ &doc,
18371836 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
18381837 );
1839− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1838+ let edits = LanguageLayer::generate_edits(doc.slice(..), transaction.changes());
18401839 // transaction.apply(&mut state);
18411840
18421841 assert_eq!(
@@ -1862,13 +1861,13 @@ mod test {
18621861 );
18631862
18641863 // Testing with the official example from tree-sitter
1865− let mut state = State::new("fn test() {}".into());
1864+ let mut doc = Rope::from("fn test() {}");
18661865 let transaction =
1867− Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1868− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1869− transaction.apply(&mut state.doc);
1866+ Transaction::change(&doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1867+ let edits = LanguageLayer::generate_edits(doc.slice(..), transaction.changes());
1868+ transaction.apply(&mut doc);
18701869
1871− assert_eq!(state.doc, "fn test(a: u32) {}");
1870+ assert_eq!(doc, "fn test(a: u32) {}");
18721871 assert_eq!(
18731872 edits,
18741873 &[InputEdit {
helix-core/src/transaction.rs+5−5
@@ -689,21 +689,21 @@ mod test {
689689
690690 #[test]
691691 fn transaction_change() {
692− let mut state = State::new("hello world!\ntest 123".into());
692+ let mut doc = Rope::from("hello world!\ntest 123".into());
693693 let transaction = Transaction::change(
694694 &state.doc,
695695 // (1, 1, None) is a useless 0-width delete
696696 vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
697697 );
698− transaction.apply(&mut state.doc);
699− assert_eq!(state.doc, Rope::from_str("hello void! 123"));
698+ transaction.apply(&mut doc);
699+ assert_eq!(doc, Rope::from_str("hello void! 123"));
700700 }
701701
702702 #[test]
703703 fn changes_iter() {
704− let state = State::new("hello world!\ntest 123".into());
704+ let doc = Rope::from("hello world!\ntest 123".into());
705705 let changes = vec![(6, 11, Some("void".into())), (12, 17, None)];
706− let transaction = Transaction::change(&state.doc, changes.clone().into_iter());
706+ let transaction = Transaction::change(&doc, changes.clone().into_iter());
707707 assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
708708 }
709709