Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Not yet using tree-sitter.json #64

Open
sogaiu opened this issue Oct 1, 2024 · 2 comments
Open

Not yet using tree-sitter.json #64

sogaiu opened this issue Oct 1, 2024 · 2 comments

Comments

@sogaiu
Copy link
Owner

sogaiu commented Oct 1, 2024

I think at some point we should start using tree-sitter.json. The file is described here.

Also, there is some more info about eventual removal of the tree-sitter section from package.json here.

I'd like to get rid of package.json, but I think Cursorless may still depend on it, so that may not happen so soon.


(On a side note, the build-wasm command may be going away in 0.24; with recent releases you can already use build --wasm the replacement. My attempts at getting the older subcommand to stay around longer did not meet with success. Backward compatibility of the cli API does not rank that highly priority-wise AFAIU.)

@sogaiu
Copy link
Owner Author

sogaiu commented Oct 9, 2024

At some point it looks like the tree-sitter cli's generate subcommand may result in the mutating of package.json and the creating of a tree-sitter.json file. AFAIU, this may happen if there isn't already a tree-sitter.json file.

Gave it a try here [1] and observed that some of the values that got into tree-sitter.json were wrong for our case (e.g. license, repository URL, and binding-generation):

{
  "grammars": [
    {
      "name": "clojure",
      "camelcase": "Clojure",
      "scope": "source.clojure",
      "path": ".",
      "file-types": [
        "bb",
        "clj",
        "cljc",
        "cljs"
      ]
    }
  ],
  "metadata": {
    "version": "0.0.13",
    "license": "MIT",
    "description": "Clojure grammar for tree-sitter",
    "links": {
      "repository": "https://github.com/tree-sitter/tree-sitter-clojure"
    }
  },
  "bindings": {
    "c": true,
    "go": true,
    "node": true,
    "python": true,
    "rust": true,
    "swift": true
  }
}

It may be that pre-emptively creating a tree-sitter.json will leave our package.json file alone.

Below is a draft of a possible tree-sitter.json:

{
  "grammars": [
    {
      "name": "clojure",
      "camelcase": "Clojure",
      "scope": "source.clojure",
      "path": ".",
      "file-types": [
        "bb",
        "clj",
        "cljc",
        "cljs"
      ]
    }
  ],
  "metadata": {
    "version": "0.0.13",
    "description": "Clojure grammar for tree-sitter"
  }
}

Unfortunately, it looks like version info is now duplicated across two files. We may be stuck with this unless / until Cursorless stops needing package.json.


On a side note, having both package.json and tree-sitter.json might be nicer because some users may be using older versions of the tree-sitter cli while others newer. It may be that having both files in the repository will serve a wider range of users (i.e. a broader range of versions of the cli can be used easily).


[1] Tested with:

tree-sitter 0.24.2 (0b167b0782a74e3702fb77cbef1486c6c01c24c8)

though it's possible an earlier version exhibits similar behavior.

@sogaiu
Copy link
Owner Author

sogaiu commented Jan 25, 2025

The situation of grammars missing tree-sitter.json files was mentioned in a comment as part of a recent PR:

Ok, there's 3 out of 356 grammars with no tree-sitter.json file used in nvim-treesitter that must be generated from the grammar. The config file is sort of mandatory for this feature, as we use the version defined in this file. That means <1% of grammars are impacted, and I've gone ahead and put up PRs to migrate them 2 days ago now - if they don't bother to update, then that's on them, and they cannot use ABI 15 then (but nothing is broken with ABI 14).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant