From c3867d7cbbfd45bf3938d9d9967a6751f7225d7e Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 18 Oct 2022 11:06:28 +0200 Subject: nvim: use cmp instead of coq --- .config/nvim/init.vim | 18 +++++++++++++--- .config/nvim/lua/lsp_conf.lua | 50 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 5 deletions(-) (limited to '.config/nvim') diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 063a8f8..0007a52 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -24,14 +24,22 @@ Plug 'matze/vim-move' Plug 'togglebyte/togglerust' " Debug Rust projects +Plug 'chriskempson/base16-vim' + if has('nvim') - Plug 'rktjmp/lush.nvim' + " Plug 'rktjmp/lush.nvim' Plug 'dcariotti/gruvbox.nvim' Plug 'nvim-telescope/telescope.nvim' Plug 'neovim/nvim-lspconfig' - Plug 'ms-jpq/coq_nvim', {'branch': 'coq'} - Plug 'ms-jpq/coq.artifacts', {'branch': 'artifacts'} + + Plug 'hrsh7th/nvim-cmp' + Plug 'hrsh7th/cmp-nvim-lsp' + Plug 'saadparwaiz1/cmp_luasnip' + Plug 'L3MON4D3/LuaSnip' + + " Plug 'ms-jpq/coq_nvim', {'branch': 'coq'} + " Plug 'ms-jpq/coq.artifacts', {'branch': 'artifacts'} Plug 'kyazdani42/nvim-tree.lua' Plug 'ray-x/lsp_signature.nvim' Plug 'folke/todo-comments.nvim' @@ -45,6 +53,7 @@ if has('nvim') Plug 'folke/trouble.nvim' Plug 'folke/lsp-colors.nvim' + Plug 'sindrets/diffview.nvim' Plug 'windwp/nvim-ts-autotag' @@ -116,6 +125,9 @@ set background=dark if has('nvim') colorscheme gruvbox + " let base16colorspace=256 + " colorscheme base16-irblack + lua require('git') let g:coq_settings = { 'auto_start': v:true } lua require('lsp_conf') diff --git a/.config/nvim/lua/lsp_conf.lua b/.config/nvim/lua/lsp_conf.lua index a64839e..36b6735 100644 --- a/.config/nvim/lua/lsp_conf.lua +++ b/.config/nvim/lua/lsp_conf.lua @@ -1,5 +1,8 @@ local nvim_lsp = require('lspconfig') -local coq = require('coq') +-- local coq = require('coq') +-- + +local capabilities = require("cmp_nvim_lsp").default_capabilities() local null_ls = require("null-ls") local trouble = require("trouble") @@ -48,6 +51,7 @@ local common_on_attach = function(client, bufnr) -- Mappings. vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "ga", "lua vim.lsp.buf.code_action()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) @@ -57,7 +61,7 @@ end local servers = { 'pyright', 'rust_analyzer', 'tsserver', 'clangd' } -local capabilities = vim.lsp.protocol.make_client_capabilities() +-- local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.offsetEncoding = { "utf-16" } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { @@ -75,3 +79,45 @@ trouble.setup({ auto_open = false }) + +-- nvim-cmp setup +local luasnip = require 'luasnip' +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} -- cgit v1.2.3-18-g5258