Send updates to the lsp on undo/redo.

pull/8/head
Blaž Hrastnik 4 years ago
parent b7da7f83c3
commit 1ffd1e7633

@ -17,7 +17,7 @@
- [x] retain horiz when moving vertically - [x] retain horiz when moving vertically
- [x] deindent - [x] deindent
- [ ] ensure_cursor_in_view always before rendering? or always in app after event process? - [ ] ensure_cursor_in_view always before rendering? or always in app after event process?
- [ ] update lsp on redo/undo - [x] update lsp on redo/undo
- [ ] Implement marks (superset of Selection/Range) - [ ] Implement marks (superset of Selection/Range)
- [ ] ctrl-v/ctrl-x on file picker - [ ] ctrl-v/ctrl-x on file picker
- [ ] linewise selection work - [ ] linewise selection work

@ -160,24 +160,13 @@ impl Document {
self.state.selection = selection; self.state.selection = selection;
} }
pub fn apply(&mut self, transaction: &Transaction) -> bool { pub fn _apply(&mut self, transaction: &Transaction) -> bool {
let old_doc = self.text().clone(); let old_doc = self.text().clone();
// store the state just before any changes are made. This allows us to undo to the
// state just before a transaction was applied.
if self.changes.is_empty() && !transaction.changes().is_empty() {
self.old_state = Some(self.state.clone());
}
let success = transaction.apply(&mut self.state); let success = transaction.apply(&mut self.state);
if !transaction.changes().is_empty() { if !transaction.changes().is_empty() {
// Compose this transaction with the previous one // TODO: self.version += 1;?
take_with(&mut self.changes, |changes| {
changes.compose(transaction.changes().clone())
});
// TODO: when composing, replace transaction.selection too
// update tree-sitter syntax tree // update tree-sitter syntax tree
if let Some(syntax) = &mut self.syntax { if let Some(syntax) = &mut self.syntax {
@ -203,21 +192,28 @@ impl Document {
success success
} }
pub fn undo(&mut self) -> bool { pub fn apply(&mut self, transaction: &Transaction) -> bool {
if let Some(transaction) = self.history.undo() { // store the state just before any changes are made. This allows us to undo to the
let old_doc = self.text().clone(); // state just before a transaction was applied.
self.version += 1; if self.changes.is_empty() && !transaction.changes().is_empty() {
let success = transaction.apply(&mut self.state); self.old_state = Some(self.state.clone());
}
// update tree-sitter syntax tree let success = self._apply(&transaction);
if let Some(syntax) = &mut self.syntax {
// TODO: no unwrap if !transaction.changes().is_empty() {
syntax // Compose this transaction with the previous one
.update(&old_doc, &self.state.doc, transaction.changes()) take_with(&mut self.changes, |changes| {
.unwrap(); changes.compose(transaction.changes().clone())
});
}
success
} }
// TODO: undo / redo need to emit changes to lsp pub fn undo(&mut self) -> bool {
if let Some(transaction) = self.history.undo() {
self.version += 1;
let success = self._apply(&transaction);
// reset changeset to fix len // reset changeset to fix len
self.changes = ChangeSet::new(self.text()); self.changes = ChangeSet::new(self.text());
@ -229,17 +225,9 @@ impl Document {
pub fn redo(&mut self) -> bool { pub fn redo(&mut self) -> bool {
if let Some(transaction) = self.history.redo() { if let Some(transaction) = self.history.redo() {
let old_doc = self.text().clone();
self.version += 1; self.version += 1;
let success = transaction.apply(&mut self.state);
// update tree-sitter syntax tree let success = self._apply(&transaction);
if let Some(syntax) = &mut self.syntax {
// TODO: no unwrap
syntax
.update(&old_doc, &self.state.doc, transaction.changes())
.unwrap();
}
// reset changeset to fix len // reset changeset to fix len
self.changes = ChangeSet::new(self.text()); self.changes = ChangeSet::new(self.text());

Loading…
Cancel
Save