From bb87b08fc9677ddf0f083a2297c23c17144470e2 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 14 Mar 2021 17:13:55 +0900 Subject: Configure language servers via LanguageConfiguration. --- helix-view/src/document.rs | 30 +++++++++++++----------------- helix-view/src/editor.rs | 3 ++- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'helix-view') 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, - /// Corresponding language scope name. Usually `source.`. - language: Option, + // /// Corresponding language scope name. Usually `source.`. + pub(crate) language: Option>, /// 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 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.`. 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 { -- cgit v1.2.3-70-g09d2