From 1113ac2073748272e9feb48c068eef39050562ab Mon Sep 17 00:00:00 2001 From: Christian Speich Date: Wed, 19 Oct 2022 10:13:39 +0200 Subject: [PATCH 1/2] grammar: Don't require lower-case (#4346) Currently we always lower-case the grammar name when loading it. While it is somewhat of an convention to name tree-sitter grammars in lowercase there is no rule to enforce it. This patch removes the lower-casing to allow all possible grammar names. Signed-off-by: Christian Speich --- helix-loader/src/grammar.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/helix-loader/src/grammar.rs b/helix-loader/src/grammar.rs index eb1895a554c6..a92cadb64b62 100644 --- a/helix-loader/src/grammar.rs +++ b/helix-loader/src/grammar.rs @@ -67,7 +67,6 @@ pub fn get_language(name: &str) -> Result { #[cfg(not(target_arch = "wasm32"))] pub fn get_language(name: &str) -> Result { use libloading::{Library, Symbol}; - let name = name.to_ascii_lowercase(); let mut library_path = crate::runtime_dir().join("grammars").join(&name); library_path.set_extension(DYLIB_EXTENSION); From 66ccfccb2458fdd96aeab689e76bd6861eed7002 Mon Sep 17 00:00:00 2001 From: Christian Speich Date: Wed, 19 Oct 2022 10:29:09 +0200 Subject: [PATCH 2/2] syntax: Don't force lower-case for filenames (#4346) Just like for grammars we currently force a lower-case of the name for some actions (like filesystem lookup). To make this consistent and less surprising for users, we remove this lower-casing here. Note: it is still the preferred way to name both language and grammar in lower-case Signed-off-by: Christian Speich --- helix-core/src/syntax.rs | 26 +++++++++++++++----------- xtask/src/querycheck.rs | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index f9a2ea5f7630..21d19ce78635 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -361,14 +361,12 @@ pub fn read_query(language: &str, filename: &str) -> String { impl LanguageConfiguration { fn initialize_highlight(&self, scopes: &[String]) -> Option> { - let language = self.language_id.to_ascii_lowercase(); - - let highlights_query = read_query(&language, "highlights.scm"); + let highlights_query = read_query(&self.language_id, "highlights.scm"); // always highlight syntax errors // highlights_query += "\n(ERROR) @error"; - let injections_query = read_query(&language, "injections.scm"); - let locals_query = read_query(&language, "locals.scm"); + let injections_query = read_query(&self.language_id, "injections.scm"); + let locals_query = read_query(&self.language_id, "locals.scm"); if highlights_query.is_empty() { None @@ -432,14 +430,20 @@ impl LanguageConfiguration { } fn load_query(&self, kind: &str) -> Option { - let lang_name = self.language_id.to_ascii_lowercase(); - let query_text = read_query(&lang_name, kind); + let query_text = read_query(&self.language_id, kind); if query_text.is_empty() { return None; } let lang = self.highlight_config.get()?.as_ref()?.language; Query::new(lang, &query_text) - .map_err(|e| log::error!("Failed to parse {} queries for {}: {}", kind, lang_name, e)) + .map_err(|e| { + log::error!( + "Failed to parse {} queries for {}: {}", + kind, + self.language_id, + e + ) + }) .ok() } } @@ -2119,7 +2123,7 @@ mod test { ); let loader = Loader::new(Configuration { language: vec![] }); - let language = get_language("Rust").unwrap(); + let language = get_language("rust").unwrap(); let query = Query::new(language, query_str).unwrap(); let textobject = TextObjectQuery { query }; @@ -2179,7 +2183,7 @@ mod test { let loader = Loader::new(Configuration { language: vec![] }); - let language = get_language("Rust").unwrap(); + let language = get_language("rust").unwrap(); let config = HighlightConfiguration::new( language, &std::fs::read_to_string("../runtime/grammars/sources/rust/queries/highlights.scm") @@ -2275,7 +2279,7 @@ mod test { let source = Rope::from_str(source); let loader = Loader::new(Configuration { language: vec![] }); - let language = get_language("Rust").unwrap(); + let language = get_language("rust").unwrap(); let config = HighlightConfiguration::new(language, "", "", "").unwrap(); let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)); diff --git a/xtask/src/querycheck.rs b/xtask/src/querycheck.rs index 5595b8ec88fb..7014c7d6f5d5 100644 --- a/xtask/src/querycheck.rs +++ b/xtask/src/querycheck.rs @@ -14,8 +14,8 @@ pub fn query_check() -> Result<(), DynError> { ]; for language in lang_config().language { - let language_name = language.language_id.to_ascii_lowercase(); - let grammar_name = language.grammar.unwrap_or(language.language_id); + let language_name = &language.language_id; + let grammar_name = language.grammar.as_ref().unwrap_or(language_name); for query_file in query_files { let language = get_language(&grammar_name); let query_text = read_query(&language_name, query_file);