Repository: LazyVim/LazyVim
File: lua/lazyvim/plugins/extras/coding/mini-snippets.lua (Lua)

Code before:
      --
      -- In order to change opts.snippets, replace the entire table inside your own opts

      local snippets, config_path = require("mini.snippets"), vim.fn.stdpath("config")

      opts.snippets = { -- override opts.snippets provided by extra...
        -- Load custom file with global snippets first (order matters)
        snippets.gen_loader.from_file(config_path .. "/snippets/global.json"),

        -- Load snippets based on current language by reading files from
        -- "snippets/" subdirectories from 'runtimepath' directories.
        snippets.gen_loader.from_lang(), -- this is the default in the extra...
      }
    end,
  },
}

--]]

local function expand(args)
  ---@diagnostic disable-next-line: undefined-global
  local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
  insert({ body = args.body }) -- insert at cursor
end

local snippet_select_for_cmp = function(snippets, insert, opts)
  local cmp = require("cmp")
  if cmp.visible() then
    cmp.close()
  end

  MiniSnippets.default_select(snippets, insert, opts)
end
local snippet_select_for_blink = function(snippets, insert, opts)
  -- Blink's cancel uses vim.schedule!
  require("blink.cmp").cancel()

  -- Schedule, otherwise blink's virtual text is not removed on vim.ui.select
  vim.schedule(function()
    MiniSnippets.default_select(snippets, insert, opts)
  end)
end
local snippet_select_without_completion_engine = function(snippets, insert, opts)
  MiniSnippets.default_select(snippets, insert, opts)
end
local snippet_select = snippet_select_without_completion_engine

return {
  -- disable builtin snippet support
  { "garymjr/nvim-snippets", optional = true, enabled = false },
  -- disable luasnip:

Review comment (suggestion):
`select` step [takes only two `snippets` and `insert` arguments](https://github.com/echasnovski/mini.nvim/blob/733afb94ed88d32b839a644dc137604691e46032/doc/mini-snippets.txt#L626-L631). The third `opts` argument is only present in `default_select()` to be able to adjust its behavior inside custom `expand.select`.

Code after:

          -- Load snippets based on current language by reading files from
          -- "snippets/" subdirectories from 'runtimepath' directories.
          snippets.gen_loader.from_lang(), -- this is the default in the extra...
        }
      end,
    },
  }
--]]
end

local include_in_completion = vim.g.lazyvim_mini_snippets_in_completion == nil
  or vim.g.lazyvim_mini_snippets_in_completion

local function expand_from_lsp(snippet)
  local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
  insert({ body = snippet })
end

local function jump(direction)
  local is_active = MiniSnippets.session.get(false) ~= nil
  if is_active then
    MiniSnippets.session.jump(direction)
    return true
  end
end

---@type fun(snippets, insert) | nil
local expand_select_override = nil

return {
  -- disable builtin snippet support:
  { "garymjr/nvim-snippets", optional = true, enabled = false },
  -- disable luasnip:
  { "L3MON4D3/LuaSnip", optional = true, enabled = false },

  -- add mini.snippets
  desc = "mini.snippets(beta), a plugin to manage and expand snippets (alternative for luasnip)",
  {
    "echasnovski/mini.snippets",
    event = "InsertEnter", -- don't depend on other plugins to load...
    dependencies = "rafamadriz/friendly-snippets",
    opts = function()
      ---@diagnostic disable-next-line: duplicate-set-field
      LazyVim.cmp.actions.snippet_stop = function() end -- by design, <esc> should not stop the session!
      ---@diagnostic disable-next-line: duplicate-set-field
      LazyVim.cmp.actions.snippet_forward = function()
        return jump("next")
      end

      local mini_snippets = require("mini.snippets")