180 lines
6.3 KiB
Lua
180 lines
6.3 KiB
Lua
return {
|
|
{
|
|
{
|
|
'VonHeikemen/lsp-zero.nvim',
|
|
branch = 'v3.x',
|
|
lazy = true,
|
|
config = false,
|
|
init = function()
|
|
-- Disable automatic setup, we are doing it manually
|
|
vim.g.lsp_zero_extend_cmp = 0
|
|
vim.g.lsp_zero_extend_lspconfig = 0
|
|
end
|
|
},
|
|
{
|
|
'williamboman/mason.nvim',
|
|
lazy = false,
|
|
config = true
|
|
},
|
|
|
|
-- Autocompletion
|
|
{
|
|
'hrsh7th/nvim-cmp',
|
|
event = 'InsertEnter',
|
|
dependencies = {
|
|
'L3MON4D3/LuaSnip',
|
|
'hrsh7th/cmp-buffer',
|
|
'hrsh7th/cmp-path',
|
|
'hrsh7th/cmp-cmdline',
|
|
'hrsh7th/cmp-nvim-lsp-signature-help',
|
|
'saadparwaiz1/cmp_luasnip'
|
|
},
|
|
config = function()
|
|
local lsp_zero = require('lsp-zero')
|
|
lsp_zero.extend_cmp()
|
|
|
|
local cmp = require('cmp')
|
|
|
|
cmp.setup({
|
|
sources = {
|
|
-- LuaFormatter off
|
|
{ name = 'path' },
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'nvim_lua' },
|
|
{ name = 'luasnip', keyword_length = 2 },
|
|
{ name = 'buffer', keyword_length = 3 },
|
|
{ name = 'nvim_lsp_signature_help' }
|
|
-- LuaFormatter on
|
|
},
|
|
formatting = lsp_zero.cmp_format(),
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
|
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
|
['<Tab>'] = cmp.mapping.confirm({
|
|
select = true
|
|
}),
|
|
['<C-Space>'] = cmp.mapping.complete()
|
|
}),
|
|
snippet = {
|
|
expand = function(args) require('luasnip').lsp_expand(args.body) end
|
|
}
|
|
})
|
|
|
|
cmp.setup.filetype('gitcommit', {
|
|
-- LuaFormatter off
|
|
sources = cmp.config.sources(
|
|
{ { name = 'git' } },
|
|
{ { name = 'buffer' } }
|
|
)
|
|
-- LuaFormatter on
|
|
})
|
|
|
|
cmp.setup.cmdline({
|
|
'/',
|
|
'?'
|
|
}, {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{
|
|
name = 'buffer'
|
|
}
|
|
}
|
|
})
|
|
|
|
cmp.setup.cmdline(':', {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = cmp.config.sources({
|
|
{
|
|
name = 'path'
|
|
}
|
|
}, {
|
|
{
|
|
name = 'cmdline'
|
|
}
|
|
})
|
|
})
|
|
end
|
|
},
|
|
|
|
-- LSP
|
|
{
|
|
'neovim/nvim-lspconfig',
|
|
cmd = {
|
|
'LspInfo',
|
|
'LspInstall',
|
|
'LspStart'
|
|
},
|
|
event = {
|
|
'BufReadPre',
|
|
'BufNewFile'
|
|
},
|
|
dependencies = {
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
'williamboman/mason-lspconfig.nvim',
|
|
"folke/trouble.nvim"
|
|
},
|
|
config = function()
|
|
local lsp_zero = require('lsp-zero')
|
|
lsp_zero.extend_lspconfig()
|
|
|
|
lsp_zero.on_attach(function(client, bufnr)
|
|
vim.keymap.set("n", "<leader>ld", function() vim.lsp.buf.definition() end, {
|
|
desc = "Go to definition"
|
|
})
|
|
vim.keymap.set("n", "<leader>lh", function() vim.lsp.buf.hover() end, {
|
|
desc = "Hover"
|
|
})
|
|
vim.keymap.set("n", "<leader>lr", ":Trouble lsp_references<CR>", {
|
|
desc = "Show references"
|
|
})
|
|
vim.keymap.set("n", "<leader>ln", function() vim.lsp.buf.rename() end, {
|
|
desc = "Rename"
|
|
})
|
|
vim.keymap.set("n", "<leader>ls", function() vim.lsp.buf.signature_help() end, {
|
|
desc = "Signature help"
|
|
})
|
|
vim.keymap.set("n", "<leader>la", function() vim.lsp.buf.code_action() end, {
|
|
desc = "Code actions"
|
|
})
|
|
vim.keymap.set("n", "<leader>la", function() vim.lsp.buf.code_action() end, {
|
|
desc = "Code actions"
|
|
})
|
|
end)
|
|
|
|
require('mason-lspconfig').setup({
|
|
ensure_installed = {
|
|
'clangd',
|
|
'pyright',
|
|
'cmake',
|
|
'texlab'
|
|
},
|
|
handlers = {
|
|
lsp_zero.default_setup,
|
|
lua_ls = function()
|
|
local lua_opts = lsp_zero.nvim_lua_ls()
|
|
require('lspconfig').lua_ls.setup(lua_opts)
|
|
end
|
|
}
|
|
})
|
|
|
|
require('lspconfig')['clangd'].setup {
|
|
cmd = {
|
|
"clangd",
|
|
"--background-index",
|
|
"--clang-tidy",
|
|
"--completion-style=bundled",
|
|
"--cross-file-rename",
|
|
"--header-insertion=iwyu",
|
|
-- Required for embedded system compilers
|
|
"--query-driver=/**/*g++",
|
|
"--offset-encoding=utf-16"
|
|
-- "-j=8",
|
|
-- "--malloc-trim",
|
|
-- "--pch-storage=memory"
|
|
}
|
|
}
|
|
end
|
|
}
|
|
}
|
|
}
|