From 2f2306475cac7ee9385b816424137421c13bf4c2 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Fri, 12 May 2023 16:42:00 +0200 Subject: async picker syntax highlighting --- helix-view/src/document.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'helix-view/src/document.rs') diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index e29e52cc..770341dc 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -154,9 +154,9 @@ pub struct Document { /// The document's default line ending. pub line_ending: LineEnding, - syntax: Option, + pub syntax: Option, /// Corresponding language scope name. Usually `source.`. - pub(crate) language: Option>, + pub language: Option>, /// Pending changes since last history commit. changes: ChangeSet, @@ -869,12 +869,20 @@ impl Document { /// Detect the programming language based on the file type. pub fn detect_language(&mut self, config_loader: Arc) { - if let Some(path) = &self.path { - let language_config = config_loader - .language_config_for_file_name(path) - .or_else(|| config_loader.language_config_for_shebang(self.text())); - self.set_language(language_config, Some(config_loader)); - } + self.set_language( + self.detect_language_config(&config_loader), + Some(config_loader), + ); + } + + /// Detect the programming language based on the file type. + pub fn detect_language_config( + &self, + config_loader: &syntax::Loader, + ) -> Option> { + config_loader + .language_config_for_file_name(self.path.as_ref()?) + .or_else(|| config_loader.language_config_for_shebang(self.text())) } /// Detect the indentation used in the file, or otherwise defaults to the language indentation -- cgit v1.2.3-70-g09d2