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.
198 lines
6.4 KiB
Lua
198 lines
6.4 KiB
Lua
vim.diagnostic.config({ virtual_text = true })
|
|
vim.fn.sign_define("DiagnosticSignError", { text = "✘", texthl = "DiagnosticSignError" })
|
|
vim.fn.sign_define("DiagnosticSignWarn", { text = "", texthl = "DiagnosticSignWarn" })
|
|
vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" })
|
|
vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
|
|
|
|
local lsp = require("lsp-setup")
|
|
|
|
local servers = {
|
|
ansiblels = {},
|
|
arduino_language_server = {},
|
|
astro = {},
|
|
bashls = {},
|
|
beancount = {},
|
|
clangd = {},
|
|
cssls = {},
|
|
docker_compose_language_service = {},
|
|
dockerls = {},
|
|
emmet_ls = {},
|
|
eslint = {},
|
|
gopls = {},
|
|
julials = {},
|
|
lua_ls = {
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = { globals = { "vim" } },
|
|
-- enable when working on neovim stuff. Takes *long* to load
|
|
-- workspace = { library = vim.api.nvim_get_runtime_file("", true) },
|
|
telemetry = { enable = false },
|
|
},
|
|
},
|
|
},
|
|
marksman = {
|
|
filetypes = { "markdown", "quarto" },
|
|
},
|
|
basedpyright = {},
|
|
ruff = {},
|
|
serve_d = {},
|
|
tailwindcss = {},
|
|
taplo = {},
|
|
texlab = {},
|
|
tsserver = {},
|
|
yamlls = {},
|
|
}
|
|
|
|
local function on_attach(_, bufnr)
|
|
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_next()<cr>", { buffer = bufnr, desc = "Next diagnostic" })
|
|
map(
|
|
"n",
|
|
"[D",
|
|
"<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<cr>",
|
|
{ buffer = bufnr, desc = "Previous error" }
|
|
)
|
|
map(
|
|
"n",
|
|
"]D",
|
|
"<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<cr>",
|
|
{ buffer = bufnr, desc = "Next error" }
|
|
)
|
|
|
|
if require("core.util").is_available("which-key") then
|
|
require("which-key").register({ ["<localleader>l"] = { name = "+language" } })
|
|
end
|
|
map(
|
|
"n",
|
|
"<localleader>ld",
|
|
"<cmd>lua vim.diagnostic.open_float()<cr>",
|
|
{ buffer = bufnr, desc = "Line diagnostics" }
|
|
)
|
|
map("n", "<localleader>li", function()
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
|
|
end, { buffer = bufnr, desc = "Inlay hints" })
|
|
map("n", "<localleader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", { buffer = bufnr, desc = "Codeactions" })
|
|
map("n", "<localleader>ln", "<cmd>lua vim.lsp.buf.rename()<cr>", { buffer = bufnr, desc = "Rename element" })
|
|
if vim.fn.exists(":Glance") then
|
|
map("n", "<localleader>lr", "<cmd>Glance references<cr>", { buffer = bufnr, desc = "References" })
|
|
map("n", "<localleader>lf", "<cmd>Glance definitions<cr>", { buffer = bufnr, desc = "Definition" })
|
|
map("n", "<localleader>lt", "<cmd>Glance type_definitions<cr>", { buffer = bufnr, desc = "Type definition" })
|
|
map("n", "<localleader>lm", "<cmd>Glance implementations<cr>", { buffer = bufnr, desc = "Implementation" })
|
|
elseif vim.fn.exists(":Telescope") then
|
|
map("n", "<localleader>lr", "<cmd>Telescope lsp_references<cr>", { buffer = bufnr, desc = "References" })
|
|
map("n", "<localleader>lf", "<cmd>Telescope lsp_definitions<cr>", { buffer = bufnr, desc = "Definition" })
|
|
map(
|
|
"n",
|
|
"<localleader>lt",
|
|
"<cmd>Telescope lsp_type_definitions<cr>",
|
|
{ buffer = bufnr, desc = "Type definition" }
|
|
)
|
|
map(
|
|
"n",
|
|
"<localleader>lm",
|
|
"<cmd>Telescope lsp_implementations<cr>",
|
|
{ buffer = bufnr, desc = "Implementation" }
|
|
)
|
|
else
|
|
map("n", "<localleader>lr", "<cmd>lua vim.lsp.buf.references()<cr>", { buffer = bufnr, desc = "References" })
|
|
map("n", "<localleader>lf", "<cmd>lua vim.lsp.buf.definition()<cr>", { buffer = bufnr, desc = "Definition" })
|
|
map(
|
|
"n",
|
|
"<localleader>lt",
|
|
"<cmd>lua vim.lsp.buf.type_definition()<cr>",
|
|
{ buffer = bufnr, desc = "Type definition" }
|
|
)
|
|
map(
|
|
"n",
|
|
"<localleader>lm",
|
|
"<cmd>lua vim.lsp.buf.implementation()<cr>",
|
|
{ buffer = bufnr, desc = "Implementation" }
|
|
)
|
|
end
|
|
map("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", { buffer = bufnr, desc = "Hover definition" })
|
|
map("n", "<localleader>lc", "<cmd>lua vim.lsp.buf.declaration()<cr>", { buffer = bufnr, desc = "Declaration" })
|
|
map(
|
|
"n",
|
|
"<localleader>ls",
|
|
"<cmd>lua vim.lsp.buf.signature_help()<cr>",
|
|
{ buffer = bufnr, desc = "Signature help" }
|
|
)
|
|
map("n", "<localleader>lo", function()
|
|
if vim.diagnostic.is_disabled(0) then
|
|
vim.diagnostic.enable(0)
|
|
else
|
|
vim.diagnostic.disable(0)
|
|
end
|
|
end, { buffer = bufnr, desc = "Disable buffer diagnostics" })
|
|
end
|
|
|
|
-- Display diagnostics as virtual text only if not in insert mode
|
|
-- /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,
|
|
})
|
|
|
|
lsp.setup({
|
|
default_mappings = false,
|
|
servers = servers,
|
|
on_attach = on_attach,
|
|
inlay_hints = {
|
|
enabled = vim.fn.has("nvim-0.10") == true and true or false,
|
|
},
|
|
})
|
|
|
|
local lspconfig = require("lspconfig")
|
|
lspconfig.nushell.setup({})
|
|
|
|
local python_path
|
|
-- ensure python virtualenv is determined automatically on lsp start
|
|
lspconfig.basedpyright.setup({
|
|
on_attach = function(client, bufnr)
|
|
on_attach(client, bufnr)
|
|
if python_path == nil then
|
|
python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir))
|
|
end
|
|
vim.g["python3_host_prog"] = python_path
|
|
-- print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path)))
|
|
client.config.settings.python = {} or client.config.settings.python
|
|
client.config.settings.python.pythonPath = python_path
|
|
end,
|
|
settings = {
|
|
-- disable imports and linting since, we use ruff for that
|
|
pyright = {
|
|
disableOrganizeImports = true,
|
|
},
|
|
python = {
|
|
analysis = {
|
|
ignore = { "*" },
|
|
},
|
|
},
|
|
},
|
|
})
|
|
lspconfig.ruff.setup({
|
|
on_attach = function(client, bufnr)
|
|
on_attach(client, bufnr)
|
|
client.server_capabilities.hoverProvider = false -- we use pyright for hover info
|
|
if python_path == nil then
|
|
python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir))
|
|
end
|
|
vim.g["python3_host_prog"] = python_path
|
|
client.config.settings.python = {} or client.config.settings.python
|
|
client.config.settings.python.pythonPath = python_path
|
|
end,
|
|
})
|
|
|
|
-- set up arduino with the help of arduino.nvim plugin
|
|
if require("core.util").is_available("arduino") then
|
|
lspconfig.arduino_language_server.setup({
|
|
on_new_config = require("arduino").on_new_config,
|
|
})
|
|
end
|