mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
feat: an extra for mini.snippets. Upstream solution in nvim-cmp regarding outdated completion items
This commit is contained in:
parent
ba6364a6ca
commit
741f37f405
1 changed files with 16 additions and 43 deletions
|
|
@ -3,14 +3,6 @@ if lazyvim_docs then
|
|||
-- Motivation: Less clutter in completion windows and a more direct usage of snippits
|
||||
vim.g.lazyvim_mini_snippets_in_completion = true
|
||||
|
||||
-- Using default mini.snippets, completion suggestions might appear directly after inserting a snippet
|
||||
-- This extra prevents that from happening.
|
||||
-- Motivation: A better display of the current snippet.
|
||||
-- Also, those completions do not appear when using luasnip or native snippets
|
||||
--
|
||||
-- Set to `false` to enable completion suggestions directly after inserting a snippet
|
||||
vim.g.lazyvim_mini_snippets_override_expand_insert = true
|
||||
|
||||
-- NOTE: Please also read:
|
||||
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-snippets.md#expand
|
||||
-- :h MiniSnippets-session
|
||||
|
|
@ -45,8 +37,6 @@ end
|
|||
|
||||
local include_in_completion = vim.g.lazyvim_mini_snippets_in_completion == nil
|
||||
or vim.g.lazyvim_mini_snippets_in_completion
|
||||
local override_expand_insert = vim.g.lazyvim_mini_snippets_override_expand_insert == nil
|
||||
or vim.g.lazyvim_mini_snippets_override_expand_insert
|
||||
|
||||
local function expand_from_lsp(snippet)
|
||||
local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
|
||||
|
|
@ -64,9 +54,6 @@ end
|
|||
---@type fun(snippets, insert) | nil
|
||||
local expand_select_override = nil
|
||||
|
||||
---@type fun(snippet) | nil
|
||||
local expand_insert_override = nil
|
||||
|
||||
return {
|
||||
-- disable builtin snippet support:
|
||||
{ "garymjr/nvim-snippets", optional = true, enabled = false },
|
||||
|
|
@ -104,11 +91,6 @@ return {
|
|||
local select = expand_select_override or MiniSnippets.default_select
|
||||
select(snippets, insert)
|
||||
end,
|
||||
insert = function(snippet)
|
||||
-- Prevent completion suggestions directly after snippet insert
|
||||
local insert = expand_insert_override or MiniSnippets.default_insert
|
||||
insert(snippet)
|
||||
end,
|
||||
},
|
||||
}
|
||||
end,
|
||||
|
|
@ -120,31 +102,25 @@ return {
|
|||
optional = true,
|
||||
dependencies = include_in_completion and { "abeldekat/cmp-mini-snippets" } or nil,
|
||||
opts = function(_, opts)
|
||||
if override_expand_insert then
|
||||
expand_insert_override = function(snippet)
|
||||
MiniSnippets.default_insert(snippet)
|
||||
require("cmp.config").set_onetime({ sources = {} })
|
||||
end
|
||||
end
|
||||
local cmp = require("cmp")
|
||||
local cmp_config = require("cmp.config")
|
||||
|
||||
-- stylua: ignore
|
||||
opts.snippet = { expand = function(args) expand_from_lsp(args.body) end }
|
||||
opts.snippet = {
|
||||
expand = function(args)
|
||||
expand_from_lsp(args.body)
|
||||
cmp.resubscribe({ "TextChangedI", "TextChangedP" })
|
||||
cmp_config.set_onetime({ sources = {} })
|
||||
end,
|
||||
}
|
||||
|
||||
-- Return early
|
||||
if include_in_completion then
|
||||
table.insert(opts.sources, { name = "mini_snippets" })
|
||||
return
|
||||
end
|
||||
|
||||
-- Standalone --
|
||||
local function close_cmp()
|
||||
local cmp = require("cmp")
|
||||
-- stylua: ignore
|
||||
if cmp.visible() then cmp.close() end
|
||||
end
|
||||
expand_select_override = function(snippets, insert)
|
||||
close_cmp()
|
||||
MiniSnippets.default_select(snippets, insert)
|
||||
else
|
||||
expand_select_override = function(snippets, insert)
|
||||
-- stylua: ignore
|
||||
if cmp.visible() then cmp.close() end
|
||||
MiniSnippets.default_select(snippets, insert)
|
||||
end
|
||||
end
|
||||
end,
|
||||
-- stylua: ignore
|
||||
|
|
@ -164,12 +140,9 @@ return {
|
|||
end
|
||||
|
||||
-- Standalone --
|
||||
local function close_cmp()
|
||||
require("blink.cmp").cancel()
|
||||
end
|
||||
expand_select_override = function(snippets, insert)
|
||||
-- Schedule, otherwise blink's virtual text is not removed on vim.ui.select
|
||||
close_cmp()
|
||||
require("blink.cmp").cancel()
|
||||
vim.schedule(function()
|
||||
MiniSnippets.default_select(snippets, insert)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue