feat(loader): add error message when a tree-sitter.json file is invalid
This commit is contained in:
parent
0dc1044d0d
commit
7b90dbf189
1 changed files with 11 additions and 4 deletions
|
|
@ -147,9 +147,10 @@ pub struct TreeSitterJSON {
|
|||
}
|
||||
|
||||
impl TreeSitterJSON {
|
||||
#[must_use]
|
||||
pub fn from_file(path: &Path) -> Option<Self> {
|
||||
serde_json::from_str(&fs::read_to_string(path.join("tree-sitter.json")).ok()?).ok()
|
||||
pub fn from_file(path: &Path) -> Result<Self> {
|
||||
Ok(serde_json::from_str(&fs::read_to_string(
|
||||
path.join("tree-sitter.json"),
|
||||
)?)?)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -1119,7 +1120,8 @@ impl Loader {
|
|||
) -> Result<&[LanguageConfiguration]> {
|
||||
let initial_language_configuration_count = self.language_configurations.len();
|
||||
|
||||
if let Some(config) = TreeSitterJSON::from_file(parser_path) {
|
||||
let ts_json = TreeSitterJSON::from_file(parser_path);
|
||||
if let Ok(config) = ts_json {
|
||||
let language_count = self.languages_by_id.len();
|
||||
for grammar in config.grammars {
|
||||
// Determine the path to the parser directory. This can be specified in
|
||||
|
|
@ -1210,6 +1212,11 @@ impl Loader {
|
|||
Some(self.language_configurations.len() - 1);
|
||||
}
|
||||
}
|
||||
} else if let Err(e) = ts_json {
|
||||
eprintln!(
|
||||
"Warning: Failed to read {} -- {e}",
|
||||
parser_path.join("tree-sitter.json").display()
|
||||
);
|
||||
}
|
||||
|
||||
// If we didn't find any language configurations in the tree-sitter.json file,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue