2024-04-14 23:36:23 -04:00
|
|
|
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>')
|
2024-06-21 10:40:59 -04:00
|
|
|
-- Lists all the references
|
2024-04-14 23:36:23 -04:00
|
|
|
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({
|
2024-06-21 10:40:59 -04:00
|
|
|
ensure_installed = {'lua_ls', 'pyright', 'rust_analyzer', 'clangd' },
|
2024-02-04 20:53:56 -05:00
|
|
|
handlers = {
|
2024-04-14 23:36:23 -04:00
|
|
|
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",
|
|
|
|
}
|
|
|
|
|
|
|
|
}),
|
2024-06-21 10:40:59 -04:00
|
|
|
require('lspconfig').pyright.setup{
|
2024-04-14 23:36:23 -04:00
|
|
|
capabilities = capabilities,
|
|
|
|
},
|
2024-06-21 10:40:59 -04:00
|
|
|
-- require('lspconfig').jedi_language_server.setup{
|
|
|
|
-- capabilities = capabilities,
|
|
|
|
-- },
|
2024-04-14 23:36:23 -04:00
|
|
|
require('lspconfig').lua_ls.setup{
|
|
|
|
capabilities = capabilities,
|
|
|
|
-- settings = {
|
|
|
|
-- workspace = {
|
|
|
|
-- environmentPath = "./venv/bin/python",
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
},
|
|
|
|
},
|
2024-02-04 20:53:56 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|