@@ -4,7 +4,8 @@ use std::path::{Path, PathBuf};
4use std::sync::Arc;
4use std::sync::Arc;
6use helix_core::{
6use helix_core::{
7+ syntax::{LanguageConfiguration, LOADER},
7− syntax::LOADER, ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
8+ ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
10#[derive(Copy, Clone, PartialEq, Eq, Hash)]
11#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -26,8 +27,8 @@ pub struct Document {
27 /// Tree-sitter AST tree
28 /// Tree-sitter AST tree
28 pub syntax: Option<Syntax>,
29 pub syntax: Option<Syntax>,
29− /// Corresponding language scope name. Usually `source.<lang>`.
30+ // /// Corresponding language scope name. Usually `source.<lang>`.
30− language: Option<String>,
31+ pub(crate) language: Option<Arc<LanguageConfiguration>>,
32 /// Pending changes since last history commit.
33 /// Pending changes since last history commit.
33 changes: ChangeSet,
34 changes: ChangeSet,
@@ -144,20 +145,13 @@ impl Document {
144 scopes: &[String],
145 scopes: &[String],
146 if let Some(language_config) = language_config {
147 if let Some(language_config) = language_config {
147− // TODO: maybe just keep an Arc<> pointer to the language_config?
148− self.language = Some(language_config.scope().to_string());
150− // TODO: this ties lsp support to tree-sitter enabled languages for now. Language
151− // config should use Option<HighlightConfig> to let us have non-tree-sitter configs.
153− let highlight_config = language_config
148+ if let Some(highlight_config) = language_config.highlight_config(scopes) {
154− .highlight_config(scopes)
155− .expect("No highlight_config found!");
156− // TODO: config.configure(scopes) is now delayed, is that ok?
158− let syntax = Syntax::new(&self.state.doc, highlight_config);
149+ let syntax = Syntax::new(&self.state.doc, highlight_config);
150+ self.syntax = Some(syntax);
151+ // TODO: config.configure(scopes) is now delayed, is that ok?
160− self.syntax = Some(syntax);
154+ self.language = Some(language_config);
162 self.syntax = None;
156 self.syntax = None;
163 self.language = None;
157 self.language = None;
@@ -286,7 +280,9 @@ impl Document {
286 #[inline]
280 #[inline]
287 /// Corresponding language scope name. Usually `source.<lang>`.
281 /// Corresponding language scope name. Usually `source.<lang>`.
288 pub fn language(&self) -> Option<&str> {
282 pub fn language(&self) -> Option<&str> {
289− self.language.as_deref()
283+ self.language
285+ .map(|language| language.scope.as_str())
292 #[inline]
288 #[inline]