tree-sitter: add schema to grammar definition, support multi-grammar repos#200028
Closed
Profpatsch wants to merge 14 commits intoNixOS:masterfrom
Closed
tree-sitter: add schema to grammar definition, support multi-grammar repos#200028Profpatsch wants to merge 14 commits intoNixOS:masterfrom
Profpatsch wants to merge 14 commits intoNixOS:masterfrom
Conversation
The allGrammars had to be patched at both use-sites, so let’s pull that into the original definition. Adds a few more docstrings.
`repo` and `orga` are not required to print the `default.nix`. This will be relevant because `gitlab` is going to be added, which does not have these two fields.
We want to be able to download tree-sitter grammars from other platforms. The first, easiest target is gitlab. Gitlab uses a `projectId` instead of orga/repo though, so we need to implement it differently (also checking the latest version of a repo works differently).
This uses the gitlab API to download the jsonc grammar. Currently the gitlab support only allows for gitlab.com, but that could be changed quite easily. I opted for copying a lot of the github code, since it’s too early to factor out shared code.
The `language` attr is only used for the grammar name, changing it makes no sense at all, and makes the output names irregular. I read something about nvim inferring the language from the filepath or something, I seriously hope that’s not A Thing, and if it is, we should find a different way of solving that. The tree-sitter integration is not specific to nvim, so it shouldn’t have nvim hacks.
Some of these repos define multiple grammars, so we need to be able to specify them, in order to remove the hack in the default.nix
The toml quickly got out of hand when I wanted to add more fields to
the list of known grammars, since then you need something like
```
[[knownTreeSitterOrgGrammarRepos.foo]]
repo = "foo"
[[knownTreeSitterOrgGrammarRepos.foo.grammars]]
name = "foo-grammar-bar"
location = "bar"
```
Just to express
```
{ knownTreeSitterOrgGrammarRepos = [
{ foo = {
repo = "foo"
grammars = [
{ name = "foo-grammar-bar"
location = "bar"
}
]
}
}
]}
```
Which translates to a *very* verbose config file.
Instead, let’s convert to json. Of course that means no comments are
possible, but there is a good solution that every modern editor
supports: json schema.
This also gives auto-completion and documentation for free.
Looks like this is just an elaborate linkFarm command.
So much nicer :w:
This argument was extremely underspecified and hacked into the rest of the code. I’d rather remove it for now and re-do support later if necessary. Ideally we’d expose the building blocks in a defined & documented fashion.
Member
|
I think now that grammar sources and updating has been reworked in #408414, this can be closed? |
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
based on #199566
WIP
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes