LazyVim.LazyVim/lua/lazyvim/plugins/lsp/init.lua

113 lines
3.1 KiB
Lua
Raw Normal View History

2022-12-30 17:30:52 +01:00
return {
-- lspconfig
{
"neovim/nvim-lspconfig",
event = "BufReadPre",
dependencies = {
{ "folke/neoconf.nvim", cmd = "Neoconf", config = true },
{ "folke/neodev.nvim", config = true },
"mason.nvim",
"williamboman/mason-lspconfig.nvim",
2022-12-30 17:30:52 +01:00
"hrsh7th/cmp-nvim-lsp",
},
---@type lspconfig.options
servers = {
jsonls = {},
sumneko_lua = {
settings = {
Lua = {
workspace = {
checkThirdParty = false,
},
completion = {
callSnippet = "Replace",
},
},
},
},
},
-- you can do any additional lsp server setup here
-- return true if you don't want this server to be setup with lspconfig
---@param server string lsp server name
---@param opts _.lspconfig.options any options set for the server
setup_server = function(server, opts)
return false
end,
config = function(plugin)
-- setup formatting and keymaps
require("lazyvim.util").on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
end)
2022-12-31 17:02:55 +01:00
-- diagnostics
for name, icon in pairs(require("lazyvim.config.settings").icons.diagnostics) do
2022-12-31 17:02:55 +01:00
name = "DiagnosticSign" .. name
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
end
vim.diagnostic.config({
underline = true,
update_in_insert = false,
virtual_text = { spacing = 4, prefix = "" },
severity_sort = true,
})
---@type lspconfig.options
local servers = plugin.servers or {}
2022-12-30 23:35:27 +01:00
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
require("mason-lspconfig").setup({ ensure_installed = vim.tbl_keys(servers) })
require("mason-lspconfig").setup_handlers({
function(server)
local opts = servers[server] or {}
opts.capabilities = capabilities
if not plugin.setup_server(opts) then
require("lspconfig")[server].setup(opts)
end
end,
})
2022-12-30 17:30:52 +01:00
end,
},
-- formatters
{
"jose-elias-alvarez/null-ls.nvim",
event = "BufReadPre",
dependencies = { "mason.nvim" },
2022-12-30 17:30:52 +01:00
config = function()
local nls = require("null-ls")
nls.setup({
sources = {
-- nls.builtins.formatting.prettierd,
nls.builtins.formatting.stylua,
nls.builtins.diagnostics.flake8,
},
})
end,
},
-- cmdline tools and lsp servers
{
"williamboman/mason.nvim",
cmd = "Mason",
keys = { { "<leader>cm", "<cmd>Mason<cr>", desc = "Mason" } },
ensure_installed = {
"stylua",
"shellcheck",
"shfmt",
"flake8",
},
config = function(plugin)
require("mason").setup()
local mr = require("mason-registry")
for _, tool in ipairs(plugin.ensure_installed) do
local p = mr.get_package(tool)
if not p:is_installed() then
p:install()
end
end
end,
},
2022-12-30 17:30:52 +01:00
}