From 1c8c5ca6d98d0f90f6ced35e6f113a5631c8d5e7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 20 Jun 2023 14:09:48 +0200 Subject: [PATCH] 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. --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index 7932f05..90947db 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -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, }, })