A simple wrapper for nvim-lspconfig and mason-lspconfig (optional) to easily setup LSP servers.
{
'junnplus/lsp-setup.nvim',
dependencies = {
'neovim/nvim-lspconfig',
'williamboman/mason.nvim', -- optional
'williamboman/mason-lspconfig.nvim', -- optional
},
}
use {
'junnplus/lsp-setup.nvim',
requires = {
'neovim/nvim-lspconfig',
'williamboman/mason.nvim', -- optional
'williamboman/mason-lspconfig.nvim', -- optional
}
}
require('lsp-setup').setup({
servers = {
pylsp = {},
clangd = {}
}
})
You can replace pylsp
with the LSP server name you need, see available LSPs.
Also support installing custom versions of LSP servers (requires mason and mason-lspconfig), for example:
require('lsp-setup').setup({
servers = {
['rust_analyzer@nightly'] = {}
}
})
LSP servers returns a table will automatically setup server process using lspconfig. You can also pass a nil function to setup the server manually, see Integrations/rust-tools.nvim.
Inlay hints are only available in Neovim >= 0.10 or nightly.
require('lsp-setup').setup({
inlay_hints = {
enabled = true,
}
})
require('lsp-setup').setup({
-- Default mappings
-- gD = 'lua vim.lsp.buf.declaration()',
-- gd = 'lua vim.lsp.buf.definition()',
-- gt = 'lua vim.lsp.buf.type_definition()',
-- gi = 'lua vim.lsp.buf.implementation()',
-- gr = 'lua vim.lsp.buf.references()',
-- K = 'lua vim.lsp.buf.hover()',
-- ['<C-k>'] = 'lua vim.lsp.buf.signature_help()',
-- ['<space>rn'] = 'lua vim.lsp.buf.rename()',
-- ['<space>ca'] = 'lua vim.lsp.buf.code_action()',
-- ['<space>f'] = 'lua vim.lsp.buf.formatting()',
-- ['<space>e'] = 'lua vim.diagnostic.open_float()',
-- ['[d'] = 'lua vim.diagnostic.goto_prev()',
-- [']d'] = 'lua vim.diagnostic.goto_next()',
default_mappings = true,
-- Custom mappings, will overwrite the default mappings for the same key
-- Example mappings for telescope pickers:
-- gd = 'lua require"telescope.builtin".lsp_definitions()',
-- gi = 'lua require"telescope.builtin".lsp_implementations()',
-- gr = 'lua require"telescope.builtin".lsp_references()',
mappings = {},
-- Global on_attach
on_attach = function(client, bufnr)
-- Support custom the on_attach function for global
-- Formatting on save as default
require('lsp-setup.utils').format_on_save(client)
end,
-- Global capabilities
capabilities = vim.lsp.protocol.make_client_capabilities(),
-- Configuration of LSP servers
servers = {
-- Install LSP servers automatically (requires mason and mason-lspconfig)
-- LSP server configuration please see: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- pylsp = {},
-- rust_analyzer = {
-- settings = {
-- ['rust-analyzer'] = {
-- cargo = {
-- loadOutDirsFromCheck = true,
-- },
-- procMacro = {
-- enable = true,
-- },
-- },
-- },
-- },
},
-- Configuration of LSP inlay hints
inlay_hints = {
enabled = false,
highlight = 'Comment',
}
})
If installed, will auto advertise capabilities to LSP servers.
-- Setup lua_ls with neodev
require('neodev').setup()
require('lsp-setup').setup({
servers = {
lua_ls = {}
}
})
require('lsp-setup').setup({
servers = {
rust_analyzer = function()
require('rust-tools').setup({
server = {
settings = {
['rust-analyzer'] = {
cargo = {
loadOutDirsFromCheck = true,
},
procMacro = {
enable = true,
},
},
},
},
})
-- no need to return anything
end,
}
})
Bug reports and feature requests are welcome! PRs are doubly welcome!