nix-eval-lsp
Still use nix-community/rnix-lsp. This repo is a work in progress.
nix-eval-lsp
is an experimental language server for Nix. It provides completions and tooltips by efficiently evaluating Nix expressions as they are typed.
Features
- hover over an expression to see its value
- auto-complete inside expressions such as
with pkgs; [
] - goto definitions across files
- clickable paths and urls
- auto-formatting using
nixpkgs-fmt
- helpful documentation for builtins
- caching of lambda parameters to make
callPackage
derivations easier to write - auto-complete for lambda arguments, with documentation comments extracted from source code
- snippets for common Nix expressions
Important note: the evaluator is developed for the purpose of debugging tools only. It does not aim to correctly implement Nix in its entirety.
Usage
- Install the Nix IDE extension for VS Code
git clone https://github.com/aaronjanse/nix-eval-lsp.git && cd nix-eval-lsp
- Run
nix build
,nix-build
, orRUSTC_BOOTSTRAP=1 cargo build --release
(the--release
is important!) - Copy the absolute path of the built binary into Nix IDE's settings (search "nix" then edit the "server path" field)
- Make sure "Nix: Enable Language Server" is set to
true
- Restart VS Code ("Reload Window" in command palette)
Try it out
Here's an expression to try out the LSP:
let
pkgs = import /path/to/nixpkgs {};
foo = pkgs.gcc;
in
with pkgs; [
htop hello
]
Credits
Huge thank you to @jd91mZM2 for nix-community/rnix-parser.