diagnostics/nvim-lint: rough initial implementation

This commit is contained in:
raf 2025-02-06 12:28:49 +03:00
parent 7d8e2f7669
commit 6b98217df8
No known key found for this signature in database
GPG key ID: EED98D11B85A2819
2 changed files with 34 additions and 5 deletions

View file

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

View file

@ -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"];