From 35f3be1306cf89a08714632a5b0e5dcdca95ce58 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 31 Jul 2023 13:34:51 +0300 Subject: [PATCH] feat(languages/nix): statix & deadnix diagnostics --- docs/release-notes/rl-0.5.adoc | 2 ++ modules/languages/nix.nix | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/docs/release-notes/rl-0.5.adoc b/docs/release-notes/rl-0.5.adoc index ff7a105..84d9843 100644 --- a/docs/release-notes/rl-0.5.adoc +++ b/docs/release-notes/rl-0.5.adoc @@ -35,3 +35,5 @@ https://github.com/notashelf[notashelf]: * Addeed nvim-navic integration for catppuccin theme * Fixed mismatching zig language description + +* Added support for `statix` and `deadnix` through <> diff --git a/modules/languages/nix.nix b/modules/languages/nix.nix index 4a1c892..26f9285 100644 --- a/modules/languages/nix.nix +++ b/modules/languages/nix.nix @@ -82,6 +82,32 @@ with builtins; let # 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 { options.vim.languages.nix = { enable = mkEnableOption "Nix language support"; @@ -124,6 +150,19 @@ in { 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 [ @@ -147,5 +186,14 @@ in { vim.lsp.null-ls.enable = true; 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; + }; + }) ]); }