diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index f42e4228..d5931113 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -173,6 +173,9 @@ - Added XML syntax highlighting, LSP support and formatting +- Added [mypy](https://www.mypy-lang.org/) to `languages.python` for extra + diagnostics. + - Added [tera](https://keats.github.io/tera/) language support (syntax highlighting only). diff --git a/modules/plugins/languages/python.nix b/modules/plugins/languages/python.nix index 04d2554f..4c777e3e 100644 --- a/modules/plugins/languages/python.nix +++ b/modules/plugins/languages/python.nix @@ -11,7 +11,7 @@ inherit (lib.modules) mkIf mkMerge; inherit (lib.types) enum package bool; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.types) deprecatedSingleOrListOf; + inherit (lib.nvim.types) deprecatedSingleOrListOf diagnostics; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryBefore; inherit (lib.trivial) warn; @@ -278,6 +278,14 @@ ''; }; }; + defaultDiagnosticsProvider = ["mypy"]; + diagnosticsProviders = { + mypy = { + config = { + cmd = getExe' pkgs.mypy "mypy"; + }; + }; + }; in { options.vim.languages.python = { enable = mkEnableOption "Python language support"; @@ -335,6 +343,15 @@ in { ''; }; }; + + extraDiagnostics = { + enable = mkEnableOption "extra Python diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; + types = diagnostics { + langDesc = "Python"; + inherit diagnosticsProviders; + inherit defaultDiagnosticsProvider; + }; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -404,5 +421,15 @@ in { vim.debugger.nvim-dap.enable = true; vim.debugger.nvim-dap.sources.python-debugger = debuggers.${cfg.dap.debugger}.dapConfig; }) + + (mkIf cfg.extraDiagnostics.enable { + vim.diagnostics.nvim-lint = { + enable = true; + linters_by_ft.python = cfg.extraDiagnostics.types; + linters = + mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;}) + cfg.extraDiagnostics.types); + }; + }) ]); }