dotfiles/.config/nvim/lua/config/plugins/lsp.lua

71 lines
2.2 KiB
Lua
Raw Normal View History

return {
"neovim/nvim-lspconfig",
dependencies = {
{ "saghen/blink.cmp" },
{ "b0o/schemastore.nvim" },
{
"folke/lazydev.nvim",
ft = "lua",
opts = {
library = {
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
},
},
opts = {
inlay_hints = { enabled = false },
servers = {
ansiblels = {},
dockerls = {},
lua_ls = {},
ruff = {},
jsonls = {
settings = {
json = {
validate = { enable = true },
},
},
},
yamlls = {
settings = {
yaml = {
schemaStore = {
enable = false,
url = "",
},
},
},
},
},
},
config = function(_, opts)
local lspconfig = require("lspconfig")
for server, config in pairs(opts.servers) do
config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities)
if server == "yamlls" then
config.settings.yaml.schemas = require('schemastore').yaml.schemas()
end
if server == "jsonls" then
config.settings.json.schemas = require('schemastore').json.schemas()
end
lspconfig[server].setup(config)
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
if client.supports_method('textDocument/formatting') then
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,
}