vim.api.nvim_create_autocmd('LspAttach', { desc = 'LSP actions', callback = function(event) local bufmap = function(mode, lhs, rhs) local opts = {buffer = event.buf} vim.keymap.set(mode, lhs, rhs, opts) end -- Trigger code completion bufmap('i', '', '') -- Display documentation of the symbol under the cursor bufmap('n', 'K', 'lua vim.lsp.buf.hover()') -- Jump to the definition bufmap('n', 'gd', 'lua vim.lsp.buf.definition()') -- Jump to declaration bufmap('n', 'gD', 'lua vim.lsp.buf.declaration()') -- Lists all the implementations for the symbol under the cursor bufmap('n', 'gi', 'lua vim.lsp.buf.implementation()') -- Jumps to the definition of the type symbol bufmap('n', 'go', 'lua vim.lsp.buf.type_definition()') -- Lists all the references bufmap('n', 'gr', 'lua vim.lsp.buf.references()') -- Displays a function's signature information bufmap('n', '', 'lua vim.lsp.buf.signature_help()') -- Renames all references to the symbol under the cursor bufmap('n', '', 'lua vim.lsp.buf.rename()') -- Format current file bufmap('n', '', 'lua vim.lsp.buf.format()') -- Selects a code action available at the current cursor position bufmap('n', '', 'lua vim.lsp.buf.code_action()') end }) local capabilities = require('cmp_nvim_lsp').default_capabilities() require('mason').setup({}) require('mason-lspconfig').setup({ ensure_installed = {'lua_ls', 'jedi_language_server', 'rust_analyzer', 'clangd' }, handlers = { require('lspconfig').clangd.setup({ filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto","hpp"}, capabilities = capabilities, }), require('lspconfig').rust_analyzer.setup({ capabilities = capabilities, cmd = { "rustup", "run", "stable", "rust-analyzer", } }), require('lspconfig').jedi_language_server.setup{ capabilities = capabilities, }, require('lspconfig').lua_ls.setup{ capabilities = capabilities, -- settings = { -- workspace = { -- environmentPath = "./venv/bin/python", -- } -- } }, }, }) local cmp = require('cmp') local cmp_select = {behavior = cmp.SelectBehavior.Select} cmp.setup({ sources = { {name = 'path'}, {name = 'nvim_lsp'}, {name = 'nvim_lua'}, }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [''] = cmp.mapping.confirm({ select = true }), [''] = cmp.mapping.complete(), }), })