From 4d636970360c57c1d452b7d8df2341125fcac5cb Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 11 Aug 2019 09:21:49 -0700 Subject: [PATCH] cli: Fix loading of parsers with no tree-sitter section in package.json --- cli/src/loader.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cli/src/loader.rs b/cli/src/loader.rs index d29ba1fe..237718bb 100644 --- a/cli/src/loader.rs +++ b/cli/src/loader.rs @@ -370,10 +370,6 @@ impl Loader { if let Ok(package_json_contents) = fs::read_to_string(&parser_path.join("package.json")) { let package_json = serde_json::from_str::(&package_json_contents); if let Ok(package_json) = package_json { - if package_json.tree_sitter.is_empty() { - return Ok(&[]); - } - let language_count = self.languages_by_id.len(); for config_json in package_json.tree_sitter { // Determine the path to the parser directory. This can be specified in @@ -428,6 +424,23 @@ impl Loader { } } + if self.language_configurations.len() == initial_language_configuration_count + && parser_path.join("src").join("grammar.json").exists() + { + self.language_configurations.push(LanguageConfiguration { + language_id: self.languages_by_id.len(), + scope: None, + content_regex: None, + injection_regex: None, + file_types: Vec::new(), + _first_line_regex: None, + highlight_property_sheet_path: None, + highlight_property_sheet: OnceCell::new(), + }); + self.languages_by_id + .push((parser_path.to_owned(), OnceCell::new())); + } + Ok(&self.language_configurations[initial_language_configuration_count..]) } }