-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
tree-sitter: make tree-sitter-grammars an overridable scope #537058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f88c486
tree-sitter: make tree-sitter-grammars an overridable scope
khaneliman f8a16a3
tree-sitter-grammars: consume scoped package set
khaneliman a8fad7e
helix: use top-level tree-sitter grammars
khaneliman 0a53614
tree-sitter: document grammar scope overrides
khaneliman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,26 +75,12 @@ let | |
| */ | ||
| builtGrammars = lib.mapAttrs (_: lib.makeOverridable buildGrammar) grammars; | ||
|
|
||
| /** | ||
| # Extensible package set for tree-sitter grammars. | ||
| # Provides .override and .extend for customization. | ||
| # Note: Use builtGrammars (not this) when iterating over grammars, | ||
| # as this includes package set functions alongside derivations | ||
| */ | ||
| grammarsScope = lib.makeScope newScope (self: builtGrammars); | ||
|
|
||
| # Usage: | ||
| # pkgs.tree-sitter.withPlugins (p: [ p.tree-sitter-c p.tree-sitter-java ... ]) | ||
| # | ||
| # or for all grammars: | ||
| # pkgs.tree-sitter.withPlugins (_: pkgs.tree-sitter.allGrammars) | ||
| # which is equivalent to | ||
| # pkgs.tree-sitter.withPlugins (p: builtins.attrValues p) | ||
| withPlugins = | ||
| grammarFn: | ||
| let | ||
| grammars = grammarFn builtGrammars; | ||
| in | ||
| grammarDerivationsFrom = lib.filterAttrs ( | ||
| name: value: lib.hasPrefix "tree-sitter-" name && lib.isDerivation value | ||
| ); | ||
|
|
||
| mkGrammarLinkFarm = | ||
| grammars: | ||
| linkFarm "grammars" ( | ||
| map ( | ||
| drv: | ||
|
|
@@ -112,7 +98,32 @@ let | |
| ) grammars | ||
| ); | ||
|
|
||
| allGrammars = lib.filter (p: !(p.meta.broken or false)) (lib.attrValues builtGrammars); | ||
| /** | ||
| Extensible package set of compiled tree-sitter grammars. | ||
|
|
||
| Exposed as `pkgs.tree-sitter-grammars` and `pkgs.tree-sitter.grammarsScope`. | ||
| Customize with `.overrideScope`; overrides propagate to every consumer that | ||
| reads the scope, including the grammar-only views below (which the | ||
| `pkgs.tree-sitter` passthru re-exports so there is a single source of truth): | ||
|
|
||
| `.derivations` attrset of every grammar derivation | ||
| `.allGrammars` list of non-broken grammar derivations | ||
| `.withPlugins` build a grammar link farm | ||
|
|
||
| The scope also carries package-set helpers (`callPackage`, `overrideScope`, | ||
| …) alongside the grammars, so prefer one of the views above when iterating. | ||
| */ | ||
| grammarsScope = lib.makeScope newScope ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably just be called |
||
| self: | ||
| builtGrammars | ||
| // { | ||
| derivations = grammarDerivationsFrom self; | ||
| allGrammars = lib.filter (p: !(p.meta.broken or false)) ( | ||
| lib.attrValues (grammarDerivationsFrom self) | ||
| ); | ||
| withPlugins = grammarFn: mkGrammarLinkFarm (grammarFn (grammarDerivationsFrom self)); | ||
| } | ||
| ); | ||
|
|
||
| isWasi = stdenv.hostPlatform.isWasi; | ||
|
|
||
|
|
@@ -237,14 +248,15 @@ rustPlatform.buildRustPackage (finalAttrs: { | |
|
|
||
| passthru = { | ||
| inherit | ||
| grammars | ||
| buildGrammar | ||
| builtGrammars | ||
| grammars | ||
| grammarsScope | ||
| withPlugins | ||
| allGrammars | ||
| ; | ||
|
|
||
| # Keep legacy `pkgs.tree-sitter` views wired to the overridable scope. | ||
| inherit (grammarsScope) allGrammars withPlugins; | ||
|
|
||
| updateScript = nix-update-script { }; | ||
|
|
||
| tests = { | ||
|
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.