diff options
author | Blaž Hrastnik | 2020-12-03 04:12:40 +0000 |
---|---|---|
committer | GitHub | 2020-12-03 04:12:40 +0000 |
commit | b7a3e525ed7fed5ed79e8580df2e3496bd994419 (patch) | |
tree | d202637047759b0510a16d8c59fdbbde62b50617 /helix-core/src/state.rs | |
parent | 2e12fc9a7cd221bb7b5f4b5c1ece599089770ccb (diff) | |
parent | 39bf1ca82514e1dc56dfebdce2558cce662367d1 (diff) |
Merge pull request #5 from helix-editor/lsp
LSP: mk1
Diffstat (limited to 'helix-core/src/state.rs')
-rw-r--r-- | helix-core/src/state.rs | 78 |
1 files changed, 2 insertions, 76 deletions
diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs index 1b0a67ae..4d531aa0 100644 --- a/helix-core/src/state.rs +++ b/helix-core/src/state.rs @@ -1,33 +1,14 @@ use crate::graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary, RopeGraphemes}; use crate::syntax::LOADER; -use crate::{ChangeSet, Position, Range, Rope, RopeSlice, Selection, Syntax}; +use crate::{ChangeSet, Diagnostic, Position, Range, Rope, RopeSlice, Selection, Syntax}; use anyhow::Error; -use std::path::PathBuf; - -#[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub enum Mode { - Normal, - Insert, - Goto, -} - /// A state represents the current editor state of a single buffer. +#[derive(Clone)] pub struct State { // TODO: fields should be private but we need to refactor commands.rs first - /// Path to file on disk. - pub path: Option<PathBuf>, pub doc: Rope, pub selection: Selection, - pub mode: Mode, - - pub restore_cursor: bool, - - // - pub syntax: Option<Syntax>, - /// Pending changes since last history commit. - pub changes: ChangeSet, - pub old_state: Option<(Rope, Selection)>, } #[derive(Copy, Clone, PartialEq, Eq)] @@ -46,57 +27,12 @@ pub enum Granularity { impl State { #[must_use] pub fn new(doc: Rope) -> Self { - let changes = ChangeSet::new(&doc); - let old_state = Some((doc.clone(), Selection::single(0, 0))); - Self { - path: None, doc, selection: Selection::single(0, 0), - mode: Mode::Normal, - restore_cursor: false, - syntax: None, - changes, - old_state, } } - // TODO: passing scopes here is awkward - pub fn load(path: PathBuf, scopes: &[String]) -> Result<Self, Error> { - use std::{env, fs::File, io::BufReader, path::PathBuf}; - let _current_dir = env::current_dir()?; - - let doc = Rope::from_reader(BufReader::new(File::open(path.clone())?))?; - - // TODO: create if not found - - let mut state = Self::new(doc); - - if let Some(language_config) = LOADER.language_config_for_file_name(path.as_path()) { - let highlight_config = language_config.highlight_config(scopes).unwrap().unwrap(); - // TODO: config.configure(scopes) is now delayed, is that ok? - - let syntax = Syntax::new(&state.doc, highlight_config.clone()); - - state.syntax = Some(syntax); - }; - - state.path = Some(path); - - Ok(state) - } - - pub fn set_language(&mut self, scope: &str, scopes: &[String]) { - if let Some(language_config) = LOADER.language_config_for_scope(scope) { - let highlight_config = language_config.highlight_config(scopes).unwrap().unwrap(); - // TODO: config.configure(scopes) is now delayed, is that ok? - - let syntax = Syntax::new(&self.doc, highlight_config.clone()); - - self.syntax = Some(syntax); - }; - } - // TODO: doc/selection accessors // TODO: be able to take either Rope or RopeSlice @@ -110,16 +46,6 @@ impl State { &self.selection } - #[inline] - pub fn mode(&self) -> Mode { - self.mode - } - - #[inline] - pub fn path(&self) -> Option<&PathBuf> { - self.path.as_ref() - } - // pub fn doc<R>(&self, range: R) -> RopeSlice // where // R: std::ops::RangeBounds<usize>, |