How it works: instead of building a new checker for Nix, it maps tree-sitter-nix’s AST directly to TypeScript AST nodes. The standard TS binder, type checker and LSP work almost unchanged – they never know they’re looking at Nix.
What works:
Hover, go-to-definition, autocomplete on builtins, lib, mkDerivation, much of main pkgs attrset
Runs on all 42K nixpkgs files in 13s
And the fun part: Fixed-point patterns (makeExtensible, finalAttrs): typed via transform to a TS class with late this binding
This is one of those things that made me fall for computers.
Using tree-sitter grammar, originally created for syntax highlighting in text editors, used to extract type-information from dynamically typed language, then mapped onto an AST of entirely different statically typed language is just brilliant idea in itself.
And it actually works through full 42k+ files in nixpkgs in reasonable time is friggin amazing! I'm gonna keep an eye on this going forward, this could get big within Nix :)
[OP] knl | 16 hours ago
What I find amazing:
peter-leonov | 5 hours ago
Same here. Even more. The upcoming Go-based TS checker is going to bring types to even more scripting languages for virtually free 🥳
peter-leonov | 5 hours ago
Ah, even better:
e3bc54b2 | 10 hours ago
This is one of those things that made me fall for computers.
Using tree-sitter grammar, originally created for syntax highlighting in text editors, used to extract type-information from dynamically typed language, then mapped onto an AST of entirely different statically typed language is just brilliant idea in itself.
And it actually works through full 42k+ files in nixpkgs in reasonable time is friggin amazing! I'm gonna keep an eye on this going forward, this could get big within Nix :)
alper | 6 hours ago
It's amazing that this works. That's all I can say.