Skip to content
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

syntax/nix: autogenerate namespaced builtins from nix __dump-language #59

Merged
merged 1 commit into from
Feb 24, 2024

Conversation

Ma27
Copy link
Collaborator

@Ma27 Ma27 commented Feb 19, 2024

We had quite a bunch of changes in the past that added builtins to get them highlighted properly[1].

Nowadays it's possible to get this from Nix itself by running nix __dump-language. This was done on a recent Nix and includes all experimental features by default[2] which seems fine to me since this is not an LSP, but only an approximation.

This patch adds a few new builtins, e.g. break and flakeRefToString and a script to regenerate the list.

This doesn't include non-scoped builtins (e.g. map, baseNameOf etc.), but those are added far less frequent, so this seems OK to me.

Also, there are a few hidden builtins, most notably unsafe* and scopedImport. I think this was done on purpose by upstream and I'm wondering if we should adhere to that approach. If we still want to keep those, I think we should add those to a custom highlighting group that's maintained manually.

[1] #44, #42, #36, #32, 711aaf7
[2] https://github.com/NixOS/nix/blob/2.20.1/src/nix/main.cc#L372

cc @LnL7 @aszlig for opinions

Copy link
Contributor

@aszlig aszlig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hell yes, nothing worse than manually managing boring lists :-)

builtins.sh Outdated Show resolved Hide resolved
syntax/nix.vim Show resolved Hide resolved
We had quite a bunch of changes in the past that added builtins to get them
highlighted properly[1].

Nowadays it's possible to get this from Nix itself by running
`nix __dump-language`. This was done on a recent Nix and includes all
experimental features by default[2] which seems fine to me since this is
not an LSP, but only an approximation.

This patch adds a few new builtins, e.g. `break` and `flakeRefToString`
and a script to regenerate the list.

This doesn't include non-scoped builtins (e.g. `map`, `baseNameOf`
etc.), but those are added far less frequent, so this seems OK to me.

Also, there are a few hidden builtins, most notably `unsafe*` and
`scopedImport`. I think this was done on purpose by upstream and I'm
wondering if we should adhere to that approach. If we still want to keep
those, I think we should add those to a custom highlighting group that's
maintained manually.

Co-authored-by: aszlig <[email protected]>

[1] LnL7#44, LnL7#42, LnL7#36, LnL7#32, 711aaf7
[2] https://github.com/NixOS/nix/blob/2.20.1/src/nix/main.cc#L372
Copy link
Owner

@LnL7 LnL7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm usually not a big fan of generating stuff, but for this type of thing it makes sense.
I think for proper context LSP/treesitter are the way to go, but this provides the basics for a vanilla setup.

@Ma27 Ma27 merged commit e25cd0f into LnL7:master Feb 24, 2024
1 check passed
@Ma27 Ma27 deleted the builtins-generated branch February 24, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants