oxalica / nil

NIx Language server, an incremental analysis assistant for writing in Nix.
Apache License 2.0
1.28k stars 39 forks source link

Formatting (with alejandra) not working anymore #123

Open sbatial opened 6 months ago

sbatial commented 6 months ago

I could not figure out why but since recently formatting does not seem to work anymore. When I try to manually invoke !alejandra % it works (and I have set alejandra as the formatting command as well), but using my shortcut (or invoking vim.lsp.buf.format()) does not format anything but also does not give any errors. Neither as an instant message nor in LspLog.

The server is running, I get code-completion.

I also tried formatting in lua files which does work.

My neovim version is: v0.10.0-dev-4e59422 My nil version is the latest on nixpkgs-unstable: 2023-08-09 (I saw that there were a few commits since then so I'll try to test it with a newer version as soon as I find the time for that. It's not really a problem for now though)

oxalica commented 3 months ago

I cannot reproduce the issue on current master and alejandra works fine with LSP formatting command.

!alejandra %

alejandra will modify the file directly by themselves, while our configuration expects a command that processes source from stdin and print into stdout. So you are expected to use command alejandra -- in the configuration, like this:

{
  "nil": { "formatting": { "command": ["alejandra", "--"] } }
}

Please recheck that you does this as well.