my_nvim_config/after/plugin/lsp.lua

66 lines
2.4 KiB
Lua
Raw Normal View History

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', '<C-Space>', '<C-x><C-o>')
-- Display documentation of the symbol under the cursor
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
-- Jump to the definition
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
-- Jump to declaration
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
-- Lists all the implementations for the symbol under the cursor
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
-- Jumps to the definition of the type symbol
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
-- Lists all the references
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
-- Displays a function's signature information
bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
-- Renames all references to the symbol under the cursor
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
-- Format current file
bufmap('n', '<F3>', '<cmd>lua vim.lsp.buf.format()<cr>')
-- Selects a code action available at the current cursor position
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
end
})
local capabilities = require('cmp_nvim_lsp').default_capabilities()
2024-02-04 20:53:56 -05:00
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",
-- }
-- }
},
},
2024-02-04 20:53:56 -05:00
})