nvim: Add conditional vale diagnostics

When writing a markdown or similar document, vale will automatically
be enabled if there is a '.vale.ini' or '_vale.ini' file (and a
corresponding styles folder) in the project root directory.

Otherwise, vale stays disabled.
This commit is contained in:
Marty Oehme 2023-06-20 14:09:48 +02:00
parent a689d7cc3d
commit 1c8c5ca6d9
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -142,7 +142,7 @@ end
local null_ls = require("null-ls")
null_ls.setup({})
require("mason-null-ls").setup({
ensure_installed = { "black", "prettier", "shfmt", "eslint-lsp", "stylua", "jq" },
ensure_installed = { "black", "prettier", "shfmt", "eslint-lsp", "stylua", "jq", "vale" },
automatic_installation = false,
handlers = {
shfmt = function(_, _)
@ -164,5 +164,12 @@ require("mason-null-ls").setup({
extra_filetypes = { "astro" },
}))
end,
vale = function(_, _)
null_ls.register(null_ls.builtins.diagnostics.vale.with({
condition = function(utils)
return (utils.root_has_file({ ".vale.ini", "_vale.ini" }) and utils.root_has_file({ "styles/" }))
end,
}))
end,
},
})