From 9fafda8a23cdb5ad6516462cea23f18bfda6fccb Mon Sep 17 00:00:00 2001 From: Steins7 Date: Thu, 20 Oct 2022 14:35:47 +0200 Subject: [PATCH] Replace coq with nvim-cmp coq is way more complicated (python-venv and sqlite) and crashes in wsl --- init.lua | 2 - lua/plugins.lua | 132 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 118 insertions(+), 16 deletions(-) diff --git a/init.lua b/init.lua index c5b9bb7..0896666 100644 --- a/init.lua +++ b/init.lua @@ -29,6 +29,4 @@ vim.api.nvim_set_keymap('n', '', ":bp", {}) -- Load plugins require('plugins') --- Launch COQ after nvim finished starting -vim.api.nvim_create_autocmd({'VimEnter'}, {command = 'COQnow -s'}) diff --git a/lua/plugins.lua b/lua/plugins.lua index fc0104c..6ca7042 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,3 +1,15 @@ +-- functions for auto-complete +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1] + :sub(col, col):match("%s") == nil +end + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + +-- plugins definition local function manage_plugins() local plugins = { @@ -42,32 +54,124 @@ local function manage_plugins() end }, - -- COQ - ["https://github.com/ms-jpq/coq_nvim.git"] = {}, - ["https://github.com/ms-jpq/coq.artifacts.git"] = { - packadd_after = { ["https://github.com/ms-jpq/coq_nvim.git"] = true } + -- Auto-completion + ["https://github.com/hrsh7th/cmp-nvim-lsp.git"] = {}, + ["https://github.com/hrsh7th/cmp-buffer.git"] = {}, + ["https://github.com/hrsh7th/cmp-path.git"] = {}, + ["https://github.com/hrsh7th/cmp-cmdline.git"] = {}, + ["https://github.com/hrsh7th/cmp-vsnip.git"] = {}, + ["https://github.com/hrsh7th/vim-vsnip.git"] = {}, + ["https://github.com/hrsh7th/nvim-cmp.git"] = { + packadd_after = { + ["https://github.com/hrsh7th/cmp-nvim-lsp.git"] = true, + ["https://github.com/hrsh7th/cmp-buffer.git"] = true, + ["https://github.com/hrsh7th/cmp-path.git"] = true, + ["https://github.com/hrsh7th/cmp-cmdline.git"] = true, + ["https://github.com/hrsh7th/cmp-vsnip.git"] = true, + ["https://github.com/hrsh7th/vim-vsnip.git"] = true, + }, + packadd_hook = function() + vim.o.completeopt = "menu,menuone,noselect" + local cmp = require("cmp") + + cmp.setup({ + snippet = { + -- snippet engine is required + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + -- The fallback function sends a already mapped key. + -- In this case, it's probably ``. + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + }, { + { name = 'buffer' }, + }) + }) + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, + }, { + { name = 'buffer' }, + }) + }) + + -- Use buffer source for `/` and `?` + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + -- Use cmdline & path source for ':' + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + end }, -- LSP servers ["https://github.com/simrat39/rust-tools.nvim.git"] = { - packadd_after = { ["https://github.com/neovim/nvim-lspconfig.git"] = true, - ["https://github.com/ms-jpq/coq_nvim.git"] = true}, + packadd_after = { + ["https://github.com/neovim/nvim-lspconfig.git"] = true, + ["https://github.com/hrsh7th/nvim-cmp.git"] = true, + }, packadd_hook = function() local rt = require("rust-tools") - local coq = require("coq") + local capabilities = require("cmp_nvim_lsp").default_capabilities() - rt.setup(coq.lsp_ensure_capabilities({ + rt.setup({ server = { + capabilities = capabilities, on_attach = function(_, bufnr) -- Hover actions - vim.keymap.set("n", "", - rt.hover_actions.hover_actions, { buffer = bufnr }) - -- Code action groups - vim.keymap.set("n", "a", - rt.code_action_group.code_action_group, { buffer = bufnr }) + --vim.keymap.set("n", "", + --rt.hover_actions.hover_actions, { buffer = bufnr }) + ---- Code action groups + --vim.keymap.set("n", "a", + --rt.code_action_group.code_action_group, { buffer = bufnr }) end, }, - })) + }) end },