Skip to content

Commit 4d2f488

Browse files
authored
languages/python: add mypy (#1395)
1 parent 1355f90 commit 4d2f488

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

docs/manual/release-notes/rl-0.9.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@
173173
174174
- Added XML syntax highlighting, LSP support and formatting
175175
176+
- Added [mypy](https://www.mypy-lang.org/) to `languages.python` for extra
177+
diagnostics.
178+
176179
- Added [tera](https://keats.github.io/tera/) language support (syntax
177180
highlighting only).
178181

modules/plugins/languages/python.nix

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
inherit (lib.modules) mkIf mkMerge;
1212
inherit (lib.types) enum package bool;
1313
inherit (lib.nvim.attrsets) mapListToAttrs;
14-
inherit (lib.nvim.types) deprecatedSingleOrListOf;
14+
inherit (lib.nvim.types) deprecatedSingleOrListOf diagnostics;
1515
inherit (lib.generators) mkLuaInline;
1616
inherit (lib.nvim.dag) entryBefore;
1717
inherit (lib.trivial) warn;
@@ -278,6 +278,14 @@
278278
'';
279279
};
280280
};
281+
defaultDiagnosticsProvider = ["mypy"];
282+
diagnosticsProviders = {
283+
mypy = {
284+
config = {
285+
cmd = getExe' pkgs.mypy "mypy";
286+
};
287+
};
288+
};
281289
in {
282290
options.vim.languages.python = {
283291
enable = mkEnableOption "Python language support";
@@ -335,6 +343,15 @@ in {
335343
'';
336344
};
337345
};
346+
347+
extraDiagnostics = {
348+
enable = mkEnableOption "extra Python diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
349+
types = diagnostics {
350+
langDesc = "Python";
351+
inherit diagnosticsProviders;
352+
inherit defaultDiagnosticsProvider;
353+
};
354+
};
338355
};
339356

340357
config = mkIf cfg.enable (mkMerge [
@@ -404,5 +421,15 @@ in {
404421
vim.debugger.nvim-dap.enable = true;
405422
vim.debugger.nvim-dap.sources.python-debugger = debuggers.${cfg.dap.debugger}.dapConfig;
406423
})
424+
425+
(mkIf cfg.extraDiagnostics.enable {
426+
vim.diagnostics.nvim-lint = {
427+
enable = true;
428+
linters_by_ft.python = cfg.extraDiagnostics.types;
429+
linters =
430+
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;})
431+
cfg.extraDiagnostics.types);
432+
};
433+
})
407434
]);
408435
}

0 commit comments

Comments
 (0)