nvim: Automatically install linters and formatters

Switch out mason-tool-installer for mason-conform.nvim and
mason-nvim-lint as respective wrappers for automatically installing
formatters and linters.

Follows the same principle as mason-lspconfig.nvim (in fact, the repos
are mostly based on the same code) and apply the concept to the other
tools: Whatever is enabled in the respective plugins (lspconfig,
nvim-lint and conform.nvim) will automatically be installed by mason.

This is really neat and basically takes care of me ever having to
interact much with Mason itself or manually set up the tools to be
installed. All I have to make sure is that they're updated once in a
while.
This commit is contained in:
Marty Oehme 2024-06-17 14:00:00 +02:00
parent b2dfdfd5ff
commit b4a9b5179f
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 84 additions and 82 deletions

View file

@ -42,8 +42,9 @@
"lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" },
"luarocks.nvim": { "branch": "main", "commit": "1db9093915eb16ba2473cfb8d343ace5ee04130a" }, "luarocks.nvim": { "branch": "main", "commit": "1db9093915eb16ba2473cfb8d343ace5ee04130a" },
"markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" }, "markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" },
"mason-conform.nvim": { "branch": "main", "commit": "abce2be529f3b4b336c56d0ba6336a9144e0fee6" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, "mason-nvim-lint": { "branch": "main", "commit": "637a5b8f1b454753ec70289c4996d88a50808642" },
"mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" }, "mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" },
"mdeval.nvim": { "branch": "master", "commit": "2c32e2f3e7d8f222e7a4724989f218d036e1081d" }, "mdeval.nvim": { "branch": "master", "commit": "2c32e2f3e7d8f222e7a4724989f218d036e1081d" },
"mini.nvim": { "branch": "main", "commit": "19e1584124cda35388d4fdb911eab7124014e541" }, "mini.nvim": { "branch": "main", "commit": "19e1584124cda35388d4fdb911eab7124014e541" },

View file

@ -43,17 +43,6 @@ local servers = {
yamlls = {}, yamlls = {},
} }
-- TODO installed for conform/nvim-lint so should be sourced from there not here
local to_mason =
---@diagnostic disable-next-line:deprecated
{ "stylua", "shellcheck", "shfmt", "markdownlint", "bibtex-tidy", "jq", "prettier", "ruff", unpack(servers) }
require("mason-tool-installer").setup({
-- a list of all tools you want to ensure are installed upon
-- start
ensure_installed = to_mason,
start_delay = 3000,
})
local function on_attach(_, bufnr) local function on_attach(_, bufnr)
local map = vim.keymap.set local map = vim.keymap.set
map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<cr>", { buffer = bufnr, desc = "Previous diagnostic" }) map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<cr>", { buffer = bufnr, desc = "Previous diagnostic" })

View file

@ -96,7 +96,6 @@ return {
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
cmd = { "LspInstall", "LspUninstall" }, cmd = { "LspInstall", "LspUninstall" },
}, },
{ "WhoIsSethDaniel/mason-tool-installer.nvim" },
}, },
event = { "BufReadPost", "BufNewFile", "BufWritePre" }, event = { "BufReadPost", "BufNewFile", "BufWritePre" },
config = function() config = function()
@ -104,7 +103,7 @@ return {
end, end,
keys = { { "<leader>vs", ":LspInfo<cr>", desc = "LspInfo" } }, keys = { { "<leader>vs", ":LspInfo<cr>", desc = "LspInfo" } },
}, },
-- very very pretty lsp 'peek' menus -- pretty lsp 'peek' menus
{ {
"DNLHC/glance.nvim", "DNLHC/glance.nvim",
opts = { border = { enable = true }, theme = { enable = true, mode = "auto" } }, opts = { border = { enable = true }, theme = { enable = true, mode = "auto" } },
@ -112,6 +111,9 @@ return {
}, },
-- linting setup -- linting setup
{
"rshkarin/mason-nvim-lint",
dependencies = {
{ {
"mfussenegger/nvim-lint", "mfussenegger/nvim-lint",
config = function() config = function()
@ -124,10 +126,17 @@ return {
end, end,
}) })
end, end,
dependencies = { "williamboman/mason.nvim" },
},
},
event = { "BufReadPost", "BufNewFile", "BufWritePre" }, event = { "BufReadPost", "BufNewFile", "BufWritePre" },
opts = {},
}, },
-- formatting setup -- formatting setup
{
"zapling/mason-conform.nvim",
dependencies = {
{ {
"stevearc/conform.nvim", "stevearc/conform.nvim",
config = function() config = function()
@ -166,7 +175,6 @@ return {
}) })
end, end,
cmd = { "ConformInfo" }, cmd = { "ConformInfo" },
event = { "BufReadPost", "BufNewFile", "BufWritePre" },
keys = { keys = {
{ {
"<localleader>ll", "<localleader>ll",
@ -193,6 +201,10 @@ return {
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end, end,
}, },
},
event = { "BufReadPost", "BufNewFile", "BufWritePre" },
opts = {},
},
-- useful quickfix-like buffer -- useful quickfix-like buffer
{ {