139 lines
4.9 KiB
Lua
139 lines
4.9 KiB
Lua
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()
|
|
-- 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")
|
|
|
|
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
|
|
|
|
local LSP_CLIENT_NAMES_FORMAT_ON_SAVE = { "lua_ls", "jdtls", "gopls", "taplo", "yamlls" }
|
|
for _, client_name_autoformat in ipairs(LSP_CLIENT_NAMES_FORMAT_ON_SAVE) do
|
|
if client.name == client_name_autoformat and client.server_capabilities.documentFormattingProvider then
|
|
-- 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
|
|
end
|
|
end,
|
|
})
|
|
|
|
vim.diagnostic.config({
|
|
virtual_lines = false,
|
|
virtual_text = false,
|
|
signs = {
|
|
text = {
|
|
[vim.diagnostic.severity.ERROR] = "",
|
|
[vim.diagnostic.severity.WARN] = "",
|
|
[vim.diagnostic.severity.HINT] = "",
|
|
[vim.diagnostic.severity.INFO] = "",
|
|
},
|
|
},
|
|
})
|
|
|
|
return {
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
config = function()
|
|
local lspconfig = require('lspconfig')
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities.textDocument.foldingRange = {
|
|
dynamicRegistration = false,
|
|
lineFoldingOnly = true
|
|
}
|
|
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)
|
|
if lspconfig[name].setup ~= nil then
|
|
lspconfig[name].setup(vim.tbl_deep_extend("force", cfg, { capabilities }))
|
|
else
|
|
vim.notify("LSP server " .. name .. " does not have a setup function", vim.log.levels.ERROR)
|
|
end
|
|
end
|
|
end
|
|
},
|
|
{
|
|
"williamboman/mason.nvim",
|
|
|
|
opts = {
|
|
tools_to_install = {
|
|
"lua-language-server", "vtsls", "ruff", "mypy", "black",
|
|
"pyright", "emmet-language-server", "tailwindcss-language-server",
|
|
"eslint-lsp", "lemminx", "gopls", "prettierd", "dotenv-linter",
|
|
"editorconfig-checker", "rust-analyzer", "taplo", "kulala-fmt",
|
|
"json-lsp", "harper-ls", "proselint", "alex", "yaml-language-server",
|
|
"golangci-lint-langserver", "golangci-lint"
|
|
}
|
|
},
|
|
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",
|
|
dependencies = { "nvimtools/none-ls-extras.nvim" },
|
|
|
|
config = function()
|
|
local null_ls = require("null-ls")
|
|
|
|
local kulala_fmt = {
|
|
method = null_ls.methods.FORMATTING,
|
|
filetypes = { "http" },
|
|
generator = null_ls.formatter({
|
|
command = "kulala-fmt",
|
|
args = { "format", "--stdin" },
|
|
to_stdin = true,
|
|
}),
|
|
}
|
|
|
|
null_ls.setup({
|
|
on_attach = function(client, bufnr)
|
|
format_on_save(client, bufnr)
|
|
end,
|
|
sources = {
|
|
null_ls.builtins.formatting.prettierd,
|
|
kulala_fmt,
|
|
|
|
null_ls.builtins.diagnostics.dotenv_linter,
|
|
null_ls.builtins.diagnostics.editorconfig_checker,
|
|
null_ls.builtins.diagnostics.proselint,
|
|
null_ls.builtins.diagnostics.alex
|
|
},
|
|
})
|
|
end
|
|
}
|
|
}
|