all repos

init.lua @ 6c15bbeded118b7b68614967080bf9d7d5b91c6b

my nvim config
6 files changed, 100 insertions(+), 3 deletions(-)
Revert "refactor(snippets): remove snippets from the config"

This reverts commit ed0b5de39310d9abb9e7f813fa8c9c69be606724.
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed at: 2024-01-18 06:40:15 +0200
Parent: 6c7f827
M after/ftplugin/go.lua

@@ -12,6 +12,6 @@ map("n", "<leader>;c", "<cmd>GoCmt<cr>")

map("n", "<leader>;g", "<cmd>GoGenerate %<cr>") map("n", "<leader>;o", "<cmd>GoTestAdd<cr>") map("n", "<leader>;a", "<cmd>GoTestsAll<cr>") -map("n", "<leader>;s", function() +map("n", "<leader><leader>", function() require("scratch.gotest_switcher").switch() end)
A after/luasnippets/go.lua

@@ -0,0 +1,15 @@

+---@diagnostic disable: undefined-global +-- selene: allow(undefined_variable) +return { + s({ trig = "err", name = "if err" }, { + t "if err != nil", + t { " {", "\t" }, + i(0), + t { "", "}" }, + }), + s(":", { + i(1, "name"), + t " := ", + i(2, "value"), + }), +}
A after/luasnippets/lua.lua

@@ -0,0 +1,20 @@

+---@diagnostic disable: undefined-global +-- selene: allow(undefined_variable) +return { + s( + "M", + fmt( + [[local <> = {} + +<> + +return <>]], + { + i(1, "M"), + i(0), + rep(1), + }, + { delimiters = "<>" } + ) + ), +}
M lazy-lock.json

@@ -1,11 +1,14 @@

{ "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "copilot-cmp": { "branch": "master", "commit": "72fbaa03695779f8349be3ac54fa8bd77eed3ee3" }, "copilot.lua": { "branch": "master", "commit": "b03617a6dc4bc88b65ab5deac1631da9a9c2dcaf" }, "fidget.nvim": { "branch": "main", "commit": "3a93300c076109d86c7ce35ec67a8034ae6ba9db" }, + "friendly-snippets": { "branch": "main", "commit": "69a2c1675b66e002799f5eef803b87a12f593049" }, "gitsigns.nvim": { "branch": "main", "commit": "4aaacbf5e5e2218fd05eb75703fe9e0f85335803" }, "harpoon": { "branch": "harpoon2", "commit": "2cd4e03372f7ee5692c8caa220f479ea07970f17" }, "helpful.vim": { "branch": "master", "commit": "d996027ea940916f8f7e55008e9a90810f1a9bfe" },
M lua/plugins/completion.lua

@@ -32,6 +32,7 @@ "hrsh7th/nvim-cmp",

event = "InsertEnter", dependencies = { "hrsh7th/cmp-buffer", + "saadparwaiz1/cmp_luasnip", "hrsh7th/cmp-path", "hrsh7th/cmp-nvim-lsp", { "zbirenbaum/copilot-cmp", dependencies = "copilot.lua" },

@@ -39,10 +40,11 @@ },

config = function() local cmp = require "cmp" local cmp_autopairs = require "nvim-autopairs.completion.cmp" + local luasnip = require "luasnip" cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) cmp.setup.filetype({ "gitcommit", "NeogitCommitMessage" }, { - sources = { { name = "buffer" } }, + sources = { { name = "buffer" }, { name = "luasnip" } }, }) require("copilot_cmp").setup()

@@ -50,7 +52,7 @@

cmp.setup { snippet = { expand = function(args) - vim.snippet.expand(args.body) + luasnip.lsp_expand(args.body) end, }, window = {},

@@ -101,6 +103,9 @@ },

["<Tab>"] = function(fallback) if cmp.visible() then cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + -- stylua: ignore + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "") else fallback() end

@@ -108,6 +113,9 @@ end,

["<S-Tab>"] = function(fallback) if cmp.visible() then cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + -- stylua: ignore + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "") else fallback() end

@@ -117,6 +125,7 @@ sources = cmp.config.sources {

{ name = "copilot", group_index = 2, max_item_count = 3 }, { name = "nvim_lsp", max_item_count = 12 }, { name = "buffer", max_item_count = 4 }, + { name = "luasnip", max_item_count = 3 }, { name = "path", max_item_count = 2 }, }, experimental = { ghost_text = true },
A lua/plugins/luasnip.lua

@@ -0,0 +1,50 @@

+return { + "L3MON4D3/LuaSnip", + dependencies = { "rafamadriz/friendly-snippets" }, + keys = { + { + "<C-l>", + function() + local ls = require "luasnip" + if ls.choice_active() then + ls.change_choice(1) + elseif ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, + mode = { "s", "i" }, + }, + }, + config = function() + local ls = require "luasnip" + local types = require "luasnip.util.types" + local fmt = require("luasnip.extras.fmt").fmt + local extras = require "luasnip.extras" + + ls.config.set_config { + history = false, + region_check_events = "CursorMoved,CursorHold,InsertEnter", + delete_check_events = "InsertLeave", + snip_env = { + fmt = fmt, + rep = extras.rep, + m = extras.match, + l = extras.lamda, + s = ls.snippet, + t = ls.text_node, + f = ls.function_node, + c = ls.choice_node, + d = ls.dynamic_node, + i = ls.insert_node, + }, + -- stylua: ignore + ext_opts = { + [types.choiceNode] = { passive = { virt_text = { { "●", "Operator" } }, hl_group = "LuaSnipChoiceNode", }, }, + [types.insertNode] = { active = { virt_text = { { "●", "Type" } }, hl_group = "LuaSnipInsertNode", }, }, + }, + } + + require("luasnip.loaders.from_lua").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load() + end, +}