From 6b98217df8b810c13babcf099211bb9052e49c17 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 6 Feb 2025 12:28:49 +0300 Subject: [PATCH] diagnostics/nvim-lint: rough initial implementation --- .../plugins/diagnostics/nvim-lint/config.nix | 28 +++++++++++++++++-- .../diagnostics/nvim-lint/nvim-lint.nix | 11 ++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/modules/plugins/diagnostics/nvim-lint/config.nix b/modules/plugins/diagnostics/nvim-lint/config.nix index dac2c2f4..e331b28c 100644 --- a/modules/plugins/diagnostics/nvim-lint/config.nix +++ b/modules/plugins/diagnostics/nvim-lint/config.nix @@ -12,9 +12,31 @@ in { config = mkIf cfg.enable { vim = { startPlugins = ["nvim-lint"]; - pluginRC.nvim-lint = entryAnywhere '' - require("lint").setup(${toLuaObject cfg.setupOpts}) - ''; + pluginRC.nvim-lint = let + mappedLinters = + lib.concatMapAttrsStringSep "\n" (name: value: '' + local linter_${name} = lint.linters.${name} + linter_${name}.args = ${toLuaObject value} + '') + cfg.configuredLinters; + in + entryAnywhere '' + local lint = require("lint") + ${mappedLinters} + lint.linters_by_ft = ${toLuaObject cfg.setupOpts.linters_by_ft}; + + -- TODO: one way of doing this dynamically is to use take required + -- parameters like fts, commands, arguments and everything expected + -- by nvim-lint to simply construct multiple autocommands. nvim-lint + -- doesn't seem to be able to handle that by itself. + vim.api.nvim_create_autocmd({ "BufWritePost" }, { + callback = function() + -- try_lint without arguments runs the linters defined in `linters_by_ft` + -- for the current filetype + require("lint").try_lint() + end, + }) + ''; }; }; } diff --git a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix index 2211211e..fb69ac02 100644 --- a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix +++ b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix @@ -1,14 +1,21 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) attrsOf listOf str; + inherit (lib.types) attrsOf listOf str anything; inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.diagnostics.nvim-lint = { enable = mkEnableOption "asynchronous linter plugin for Neovim [nvim-lint]"; + + configuredLinters = mkOption { + type = attrsOf anything; + default = {}; + description = ""; + }; + setupOpts = mkPluginSetupOption "nvim-lint" { linters_by_ft = mkOption { type = attrsOf (listOf str); - default = {}; + default = {markdown = ["value"];}; example = { text = ["vale"]; markdown = ["vale"];