diff --git a/candy/lua/marshmallow/completion.lua b/candy/lua/marshmallow/completion.lua deleted file mode 100644 index 7d5be76..0000000 --- a/candy/lua/marshmallow/completion.lua +++ /dev/null @@ -1,40 +0,0 @@ --- Awaiting mini.completion w/ snippet support... --- require("mini.completion").setup() - -local cmp = require("cmp") -cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - view = { - entries = { name = "custom", selection_order = "near_cursor" }, - }, - - 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 }), - }), - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "async_path" }, - }, { - { name = "buffer" }, - }), - - experimental = { ghost_text = true }, -}) - -cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "async_path" }, - }, { - { name = "cmdline" }, - }), -}) diff --git a/candy/lua/marshmallow/init.lua b/candy/lua/marshmallow/init.lua index 6d2aa2e..c084266 100644 --- a/candy/lua/marshmallow/init.lua +++ b/candy/lua/marshmallow/init.lua @@ -2,7 +2,6 @@ require("marshmallow.defaults") require("marshmallow.statusline") require("marshmallow.remap") require("marshmallow.treesitter") -require("marshmallow.completion") require("marshmallow.lsp") require("marshmallow.snippets") @@ -14,6 +13,7 @@ require("hardtime").setup() require("mini.jump2d").setup({ view = { dim = true } }) require("mini.jump").setup() require("mini.bracketed").setup() +require("mini.completion").setup() require("marshmallow.format") require("marshmallow.files") diff --git a/candy/lua/marshmallow/remap.lua b/candy/lua/marshmallow/remap.lua index 3c16e5a..b7684f9 100644 --- a/candy/lua/marshmallow/remap.lua +++ b/candy/lua/marshmallow/remap.lua @@ -186,3 +186,32 @@ if vim.g.neovide then vim.keymap.set("c", "", "+") -- Paste command mode vim.keymap.set("i", "", 'l"+Pli') -- Paste insert mode end + +-- Completion -- + +-- In completion +local keycode = vim.keycode or function(x) + return vim.api.nvim_replace_termcodes(x, true, true, true) +end +local keys = { + ["cr"] = keycode(""), + -- Enter the selected option + ["ctrl-y"] = keycode(""), + -- Enter the first option + ["ctrl-n_ctrl-y"] = keycode(""), +} + +_G.cr_action = function() + if vim.fn.pumvisible() ~= 0 then + -- If popup is visible, confirm selected item or add new line otherwise + local item_selected = vim.fn.complete_info()["selected"] ~= -1 + return item_selected and keys["ctrl-y"] or keys["ctrl-n_ctrl-y"] + else + -- If popup is not visible, use plain ``. You might want to customize + -- according to other plugins. For example, to use 'mini.pairs', replace + -- next line with `return require('mini.pairs').cr()` + return keys["cr"] + end +end + +vim.keymap.set("i", "", "v:lua._G.cr_action()", { expr = true }) diff --git a/candy/lua/marshmallow/snippets.lua b/candy/lua/marshmallow/snippets.lua index b812aac..41ef63a 100644 --- a/candy/lua/marshmallow/snippets.lua +++ b/candy/lua/marshmallow/snippets.lua @@ -1,19 +1,9 @@ --- Awaiting mini.snippets +local gen_loader = require("mini.snippets").gen_loader +local globals = vim.env.NIX_ABS_CONFIG .. "/snippets/global.json" -local ls = require("luasnip") - -vim.keymap.set({ "i" }, "", function() - ls.expand() -end, { silent = true }) -vim.keymap.set({ "i", "s" }, "", function() - ls.jump(1) -end, { silent = true }) -vim.keymap.set({ "i", "s" }, "", function() - ls.jump(-1) -end, { silent = true }) - -vim.keymap.set({ "i", "s" }, "", function() - if ls.choice_active() then - ls.change_choice(1) - end -end, { silent = true }) +require("mini.snippets").setup({ + snippets = { + gen_loader.from_file(globals), + gen_loader.from_lang(), + }, +}) diff --git a/candy/snippets/global.json b/candy/snippets/global.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/candy/snippets/global.json @@ -0,0 +1 @@ +{}