Nil: Yet another language server for Nix

Recently I wrote a language server for Nix, aiming at better coding assistance.

Main features currently implemented:

  • Complete and error-tolerant syntax parser.
    • Please file issues if it failed to parse any valid syntax, or has bad error-recovery during typing.
  • Goto definition and find references for local names and with exprs. Relative paths and attributes defined in multiple locations are also well supported.
  • Completion of keywords, local names and builtins.
  • Diagnostics, including warnings for dead names, dead code, deprecated syntax, duplicated attributes and more.
  • Renaming of all kinds of names.
  • Expand selection.
  • Semantic highlighting (experimental).

Feature requests are welcome!

The code is written in Rust with salsa, a multi-threaded incremental computation library. Thus intermediate computation will be cached and reused. Many designs follow rust-analyzer. (Multi-threading is not enabled currently since it’s already fast enough :slight_smile: )

The LSP server is already included in nixpkgs under attrpath nil, thanks to @figsoda

28 Likes

Works so nicely, thanks so much!

Vim

For any plain old Vim-ers, if you use vim-lsp, you can register nil as follows:

if executable('nil')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'nil',
        \ 'cmd': {server_info->['nil']},
        \ 'whitelist': ['nix'],
        \ })
endif
Hosted by Flying Circus.