feat(languages/nix): statix & deadnix diagnostics

This commit is contained in:
raf 2023-07-31 13:34:51 +03:00
parent 32a13428ec
commit 35f3be1306
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
2 changed files with 50 additions and 0 deletions

View file

@ -35,3 +35,5 @@ https://github.com/notashelf[notashelf]:
* Addeed nvim-navic integration for catppuccin theme * Addeed nvim-navic integration for catppuccin theme
* Fixed mismatching zig language description * Fixed mismatching zig language description
* Added support for `statix` and `deadnix` through <<opt-vim.languages.nix.extraDiagnostics.types>>

View file

@ -82,6 +82,32 @@ with builtins; let
# Never need to use null-ls for nixpkgs-fmt # Never need to use null-ls for nixpkgs-fmt
}; };
}; };
defaultDiagnostics = ["statix" "deadnix"];
diagnostics = {
statix = {
package = pkgs.statix;
nullConfig = pkg: ''
table.insert(
ls_sources,
null_ls.builtins.diagnostics.statix.with({
command = "${pkg}/bin/statix",
})
)
'';
};
deadnix = {
package = pkgs.deadnix;
nullConfig = pkg: ''
table.insert(
ls_sources,
null_ls.builtins.diagnostics.deadnix.with({
command = "${pkg}/bin/deadnix",
})
)
'';
};
};
in { in {
options.vim.languages.nix = { options.vim.languages.nix = {
enable = mkEnableOption "Nix language support"; enable = mkEnableOption "Nix language support";
@ -124,6 +150,19 @@ in {
default = formats.${cfg.format.type}.package; default = formats.${cfg.format.type}.package;
}; };
}; };
extraDiagnostics = {
enable = mkOption {
description = "Enable extra Nix diagnostics";
type = types.bool;
default = config.vim.languages.enableExtraDiagnostics;
};
types = lib.nvim.types.diagnostics {
langDesc = "Nix";
inherit diagnostics;
inherit defaultDiagnostics;
};
};
}; };
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
@ -147,5 +186,14 @@ in {
vim.lsp.null-ls.enable = true; vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.nix-format = formats.${cfg.format.type}.nullConfig; vim.lsp.null-ls.sources.nix-format = formats.${cfg.format.type}.nullConfig;
}) })
(mkIf cfg.extraDiagnostics.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources = lib.nvim.languages.diagnosticsToLua {
lang = "nix";
config = cfg.extraDiagnostics.types;
inherit diagnostics;
};
})
]); ]);
} }