#nix #language-server #lsp #rnix

app rnix-lsp

A work-in-progress language server for Nix, with syntax checking and basic completion

5 releases

0.2.5 Jun 14, 2022
0.2.4 Jan 30, 2022
0.2.3 Dec 24, 2021
0.2.1 Sep 23, 2021
0.1.0 Jan 12, 2020

#433 in Text editors

Download history 59/week @ 2023-12-13 61/week @ 2023-12-20 96/week @ 2023-12-27 73/week @ 2024-01-03 82/week @ 2024-01-10 72/week @ 2024-01-17 70/week @ 2024-01-24 59/week @ 2024-01-31 87/week @ 2024-02-07 89/week @ 2024-02-14 145/week @ 2024-02-21 170/week @ 2024-02-28 145/week @ 2024-03-06 148/week @ 2024-03-13 121/week @ 2024-03-20 93/week @ 2024-03-27

527 downloads per month

MIT license

54KB
1K SLoC

rnix-lsp Crates.io

A syntax-checking language server using rnix.

  • Syntax-checking diagnostics
  • Basic completion
  • Basic renaming
  • Basic goto definition
  • Expand selection proposal
  • Formatting using nixpkgs-fmt

This is beta-level quality at best - I didn't expect maintaining a language server when writing rnix, the goal was that others would flock around the parser and write a bunch of editor tooling :)

Breakages are expected. No semver compatibility before 1.x.y.

Turn on logging with RUST_LOG=trace, and redirect stderr to a file.

bash -c "env RUST_LOG=trace rnix-lsp 2> /tmp/rnix-lsp.log"

Install

$ nix-env -i -f https://github.com/nix-community/rnix-lsp/archive/master.tar.gz

Integrate with your editor

These instructions are not fully tested - see issue #3. Please raise an issue and/or send a PR if a config below didn't work out of the box.

Vim/Neovim

coc.nvim

{
  "languageserver": {
    "nix": {
      "command": "rnix-lsp",
      "filetypes": [
        "nix"
      ]
    }
  }
}

LanguageClient-neovim

let g:LanguageClient_serverCommands = {
    \ 'nix': ['rnix-lsp']
\ }

vim-lsp

if executable('rnix-lsp')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'rnix-lsp',
        \ 'cmd': {server_info->[&shell, &shellcmdflag, 'rnix-lsp']},
        \ 'whitelist': ['nix'],
        \ })
endif

Emacs

lsp-mode

(add-to-list 'lsp-language-id-configuration '(nix-mode . "nix"))
(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection '("rnix-lsp"))
                  :major-modes '(nix-mode)
                  :server-id 'nix))

eglot

(add-to-list 'eglot-server-programs '(nix-mode . ("rnix-lsp")))

Kakoune

kak-lsp

kak-lsp has builtin configuration since version v9.0.0:

[language.nix]
filetypes = ["nix"]
roots = ["flake.nix", "shell.nix", ".git"]
command = "rnix-lsp"

If you run into an issue regarding "missing roots" see this issue.

VSCode

vscode-nix-ide

{
    "nix.enableLanguageServer": true
}

RIP jd91mzm2

Sadly, the original author of this project, @jD91mZM2 has passed away. His online presence was anonymous and what we have left is his code. This is but one of his many repos that he contributed to.

Dependencies

~9–12MB
~230K SLoC