nix-community / nixvim

Configure Neovim with Nix! [maintainers=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.82k stars 286 forks source link

[BUG] conform.nvim with `format_on_save = { }` does not generate corresponding setup arg #2601

Open dwf opened 1 day ago

dwf commented 1 day ago
Field Description
Plugin conform-nvim
Nixpkgs 24.11

Description

After upgrading to nixpkgs and nixvim 24.11, I noticed conform was no longer formatting on save. The Conform augroup was completely missing. Looking at the generated init.lua, the format_on_save argument was indeed missing despite being not null in my config.

I suspect this is a "truthiness" check gone wrong, but there's a lot of indirection in the derivation and I wasn't able to figure it out. The workaround I've used is format_on_save = { quiet = false; } which restates the default, but actually successfully generates.

Minimal, Reproducible Example (MRE)

config.plugins.conform-nvim = {
  enable = true;
  settings = {
    formatters_by_ft = {
      nix = [ "nixfmt" ];
    };
    format_on_save = {};  # Should generate this argument to setup() verbatim
  };
};
MattSturgeon commented 1 day ago

The issue here is that our lua generation function filters out not just null, but also empty attrs.

This is a horrible behaviour, I know, but it is intended as otherwise many many un-defined options (or their parent attrs) end up in the generated lua.

As a workaround we provide the "empty attr" object, which looks like { __empty = null; } and can also be used via lib.nixvim.emptyTable.

In some cases you can also use "raw lua" to achieve the same thing: .__raw = "{ }";