diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index 062f96f..237344d 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,91 +1,94 @@ return { - "hrsh7th/nvim-cmp", - version = false, -- last release is way too old - event = "InsertEnter", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "saadparwaiz1/cmp_luasnip", - "hrsh7th/cmp-nvim-lua", - -- { - -- "hrsh7th/cmp-cmdline", - -- --event = "BufWinEnter", - -- event = "VeryLazy", - -- config = function() - -- require("user.cmdline") - -- end, - -- }, - }, - opts = function() - local cmp = require("cmp") - local luasnip = require("luasnip") + { "nvim-treesitter/nvim-treesitter" }, + { + "hrsh7th/nvim-cmp", + version = false, -- last release is way too old + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lua", + -- { + -- "hrsh7th/cmp-cmdline", + -- --event = "BufWinEnter", + -- event = "VeryLazy", + -- config = function() + -- require("user.cmdline") + -- end, + -- }, + }, + opts = function() + local cmp = require("cmp") + local luasnip = require("luasnip") - local check_backspace = function() - local col = vim.fn.col(".") - 1 - return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") - end + local check_backspace = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") + end - return { - completion = { - completeopt = "menu,menuone,noinsert", - }, - snippet = { - expand = function(args) - require("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.abort(), - [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif check_backspace() then - fallback() - else - fallback() - end - end, { - "i", - "s", + return { + completion = { + completeopt = "menu,menuone,noinsert", + }, + snippet = { + expand = function(args) + require("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.abort(), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), }), - }), - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - { name = "nvim_lua" }, - }), - formatting = { - fields = { "kind", "abbr", "menu" }, - format = function(entry, vim_item) - vim_item.kind = string.format("%s", require("user.icons")["kind"][vim_item.kind]) - vim_item.menu = ({ - nvim_lsp = "(LSP)", - luasnip = "(Snippet)", - buffer = "(Buffer)", - path = "(Path)", - })[entry.source.name] - return vim_item - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - experimental = { - ghost_text = false, - native_menu = false, - }, - } - end, + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + { name = "nvim_lua" }, + }), + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + vim_item.kind = string.format("%s", require("user.icons")["kind"][vim_item.kind]) + vim_item.menu = ({ + nvim_lsp = "(LSP)", + luasnip = "(Snippet)", + buffer = "(Buffer)", + path = "(Path)", + })[entry.source.name] + return vim_item + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + experimental = { + ghost_text = false, + native_menu = false, + }, + } + end, + }, } diff --git a/lua/plugins/cmp_cndline.lua b/lua/plugins/cmp_cndline.lua index e514fbd..742106b 100644 --- a/lua/plugins/cmp_cndline.lua +++ b/lua/plugins/cmp_cndline.lua @@ -1,5 +1,4 @@ return { - { "nvim-treesitter/nvim-treesitter" }, -- { -- "hrsh7th/cmp-cmdline", -- event = "BufWinEnter",