lsp-setup.nvim
A simple wrapper for nvim-lspconfig and mason-lspconfig (optional) to easily setup LSP servers.
Installation
- Neovim >= 0.8 (>= 0.10 or nightly for inlay hints)
- nvim-lspconfig
- mason.nvim & mason-lspconfig.nvim (optional)
lazy.nvim
{
'junnplus/lsp-setup.nvim',
dependencies = {
'neovim/nvim-lspconfig',
'williamboman/mason.nvim', -- optional
'williamboman/mason-lspconfig.nvim', -- optional
},
}
packer.nvim
use {
'junnplus/lsp-setup.nvim',
requires = {
'neovim/nvim-lspconfig',
'williamboman/mason.nvim', -- optional
'williamboman/mason-lspconfig.nvim', -- optional
}
}
Usage
require('lsp-setup').setup({
servers = {
pylsp = {}
}
})
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'] = {}
}
})
Inlay hints
Inlay hints are only available in Neovim >= 0.10 or nightly.
require('lsp-setup').setup({
inlay_hints = {
enabled = true,
}
})
typescript-language-server
https://github.com/typescript-language-server/typescript-language-server#inlay-hints-textdocumentinlayhintrequire('lsp-setup').setup({
servers = {
tsserver = {
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = false,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
}
},
}
},
}
})
gopls
https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.mdrequire('lsp-setup').setup({
servers = {
gopls = {
settings = {
gopls = {
hints = {
rangeVariableTypes = true,
parameterNames = true,
constantValues = true,
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
functionTypeParameters = true,
},
},
},
},
}
})
rust-analyzer
https://github.com/simrat39/rust-tools.nvim/wiki/Server-Configuration-Schemarequire('lsp-setup').setup({
servers = {
rust_analyzer = {
settings = {
['rust-analyzer'] = {
inlayHints = {
bindingModeHints = {
enable = false,
},
chainingHints = {
enable = true,
},
closingBraceHints = {
enable = true,
minLines = 25,
},
closureReturnTypeHints = {
enable = 'never',
},
lifetimeElisionHints = {
enable = 'never',
useParameterNames = false,
},
maxLength = 25,
parameterHints = {
enable = true,
},
reborrowHints = {
enable = 'never',
},
renderColons = true,
typeHints = {
enable = true,
hideClosureInitialization = false,
hideNamedConstructor = false,
},
}
},
},
},
}
})
lua-language-server
https://github.com/LuaLS/lua-language-server/wiki/Settings#hintrequire('lsp-setup').setup({
servers = {
lua_ls = {
settings = {
Lua = {
hint = {
enable = false,
arrayIndex = "Auto",
await = true,
paramName = "All",
paramType = true,
semicolon = "SameLine",
setType = false,
},
},
},
},
}
})
zls
https://github.com/zigtools/zlsrequire('lsp-setup').setup({
servers = {
zls = {
settings = {
zls = {
enable_inlay_hints = true,
inlay_hints_show_builtin = true,
inlay_hints_exclude_single_argument = true,
inlay_hints_hide_redundant_param_names = false,
inlay_hints_hide_redundant_param_names_last_token = false,
}
}
},
}
})
Setup structure
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,
parameter_hints = true,
type_hints = true,
highlight = 'Comment',
priority = 0,
}
})
Integrations
cmp-nvim-lsp or coq_nvim
If installed, will auto advertise capabilities to LSP servers.
neodev
-- Setup lua_ls with neodev
require('neodev').setup()
require('lsp-setup').setup({
servers = {
lua_ls = {}
}
})
rust-tools.nvim
Using require('lsp-setup.rust-tools').setup({})
instead of require('rust-tools').setup({})
.
require('lsp-setup').setup({
servers = {
rust_analyzer = require('lsp-setup.rust-tools').setup({
server = {
settings = {
['rust-analyzer'] = {
cargo = {
loadOutDirsFromCheck = true,
},
procMacro = {
enable = true,
},
},
},
},
})
}
})
clangd_extensions.nvim
Using require('lsp-setup.clangd_extensions').setup({})
instead of require('clangd_extensions').setup({})
.
require('lsp-setup').setup({
servers = {
clangd = require('lsp-setup.clangd_extensions').setup({})
}
})
Contributing
Bug reports and feature requests are welcome! PRs are doubly welcome!
Acknowledgements
The implementation of inlay hints is based on lvimuser's lsp-inlayhints.nvim.