From daed5f0c76a051cb9fcf0bafc5739c204f3b77ba Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 14 Apr 2024 23:36:23 -0400 Subject: [PATCH] Getting rid of lsp-zero and re-doing lsp config. Also added Toggle Term --- after/plugin/lsp.lua | 79 +++++++++++++++++++++++++++++++------------- lua/pippy/lazy.lua | 3 +- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 0158631..2cd461a 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,31 +1,65 @@ -local lsp_zero = require('lsp-zero') +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 -lsp_zero.on_attach(function(client, bufnr) - local opts = {buffer = bufnr, remap = false} - -- disable semantic highlighting cause I like tree sitter's coloring better - client.server_capabilities.semanticTokensProvider = nil - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) - vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) - vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) - vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, 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 = { - 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({ + 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') @@ -37,7 +71,6 @@ cmp.setup({ {name = 'nvim_lsp'}, {name = 'nvim_lua'}, }, - formatting = lsp_zero.cmp_format(), mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), diff --git a/lua/pippy/lazy.lua b/lua/pippy/lazy.lua index 3e93d5f..135f0cc 100644 --- a/lua/pippy/lazy.lua +++ b/lua/pippy/lazy.lua @@ -49,11 +49,10 @@ require("lazy").setup({ cmd = "Neoconf" }, "folke/neodev.nvim", - -- {'akinsho/toggleterm.nvim', version = "*", config = true}, + {'akinsho/toggleterm.nvim', version = "*", config = true}, {"danymat/neogen", dependencies = "nvim-treesitter/nvim-treesitter", config = true}, {'williamboman/mason.nvim'}, {'williamboman/mason-lspconfig.nvim'}, - {'VonHeikemen/lsp-zero.nvim', branch = 'v3.x'}, {'neovim/nvim-lspconfig'}, {'hrsh7th/cmp-nvim-lsp'}, {'hrsh7th/nvim-cmp'},