2025-03-27 08:18:20 +00:00
|
|
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
|
|
|
local format_on_save = function(client, bufnr)
|
|
|
|
|
if client.supports_method("textDocument/formatting") then
|
|
|
|
|
vim.api.nvim_clear_autocmds({
|
|
|
|
|
group = augroup,
|
|
|
|
|
buffer = bufnr,
|
|
|
|
|
})
|
|
|
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
|
|
|
group = augroup,
|
|
|
|
|
buffer = bufnr,
|
|
|
|
|
callback = function()
|
2025-03-31 09:21:32 +01:00
|
|
|
-- prevents format from being included in the undo history
|
|
|
|
|
-- this way the cursor doesn't jump around the file when
|
|
|
|
|
-- undoing
|
|
|
|
|
vim.cmd("silent! undojoin")
|
|
|
|
|
|
2025-03-27 08:18:20 +00:00
|
|
|
vim.lsp.buf.format({
|
|
|
|
|
bufnr = bufnr,
|
|
|
|
|
async = false,
|
|
|
|
|
})
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
|
callback = function(args)
|
|
|
|
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
|
|
|
if not client then return end
|
|
|
|
|
|
2025-03-29 20:01:39 +00:00
|
|
|
local LSP_CLIENT_NAMES_FORMAT_ON_SAVE = { "lua_ls", "jdtls", "gopls", "taplo", "yamlls" }
|
2025-03-27 12:48:32 +00:00
|
|
|
for _, client_name_autoformat in ipairs(LSP_CLIENT_NAMES_FORMAT_ON_SAVE) do
|
2025-03-29 01:53:04 +00:00
|
|
|
if client.name == client_name_autoformat and client.server_capabilities.documentFormattingProvider then
|
2025-03-27 12:48:32 +00:00
|
|
|
-- Format the current buffer on save
|
|
|
|
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
|
|
|
|
buffer = args.buf,
|
|
|
|
|
callback = function()
|
|
|
|
|
vim.lsp.buf.format({ bufnr = args.buf, id = client.id })
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
end
|
2025-03-27 08:18:20 +00:00
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
vim.diagnostic.config({
|
2025-03-27 10:47:46 +00:00
|
|
|
virtual_lines = {
|
|
|
|
|
current_line = true
|
|
|
|
|
}
|
2025-03-27 08:18:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return {
|
2025-03-31 11:19:48 +01:00
|
|
|
{
|
|
|
|
|
"neovim/nvim-lspconfig",
|
|
|
|
|
config = function()
|
|
|
|
|
local lspconfig = require('lspconfig')
|
|
|
|
|
for _, v in ipairs(vim.api.nvim_get_runtime_file('lua/lsp/*', true)) do
|
|
|
|
|
local name = vim.fn.fnamemodify(v, ':t:r')
|
|
|
|
|
local cfg = require("lsp/" .. name)
|
|
|
|
|
lspconfig[name].setup(cfg)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
},
|
2025-03-27 08:18:20 +00:00
|
|
|
{
|
|
|
|
|
"williamboman/mason.nvim",
|
2025-03-27 10:47:46 +00:00
|
|
|
|
2025-03-27 08:18:20 +00:00
|
|
|
opts = {
|
|
|
|
|
tools_to_install = {
|
2025-03-27 10:47:46 +00:00
|
|
|
"lua-language-server", "vtsls", "ruff", "mypy", "black",
|
|
|
|
|
"pyright", "tailwindcss-language-server",
|
2025-03-27 12:48:32 +00:00
|
|
|
"eslint-lsp", "lemminx", "gopls", "prettierd", "dotenv-linter",
|
2025-04-01 18:05:47 +01:00
|
|
|
"editorconfig-checker", "rust-analyzer", "taplo",
|
|
|
|
|
"json-lsp", "harper-ls", "proselint", "alex"
|
2025-03-27 08:18:20 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
config = function(_, opts)
|
|
|
|
|
require("mason").setup()
|
|
|
|
|
local mason_registry = require("mason-registry")
|
|
|
|
|
mason_registry.refresh()
|
|
|
|
|
for _, tool in pairs(opts.tools_to_install) do
|
|
|
|
|
local package = mason_registry.get_package(tool)
|
|
|
|
|
if not package:is_installed() then
|
|
|
|
|
package:install()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"nvimtools/none-ls.nvim",
|
2025-03-27 10:47:46 +00:00
|
|
|
dependencies = { "nvimtools/none-ls-extras.nvim" },
|
|
|
|
|
|
|
|
|
|
config = function()
|
2025-03-27 08:18:20 +00:00
|
|
|
local null_ls = require("null-ls")
|
|
|
|
|
null_ls.setup({
|
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
|
format_on_save(client, bufnr)
|
|
|
|
|
end,
|
|
|
|
|
sources = {
|
2025-03-27 12:48:32 +00:00
|
|
|
null_ls.builtins.formatting.prettierd,
|
|
|
|
|
|
|
|
|
|
null_ls.builtins.diagnostics.dotenv_linter,
|
|
|
|
|
null_ls.builtins.diagnostics.editorconfig_checker,
|
2025-04-01 18:05:47 +01:00
|
|
|
null_ls.builtins.diagnostics.proselint,
|
|
|
|
|
null_ls.builtins.diagnostics.alex
|
2025-03-27 08:18:20 +00:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
}
|