nvim: Add automatic mason tool installation

Using mason-tool-installer we ensure everything is installed correctly.
Need to improve the collection of things to install. Currently we just
do everything in lsp configuration file, even the non-lsp things
(formatters/linters) which should be sourced where they belong not
in that file.
This commit is contained in:
Marty Oehme 2023-12-08 18:35:10 +01:00
parent ab06ef922b
commit eec90ad7e2
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 34 additions and 12 deletions

View file

@ -40,6 +40,7 @@
"markdown-preview.nvim": { "branch": "master", "commit": "9becceee5740b7db6914da87358a183ad11b2049" },
"markmap.nvim": { "branch": "main", "commit": "3befc2a54c2448a16c30c1c7762aab263f22946a" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "4eb8e15e3c0757303d4c6dea64d2981fc679e990" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "8b70e7f1e0a4119c1234c3bde4a01c241cabcc74" },
"mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" },
"mdeval.nvim": { "branch": "master", "commit": "2654caf8ecaad702b50199d18e39cff23d81e0ba" },
"mini.nvim": { "branch": "main", "commit": "b5645ac6eefce8e7af9d7dd4e5e296a81cba8a10" },

View file

@ -17,6 +17,7 @@ local servers = {
docker_compose_language_service = {},
dockerls = {},
emmet_ls = {},
eslint = {},
gopls = {},
julials = {},
lua_ls = {
@ -42,6 +43,16 @@ local servers = {
yamlls = {},
}
-- TODO installed for conform/nvim-lint so should be sourced from there not here
local to_mason =
{ "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(client, bufnr)
local map = vim.keymap.set
map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<cr>", { buffer = bufnr, desc = "Previous diagnostic" })
@ -118,8 +129,16 @@ end
-- Display diagnostics as virtual text only if not in insert mode
-- https://lr.artemislena.eu/r/neovim/comments/12inp4c/disable_diagnostics_virtual_text_when_in_insert/jqqifwk/
vim.api.nvim_create_autocmd("InsertEnter", { callback = function() vim.diagnostic.config({ virtual_text = false, }) end })
vim.api.nvim_create_autocmd("InsertLeave", { callback = function() vim.diagnostic.config({ virtual_text = true, }) end })
vim.api.nvim_create_autocmd("InsertEnter", {
callback = function()
vim.diagnostic.config({ virtual_text = false })
end,
})
vim.api.nvim_create_autocmd("InsertLeave", {
callback = function()
vim.diagnostic.config({ virtual_text = true })
end,
})
lsp.setup({
default_mappings = false,
@ -136,14 +155,14 @@ lspconfig.nushell.setup({})
local python_path
-- ensure python virtualenv is determined automatically on lsp start
lspconfig.pyright.setup({
on_attach = function(client, bufnr)
if python_path == nil then
python_path, _ = require("util").get_python_venv(client.config.root_dir)
end
-- print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path)))
client.config.settings.python.pythonPath = python_path
on_attach(client, bufnr)
end,
on_attach = function(client, bufnr)
if python_path == nil then
python_path, _ = require("util").get_python_venv(client.config.root_dir)
end
-- print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path)))
client.config.settings.python.pythonPath = python_path
on_attach(client, bufnr)
end,
})
lspconfig.ruff_lsp.setup({
on_attach = function(client, bufnr)
@ -161,4 +180,3 @@ if require("util").is_available("arduino") then
on_new_config = require("arduino").on_new_config,
})
end

View file

@ -55,6 +55,9 @@ return {
"williamboman/mason-lspconfig.nvim",
cmd = { "LspInstall", "LspUninstall" },
},
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
},
},
event = "BufReadPost",
config = function()
@ -91,7 +94,7 @@ return {
end
end
end
per_cmd("markdownlint", { linters.markdown })
per_cmd("markdownlint", { linters.markdown, linters.quarto })
per_cmd("vale", { linters.markdown, linters.text, linters.quarto })
per_cmd("shellcheck", { linters.sh, linters.bash })
per_cmd("eslint_d", {