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
|
-- Motivation: Less clutter in completion windows and a more direct usage of snippits
|
||||||
vim.g.lazyvim_mini_snippets_in_completion = true
|
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:
|
-- NOTE: Please also read:
|
||||||
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-snippets.md#expand
|
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-snippets.md#expand
|
||||||
-- :h MiniSnippets-session
|
-- :h MiniSnippets-session
|
||||||
|
|
@ -45,8 +37,6 @@ end
|
||||||
|
|
||||||
local include_in_completion = vim.g.lazyvim_mini_snippets_in_completion == nil
|
local include_in_completion = vim.g.lazyvim_mini_snippets_in_completion == nil
|
||||||
or vim.g.lazyvim_mini_snippets_in_completion
|
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 function expand_from_lsp(snippet)
|
||||||
local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
|
local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
|
||||||
|
|
@ -64,9 +54,6 @@ end
|
||||||
---@type fun(snippets, insert) | nil
|
---@type fun(snippets, insert) | nil
|
||||||
local expand_select_override = nil
|
local expand_select_override = nil
|
||||||
|
|
||||||
---@type fun(snippet) | nil
|
|
||||||
local expand_insert_override = nil
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
-- disable builtin snippet support:
|
-- disable builtin snippet support:
|
||||||
{ "garymjr/nvim-snippets", optional = true, enabled = false },
|
{ "garymjr/nvim-snippets", optional = true, enabled = false },
|
||||||
|
|
@ -104,11 +91,6 @@ return {
|
||||||
local select = expand_select_override or MiniSnippets.default_select
|
local select = expand_select_override or MiniSnippets.default_select
|
||||||
select(snippets, insert)
|
select(snippets, insert)
|
||||||
end,
|
end,
|
||||||
insert = function(snippet)
|
|
||||||
-- Prevent completion suggestions directly after snippet insert
|
|
||||||
local insert = expand_insert_override or MiniSnippets.default_insert
|
|
||||||
insert(snippet)
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
|
|
@ -120,32 +102,26 @@ return {
|
||||||
optional = true,
|
optional = true,
|
||||||
dependencies = include_in_completion and { "abeldekat/cmp-mini-snippets" } or nil,
|
dependencies = include_in_completion and { "abeldekat/cmp-mini-snippets" } or nil,
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
if override_expand_insert then
|
local cmp = require("cmp")
|
||||||
expand_insert_override = function(snippet)
|
local cmp_config = require("cmp.config")
|
||||||
MiniSnippets.default_insert(snippet)
|
|
||||||
require("cmp.config").set_onetime({ sources = {} })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- stylua: ignore
|
opts.snippet = {
|
||||||
opts.snippet = { expand = function(args) expand_from_lsp(args.body) end }
|
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
|
if include_in_completion then
|
||||||
table.insert(opts.sources, { name = "mini_snippets" })
|
table.insert(opts.sources, { name = "mini_snippets" })
|
||||||
return
|
else
|
||||||
end
|
expand_select_override = function(snippets, insert)
|
||||||
|
|
||||||
-- Standalone --
|
|
||||||
local function close_cmp()
|
|
||||||
local cmp = require("cmp")
|
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
if cmp.visible() then cmp.close() end
|
if cmp.visible() then cmp.close() end
|
||||||
end
|
|
||||||
expand_select_override = function(snippets, insert)
|
|
||||||
close_cmp()
|
|
||||||
MiniSnippets.default_select(snippets, insert)
|
MiniSnippets.default_select(snippets, insert)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
-- counterpart to <tab> defined in cmp.mappings
|
-- counterpart to <tab> defined in cmp.mappings
|
||||||
|
|
@ -164,12 +140,9 @@ return {
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Standalone --
|
-- Standalone --
|
||||||
local function close_cmp()
|
|
||||||
require("blink.cmp").cancel()
|
|
||||||
end
|
|
||||||
expand_select_override = function(snippets, insert)
|
expand_select_override = function(snippets, insert)
|
||||||
-- Schedule, otherwise blink's virtual text is not removed on vim.ui.select
|
-- Schedule, otherwise blink's virtual text is not removed on vim.ui.select
|
||||||
close_cmp()
|
require("blink.cmp").cancel()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
MiniSnippets.default_select(snippets, insert)
|
MiniSnippets.default_select(snippets, insert)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue