From a21e884983ef6d99ef6fb3d3ce714953c43332a1 Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 12 Feb 2022 07:31:23 +0530 Subject: [PATCH] remove snippet option for cmp | fix telescope first time delay --- lua/core/default_config.lua | 1 - lua/plugins/configs/cmp.lua | 29 ++++++++++------------------- lua/plugins/init.lua | 17 +++++++---------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 47f0817..2901cfa 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -69,7 +69,6 @@ M.plugins = { lspsignature = true, -- lsp enhancements vim_matchup = true, -- improved matchit cmp = true, - snippets = true, nvimtree = true, autopairs = true, }, diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index c61086b..94944b7 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -4,21 +4,13 @@ if not present then return end -local snippets_status = require("core.utils").load_config().plugins.status.snippets +vim.opt.completeopt = "menuone,noselect" local default = { - completion = { - completeopt = "menuone,noselect", - }, - documentation = { - border = "single", - }, - snippet = (snippets_status and { + snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end, - }) or { - expand = function(_) end, }, formatting = { format = function(entry, vim_item) @@ -26,10 +18,9 @@ local default = { vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) vim_item.menu = ({ - buffer = "[BUF]", nvim_lsp = "[LSP]", nvim_lua = "[Lua]", - path = "[Path]", + buffer = "[BUF]", })[entry.source.name] return vim_item @@ -46,24 +37,24 @@ local default = { behavior = cmp.ConfirmBehavior.Replace, select = true, }, - [""] = cmp.mapping(function(fallback) + [""] = function(fallback) if cmp.visible() then cmp.select_next_item() - elseif snippets_status and require("luasnip").expand_or_jumpable() then - require("luasnip").expand_or_jump() + elseif require("luasnip").expand_or_jumpable() then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") else fallback() end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) + end, + [""] = function(fallback) if cmp.visible() then cmp.select_prev_item() elseif require("luasnip").jumpable(-1) then - require("luasnip").jump(-1) + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") else fallback() end - end, { "i", "s" }), + end, }, sources = { { name = "nvim_lsp" }, diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index f71041a..b26c8b1 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -115,7 +115,7 @@ local plugins = { { "max397574/better-escape.nvim", disable = not plugin_settings.status.better_escape, - event = "InsertEnter", + event = "InsertCharPre", config = override_req("better_escape", "plugins.configs.others", "better_escape"), }, @@ -124,23 +124,20 @@ local plugins = { { "rafamadriz/friendly-snippets", module = "cmp_nvim_lsp", - disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets), - event = "InsertEnter", + disable = not plugin_settings.status.cmp, + event = "InsertCharPre", }, - -- cmp by default loads after friendly snippets - -- if snippets are disabled -> cmp loads on insertEnter! { "hrsh7th/nvim-cmp", disable = not plugin_settings.status.cmp, - event = not plugin_settings.status.snippets and "InsertEnter", - after = plugin_settings.status.snippets and "friendly-snippets", + after = "friendly-snippets", config = override_req("nvim_cmp", "plugins.configs.cmp", "setup"), }, { "L3MON4D3/LuaSnip", - disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets), + disable = not plugin_settings.status.cmp, wants = "friendly-snippets", after = "nvim-cmp", config = override_req("luasnip", "plugins.configs.others", "luasnip"), @@ -148,14 +145,14 @@ local plugins = { { "saadparwaiz1/cmp_luasnip", - disable = not (plugin_settings.status.cmp and plugin_settings.status.snippets), + disable = not plugin_settings.status.cmp, after = plugin_settings.options.cmp.lazy_load and "LuaSnip", }, { "hrsh7th/cmp-nvim-lua", disable = not plugin_settings.status.cmp, - after = (plugin_settings.status.snippets and "cmp_luasnip") or "nvim-cmp", + after = "cmp_luasnip", }, {