From 475a4c5f38c06537cb708cfafe84261d7b529a58 Mon Sep 17 00:00:00 2001 From: siduck76 Date: Fri, 27 Aug 2021 06:44:58 +0530 Subject: [PATCH] replace compe with cmp --- lua/core/options.lua | 1 - lua/plugins/configs/autopairs.lua | 12 ------ lua/plugins/configs/autosave.lua | 19 --------- lua/plugins/configs/cmp.lua | 63 ++++++++++++++++++++++++++++++ lua/plugins/configs/compe.lua | 26 ------------- lua/plugins/configs/lspconfig.lua | 14 +++++++ lua/plugins/configs/luasnip.lua | 57 +-------------------------- lua/plugins/configs/others.lua | 37 ++++++++++++++++++ lua/plugins/init.lua | 64 ++++++++++++++++++++----------- 9 files changed, 157 insertions(+), 136 deletions(-) delete mode 100644 lua/plugins/configs/autopairs.lua delete mode 100644 lua/plugins/configs/autosave.lua create mode 100644 lua/plugins/configs/cmp.lua delete mode 100644 lua/plugins/configs/compe.lua diff --git a/lua/core/options.lua b/lua/core/options.lua index 149d556..6872be6 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -8,7 +8,6 @@ local options = require("core.utils").load_config().options opt.clipboard = options.clipboard opt.cmdheight = options.cmdheight -opt.completeopt = { "menuone", "noselect" } opt.cul = true -- cursor line -- Indentline diff --git a/lua/plugins/configs/autopairs.lua b/lua/plugins/configs/autopairs.lua deleted file mode 100644 index 921307a..0000000 --- a/lua/plugins/configs/autopairs.lua +++ /dev/null @@ -1,12 +0,0 @@ -local present1, autopairs = pcall(require, "nvim-autopairs") -local present2, autopairs_completion = pcall(require, "nvim-autopairs.completion.compe") - -if not (present1 or present2) then - return -end - -autopairs.setup() -autopairs_completion.setup { - map_complete = true, -- insert () func completion - map_cr = true, -} diff --git a/lua/plugins/configs/autosave.lua b/lua/plugins/configs/autosave.lua deleted file mode 100644 index 2f41ff7..0000000 --- a/lua/plugins/configs/autosave.lua +++ /dev/null @@ -1,19 +0,0 @@ --- autosave.nvim plugin disabled by default -local present, autosave = pcall(require, "autosave") -if not present then - return -end - -autosave.setup { - enabled = vim.g.auto_save or false, -- takes boolean value from init.lua - execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S", - events = { "InsertLeave", "TextChanged" }, - conditions = { - exists = true, - filetype_is_not = {}, - modifiable = true, - }, - clean_command_line_interval = 2500, - on_off_commands = true, - write_all_buffers = false, -} diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua new file mode 100644 index 0000000..b149882 --- /dev/null +++ b/lua/plugins/configs/cmp.lua @@ -0,0 +1,63 @@ +vim.opt.completeopt = "menuone,noselect" + +local lspkind = require "lspkind" +local luasnip = require "luasnip" + +-- nvim-cmp setup +local cmp = require "cmp" +cmp.setup { + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + formatting = { + format = function(entry, vim_item) + vim_item.kind = lspkind.presets.default[vim_item.kind] .. " " .. vim_item.kind + + vim_item.menu = ({ + nvim_lsp = "[LSP]", + nvim_lua = "[Lua]", + buffer = "[BUF]", + })[entry.source.name] + + return vim_item + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [""] = function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("", true, true, true), "n") + elseif luasnip.expand_or_jumpable() then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") + else + fallback() + end + end, + [""] = function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("", true, true, true), "n") + elseif luasnip.jumpable(-1) then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") + else + fallback() + end + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + }, +} diff --git a/lua/plugins/configs/compe.lua b/lua/plugins/configs/compe.lua deleted file mode 100644 index d5c7a3d..0000000 --- a/lua/plugins/configs/compe.lua +++ /dev/null @@ -1,26 +0,0 @@ -local present, compe = pcall(require, "compe") -if not present then - return -end - -compe.setup { - enabled = true, - - autocomplete = true, - debug = false, - documentation = true, - incomplete_delay = 400, - max_abbr_width = 100, - max_kind_width = 100, - max_menu_width = 100, - min_length = 1, - preselect = "enable", - source_timeout = 200, - source = { - buffer = { kind = "﬘", true }, - luasnip = { kind = "﬌", true }, - nvim_lsp = true, - nvim_lua = true, - }, - throttle_time = 80, -} diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 6902706..ec74add 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -41,7 +41,21 @@ local function on_attach(_, bufnr) end local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.documentationFormat = { "markdown", "plaintext" } capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.textDocument.completion.completionItem.preselectSupport = true +capabilities.textDocument.completion.completionItem.insertReplaceSupport = true +capabilities.textDocument.completion.completionItem.labelDetailsSupport = true +capabilities.textDocument.completion.completionItem.deprecatedSupport = true +capabilities.textDocument.completion.completionItem.commitCharactersSupport = true +capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } +capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, +} -- lspInstall + lspconfig stuff diff --git a/lua/plugins/configs/luasnip.lua b/lua/plugins/configs/luasnip.lua index 8b83cb7..aa14912 100644 --- a/lua/plugins/configs/luasnip.lua +++ b/lua/plugins/configs/luasnip.lua @@ -3,64 +3,9 @@ if not present then return end -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - -local check_back_space = function() - local col = vim.fn.col "." - 1 - if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then - return true - else - return false - end -end - -_G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif luasnip and luasnip.expand_or_jumpable() then - return t "luasnip-expand-or-jump" - elseif check_back_space() then - return t "" - else - return vim.fn["compe#complete"]() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif luasnip and luasnip.jumpable(-1) then - return t "luasnip-jump-prev" - else - return t "" - end -end - -_G.completions = function() - local npairs - if not pcall(function() - npairs = require "nvim-autopairs" - end) then - return - end - - if vim.fn.pumvisible() == 1 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"] "" - end - end - return npairs.check_break_line_char() -end - -vim.api.nvim_set_keymap("i", "", "v:lua.completions()", { expr = true }) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) - luasnip.config.set_config { history = true, updateevents = "TextChanged,TextChangedI", } + require("luasnip/loaders/from_vscode").load() diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 2363557..0364db1 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,5 +1,42 @@ local M = {} +M.autopairs = function() + local present1, autopairs = pcall(require, "nvim-autopairs") + local present2, autopairs_completion = pcall(require, "nvim-autopairs.completion.cmp") + + if not (present1 or present2) then + return + end + + autopairs.setup() + autopairs_completion.setup { + map_complete = true, -- insert () func completion + map_cr = true, + } +end + +M.autosave = function() + -- autosave.nvim plugin is disabled by default + local present, autosave = pcall(require, "autosave") + if not present then + return + end + + autosave.setup { + enabled = vim.g.auto_save or false, -- takes boolean value from init.lua + execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S", + events = { "InsertLeave", "TextChanged" }, + conditions = { + exists = true, + filetype_is_not = {}, + modifiable = true, + }, + clean_command_line_interval = 2500, + on_off_commands = true, + write_all_buffers = false, + } +end + M.better_escape = function() local config = require("core.utils").load_config() vim.g.better_escape_interval = config.options.plugin.esc_insertmode_timeout or 300 diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 7e10672..11dd0ac 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -154,7 +154,7 @@ return packer.startup(function() disable = not plugin_status.autosave, "Pocco81/AutoSave.nvim", config = function() - require "plugins.configs.autosave" + require("plugins.configs.others").autosave() end, cond = function() return require("core.utils").load_config().options.plugin.autosave == true @@ -164,7 +164,7 @@ return packer.startup(function() use { "onsails/lspkind-nvim", disable = not plugin_status.lspkind, - event = "InsertEnter", + after = "LuaSnip", config = function() require("plugins.configs.others").lspkind() end, @@ -182,36 +182,56 @@ return packer.startup(function() end, } - -- load compe in insert mode only + -- load luasnips + cmp related in insert mode only + use { - "hrsh7th/nvim-compe", + "L3MON4D3/LuaSnip", event = "InsertEnter", + wants = "friendly-snippets", config = function() - require "plugins.configs.compe" + require "plugins.configs.luasnip" end, - wants = "LuaSnip", - requires = { - { - "L3MON4D3/LuaSnip", - wants = "friendly-snippets", - event = "InsertCharPre", - config = function() - require "plugins.configs.luasnip" - end, - }, - { - "rafamadriz/friendly-snippets", - event = "InsertCharPre", - }, - }, + } + + use { + "hrsh7th/nvim-cmp", + config = function() + require "plugins.configs.cmp" + end, + after = "lspkind-nvim", + } + + use { + "saadparwaiz1/cmp_luasnip", + after = "nvim-cmp", + } + + use { + "hrsh7th/cmp-nvim-lua", + after = "cmp_luasnip", + } + + use { + "hrsh7th/cmp-nvim-lsp", + after = "cmp-nvim-lua", + } + + use { + "hrsh7th/cmp-buffer", + after = "cmp-nvim-lsp", + } + + use { + "rafamadriz/friendly-snippets", + after = "cmp-buffer", } -- misc plugins use { "windwp/nvim-autopairs", - after = "nvim-compe", + after = "nvim-cmp", config = function() - require "plugins.configs.autopairs" + require("plugins.configs.others").autopairs() end, }