diff options
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 30 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 3 |
2 files changed, 15 insertions, 18 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index f394f2be..033a3593 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -4,7 +4,8 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use helix_core::{ - syntax::LOADER, ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction, + syntax::{LanguageConfiguration, LOADER}, + ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction, }; #[derive(Copy, Clone, PartialEq, Eq, Hash)] @@ -26,8 +27,8 @@ pub struct Document { /// Tree-sitter AST tree pub syntax: Option<Syntax>, - /// Corresponding language scope name. Usually `source.<lang>`. - language: Option<String>, + // /// Corresponding language scope name. Usually `source.<lang>`. + pub(crate) language: Option<Arc<LanguageConfiguration>>, /// Pending changes since last history commit. changes: ChangeSet, @@ -144,20 +145,13 @@ impl Document { scopes: &[String], ) { if let Some(language_config) = language_config { - // TODO: maybe just keep an Arc<> pointer to the language_config? - self.language = Some(language_config.scope().to_string()); - - // TODO: this ties lsp support to tree-sitter enabled languages for now. Language - // config should use Option<HighlightConfig> to let us have non-tree-sitter configs. - - let highlight_config = language_config - .highlight_config(scopes) - .expect("No highlight_config found!"); - // TODO: config.configure(scopes) is now delayed, is that ok? - - let syntax = Syntax::new(&self.state.doc, highlight_config); + if let Some(highlight_config) = language_config.highlight_config(scopes) { + let syntax = Syntax::new(&self.state.doc, highlight_config); + self.syntax = Some(syntax); + // TODO: config.configure(scopes) is now delayed, is that ok? + } - self.syntax = Some(syntax); + self.language = Some(language_config); } else { self.syntax = None; self.language = None; @@ -286,7 +280,9 @@ impl Document { #[inline] /// Corresponding language scope name. Usually `source.<lang>`. pub fn language(&self) -> Option<&str> { - self.language.as_deref() + self.language + .as_ref() + .map(|language| language.scope.as_str()) } #[inline] diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c072d76f..01a2dac5 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -39,7 +39,8 @@ impl Editor { // try to find a language server based on the language name let language_server = doc - .language() + .language + .as_ref() .and_then(|language| self.language_servers.get(language, &executor)); if let Some(language_server) = language_server { |