feat: generate schema in tree-sitter.json

This commit is contained in:
Riley Bruins 2024-11-15 18:44:37 -08:00 committed by Amaan Qureshi
parent 05b2f443ba
commit 78e5144f3f
2 changed files with 7 additions and 0 deletions

View file

@ -140,6 +140,8 @@ pub struct LanguageConfigurationJSON {
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct TreeSitterJSON {
#[serde(rename = "$schema")]
pub schema: Option<String>,
pub grammars: Vec<Grammar>,
pub metadata: Metadata,
#[serde(default)]

View file

@ -93,6 +93,9 @@ const TEST_BINDING_PY_TEMPLATE: &str = include_str!("./templates/test_binding.py
const PACKAGE_SWIFT_TEMPLATE: &str = include_str!("./templates/package.swift");
const TESTS_SWIFT_TEMPLATE: &str = include_str!("./templates/tests.swift");
const TREE_SITTER_JSON_SCHEMA: &str =
"https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json";
#[must_use]
pub fn path_in_ignore(repo_path: &Path) -> bool {
[
@ -133,6 +136,7 @@ impl JsonConfigOpts {
#[must_use]
pub fn to_tree_sitter_json(self) -> TreeSitterJSON {
TreeSitterJSON {
schema: Some(TREE_SITTER_JSON_SCHEMA.to_string()),
grammars: vec![Grammar {
name: self.name.clone(),
camelcase: Some(self.camelcase),
@ -226,6 +230,7 @@ pub fn migrate_package_json(repo_path: &Path) -> Result<bool> {
let name = old_config.name.replace("tree-sitter-", "");
let new_config = TreeSitterJSON {
schema: Some(TREE_SITTER_JSON_SCHEMA.to_string()),
grammars: old_config
.tree_sitter
.unwrap()