-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syntax/nix: autogenerate namespaced builtins from
nix __dump-language
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] #44, #42, #36, #32, 711aaf7 [2] https://github.com/NixOS/nix/blob/2.20.1/src/nix/main.cc#L372
- Loading branch information
Showing
2 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env nix-shell | ||
#!nix-shell -i bash -p bash jq nix | ||
|
||
header="syn keyword nixNamespacedBuiltin contained" | ||
|
||
nix __dump-language | jq -r ' | ||
def to_vim: keys | map(" \\ " + . + "\n") | .[]; | ||
[ (.builtins | to_vim) | ||
, (.constants | del(.["true","false","null","builtins"]) | to_vim) | ||
] | add | ||
' | sed -n -i -e '/^'"$header"'/ { | ||
p; n; r /dev/stdin | ||
:l; n; /^$/!bl; b | ||
}; p' syntax/nix.vim |
This file contains 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