on master help sign in
Reduce State use a bit further
9d4c301Blaž Hrastnik
helix-core/src/state.rs−24
@@ -1,6 +1,5 @@
1use crate::{Rope, Selection};
1use crate::{Rope, Selection};
2
2
3−/// A state represents the current editor state of a single buffer.
4#[derive(Debug, Clone)]
3#[derive(Debug, Clone)]
5pub struct State {
4pub struct State {
6 pub doc: Rope,
5 pub doc: Rope,
@@ -15,27 +14,4 @@ impl State {
15 selection: Selection::point(0),
14 selection: Selection::point(0),
16 }
15 }
17 }
16 }
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
41}
17}
helix-core/src/syntax.rs+8−9
@@ -1828,15 +1828,14 @@ mod test {
1828
1828
1829 #[test]
1829 #[test]
1830 fn test_input_edits() {
1830 fn test_input_edits() {
1831− use crate::State;
1832 use tree_sitter::InputEdit;
1831 use tree_sitter::InputEdit;
1833
1832
1834− let state = State::new("hello world!\ntest 123".into());
1833+ let doc = Rope::from("hello world!\ntest 123");
1835 let transaction = Transaction::change(
1834 let transaction = Transaction::change(
1836− &state.doc,
1835+ &doc,
1837 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1836 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1838 );
1837 );
1839− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1838+ let edits = LanguageLayer::generate_edits(doc.slice(..), transaction.changes());
1840 // transaction.apply(&mut state);
1839 // transaction.apply(&mut state);
1841
1840
1842 assert_eq!(
1841 assert_eq!(
@@ -1862,13 +1861,13 @@ mod test {
1862 );
1861 );
1863
1862
1864 // Testing with the official example from tree-sitter
1863 // 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() {}");
1866 let transaction =
1865 let transaction =
1867− Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1866+ Transaction::change(&doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1868− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1867+ let edits = LanguageLayer::generate_edits(doc.slice(..), transaction.changes());
1869− transaction.apply(&mut state.doc);
1868+ transaction.apply(&mut doc);
1870
1869
1871− assert_eq!(state.doc, "fn test(a: u32) {}");
1870+ assert_eq!(doc, "fn test(a: u32) {}");
1872 assert_eq!(
1871 assert_eq!(
1873 edits,
1872 edits,
1874 &[InputEdit {
1873 &[InputEdit {
helix-core/src/transaction.rs+5−5
@@ -689,21 +689,21 @@ mod test {
689
689
690 #[test]
690 #[test]
691 fn transaction_change() {
691 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());
693 let transaction = Transaction::change(
693 let transaction = Transaction::change(
694 &state.doc,
694 &state.doc,
695 // (1, 1, None) is a useless 0-width delete
695 // (1, 1, None) is a useless 0-width delete
696 vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
696 vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
697 );
697 );
698− transaction.apply(&mut state.doc);
698+ transaction.apply(&mut doc);
699− assert_eq!(state.doc, Rope::from_str("hello void! 123"));
699+ assert_eq!(doc, Rope::from_str("hello void! 123"));
700 }
700 }
701
701
702 #[test]
702 #[test]
703 fn changes_iter() {
703 fn changes_iter() {
704− let state = State::new("hello world!\ntest 123".into());
704+ let doc = Rope::from("hello world!\ntest 123".into());
705 let changes = vec![(6, 11, Some("void".into())), (12, 17, None)];
705 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());
707 assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
707 assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
708 }
708 }
709
709