diff --git a/lua/config/cmp.lua b/lua/config/cmp.lua index 06d0048..9541209 100644 --- a/lua/config/cmp.lua +++ b/lua/config/cmp.lua @@ -5,23 +5,20 @@ function M.setup() 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 cmp = require "cmp" local lspkind = require "lspkind" - local cmp_autopairs = require "nvim-autopairs.completion.cmp" + local luasnip = require "luasnip" cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } }) - + vim.o.pumheight = 10 cmp.setup { - completion = { completeopt = "menu,menuone,noinsert", keyword_length = 1,}, - experimental = { native_menu = false, ghost_text = false }, - + completion = { completeopt = "menu,menuone,noinsert,noselect", keyword_length = 1, }, + experimental = { native_menu = false, ghost_text = true }, snippet = { expand = function(args) - require("luasnip").lsp_expand(args.body) + luasnip.lsp_expand(args.body) end, }, - formatting = { -- format = function(entry, vim_item) -- vim_item.menu = ({ @@ -47,24 +44,24 @@ function M.setup() }, mapping = { [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.mapping { i = cmp.mapping.close(), c = cmp.mapping.close() }, - [""] = cmp.mapping { - i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, - c = function(fallback) - if cmp.visible() then - cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false } - else - fallback() - end - end, - }, + [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.close() + else + cmp.complete() + end + end, { "i", "c" }), + [""] = cmp.mapping { i = cmp.mapping.close(), c = cmp.mapping.close() }, + [""] = cmp.mapping(cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }), + { "i", "c" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() else @@ -77,24 +74,24 @@ function M.setup() else fallback() end - end, - {"i", "s", "c" }), + end, + { "i", "s", "c" }), }, sources = { - { name = "nvim_lsp"}, + { name = "luasnip" }, + { name = "nvim_lsp" }, { name = "treesitter" }, { name = "buffer" }, { name = "nvim_lua" }, { name = "path" }, - { name = "nvim_lsp_signature_help"}, + { name = "nvim_lsp_signature_help" }, }, - --[[ documentation = { + --[[ documentation = { border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, winhighlight = "NormalFloat:NormalFloat,FloatBorder:TelescopeBorder", }, ]] - } - + } cmp.setup.cmdline("/", { sources = { { name = "buffer" }, diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua index 10ecf74..c6f00ed 100644 --- a/lua/config/luasnip.lua +++ b/lua/config/luasnip.lua @@ -6,6 +6,8 @@ function M.setup() luasnip.config.set_config { history = false, updateevents = "TextChanged,TextChangedI", + region_check_events = 'InsertEnter', + delete_check_events = 'InsertLeave', } require("luasnip/loaders/from_vscode").load()