languages/python: add mypy (#1395)

This commit is contained in:
Snoweuph 2026-02-18 11:22:51 +01:00 committed by GitHub
commit 4d2f488358
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -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).

View file

@ -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);
};
})
]);
}