view: document.rs cleanup

imgbot
Blaž Hrastnik 4 years ago
parent a323155b99
commit c1f2a14453

@ -1,4 +1,4 @@
use anyhow::Error;
use anyhow::{Context, Error};
use std::future::Future;
use std::path::{Path, PathBuf};
use std::sync::Arc;
@ -90,7 +90,8 @@ impl Document {
use std::{env, fs::File, io::BufReader};
let _current_dir = env::current_dir()?;
let doc = Rope::from_reader(BufReader::new(File::open(path.clone())?))?;
let file = File::open(path.clone()).context(format!("unable to open {:?}", path))?;
let doc = Rope::from_reader(BufReader::new(file))?;
// TODO: create if not found
@ -183,7 +184,7 @@ impl Document {
let success = transaction.apply(&mut self.state);
if !transaction.changes().is_empty() {
// TODO: self.version += 1;?
self.version += 1;
// update tree-sitter syntax tree
if let Some(syntax) = &mut self.syntax {
@ -193,7 +194,11 @@ impl Document {
.unwrap();
}
// TODO: map state.diagnostics over changes::map_pos too
// if let Some(diagnostics) = &mut self.diagnostics {
// for diagnostic in diagnostics {
// // TODO: map state.diagnostics over changes::map_pos too
// }
// }
// emit lsp notification
if let Some(language_server) = &self.language_server {
@ -230,7 +235,6 @@ impl Document {
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
@ -243,8 +247,6 @@ impl Document {
pub fn redo(&mut self) -> bool {
if let Some(transaction) = self.history.redo() {
self.version += 1;
let success = self._apply(&transaction);
// reset changeset to fix len
@ -266,9 +268,6 @@ impl Document {
// annotations either add a new layer or compose into the previous one.
let transaction = Transaction::from(changes).with_selection(self.selection().clone());
// increment document version
self.version += 1;
// HAXX: we need to reconstruct the state as it was before the changes..
let old_state = self.old_state.take().expect("no old_state available");

@ -174,6 +174,11 @@ impl Editor {
self.documents.iter().map(|(_id, doc)| doc)
}
// pub fn current_document(&self) -> Document {
// let id = self.view().doc;
// let doc = &mut editor.documents[id];
// }
pub fn cursor_position(&self) -> Option<helix_core::Position> {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
let view = self.view();

Loading…
Cancel
Save