@@ -4,7 +4,8 @@ use std::path::{Path, PathBuf};
44use std::sync::Arc;
55
66use helix_core::{
7− syntax::LOADER, ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
7+ syntax::{LanguageConfiguration, LOADER},
8+ ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
89};
910
1011#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -26,8 +27,8 @@ pub struct Document {
2627
2728 /// Tree-sitter AST tree
2829 pub syntax: Option<Syntax>,
29− /// Corresponding language scope name. Usually `source.<lang>`.
30− language: Option<String>,
30+ // /// Corresponding language scope name. Usually `source.<lang>`.
31+ pub(crate) language: Option<Arc<LanguageConfiguration>>,
3132
3233 /// Pending changes since last history commit.
3334 changes: ChangeSet,
@@ -144,20 +145,13 @@ impl Document {
144145 scopes: &[String],
145146 ) {
146147 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());
149−
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.
152−
153− let highlight_config = language_config
154− .highlight_config(scopes)
155− .expect("No highlight_config found!");
156− // TODO: config.configure(scopes) is now delayed, is that ok?
157−
158− let syntax = Syntax::new(&self.state.doc, highlight_config);
148+ if let Some(highlight_config) = language_config.highlight_config(scopes) {
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?
152+ }
159153
160− self.syntax = Some(syntax);
154+ self.language = Some(language_config);
161155 } else {
162156 self.syntax = None;
163157 self.language = None;
@@ -286,7 +280,9 @@ impl Document {
286280 #[inline]
287281 /// Corresponding language scope name. Usually `source.<lang>`.
288282 pub fn language(&self) -> Option<&str> {
289− self.language.as_deref()
283+ self.language
284+ .as_ref()
285+ .map(|language| language.scope.as_str())
290286 }
291287
292288 #[inline]