From 06d8d3f55fbf02bb4d938ecbc479cd60309a0a5d Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 4 Jun 2021 10:50:03 +0900 Subject: Try to detect language when document file path is set Fixes #91 --- helix-core/src/indent.rs | 35 +++++++++++++++++++---------------- helix-core/src/syntax.rs | 8 +++++++- 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'helix-core') diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index fc253f91..7ab810fd 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -251,22 +251,25 @@ where Configuration, IndentationConfiguration, Lang, LanguageConfiguration, Loader, }; use once_cell::sync::OnceCell; - let loader = Loader::new(Configuration { - language: vec![LanguageConfiguration { - scope: "source.rust".to_string(), - file_types: vec!["rs".to_string()], - language_id: Lang::Rust, - highlight_config: OnceCell::new(), - // - roots: vec![], - language_server: None, - indent: Some(IndentationConfiguration { - tab_width: 4, - unit: String::from(" "), - }), - indent_query: OnceCell::new(), - }], - }); + let loader = Loader::new( + Configuration { + language: vec![LanguageConfiguration { + scope: "source.rust".to_string(), + file_types: vec!["rs".to_string()], + language_id: Lang::Rust, + highlight_config: OnceCell::new(), + // + roots: vec![], + language_server: None, + indent: Some(IndentationConfiguration { + tab_width: 4, + unit: String::from(" "), + }), + indent_query: OnceCell::new(), + }], + }, + Vec::new(), + ); // set runtime path so we can find the queries let mut runtime = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index febbf821..ec95708b 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -166,13 +166,15 @@ pub struct Loader { // highlight_names ? language_configs: Vec>, language_config_ids_by_file_type: HashMap, // Vec + scopes: Vec, } impl Loader { - pub fn new(config: Configuration) -> Self { + pub fn new(config: Configuration, scopes: Vec) -> Self { let mut loader = Self { language_configs: Vec::new(), language_config_ids_by_file_type: HashMap::new(), + scopes, }; for config in config.language { @@ -192,6 +194,10 @@ impl Loader { loader } + pub fn scopes(&self) -> &[String] { + &self.scopes + } + pub fn language_config_for_file_name(&self, path: &Path) -> Option> { // Find all the language configurations that match this file name // or a suffix of the file name. -- cgit v1.2.3-70-g09d2