You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
localroot=vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .reprofor_, nameinipairs({ "config", "data", "state", "cache" }) dovim.env[("XDG_%s_HOME"):format(name:upper())] =root.."/" ..nameend-- bootstrap lazylocallazypath=root.."/plugins/lazy.nvim"ifnotvim.loop.fs_stat(lazypath) thenvim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
endvim.opt.runtimepath:prepend(lazypath)
-- install pluginslocalplugins= {
-- do not remove the colorscheme!"folke/tokyonight.nvim",
"neovim/nvim-lspconfig",
{
"hrsh7th/nvim-cmp",
lazy=false,
dependencies= {
"hrsh7th/cmp-nvim-lsp",
},
config=function(_, opts)
localcmp=require("cmp")
require("cmp").setup({
mapping=cmp.mapping.preset.insert({
["<cr>"] =cmp.mapping(function(fallback)
ifcmp.visible() thencmp.confirm()
endend, { "i", "c", "s" }),
}),
completion= {
completeopt="menu,menuone,noinsert",
},
snippet= {
expand=function(args)
localinsert=MiniSnippets.config.expand.insertorMiniSnippets.default_insertinsert({ body=args.body })
end,
},
sources=require("cmp").config.sources({
{ name="nvim_lsp" },
}, {}),
})
end,
},
{
"echasnovski/mini.snippets",
version=false,
config=function()
localgen_loader=require("mini.snippets").gen_loaderrequire("mini.snippets").setup({
snippets= {
-- Load custom file with global snippets first (adjust for Windows)gen_loader.from_file("~/.config/nvim/snippets/global.json"),
-- Load snippets based on current language by reading files from-- "snippets/" subdirectories from 'runtimepath' directories.gen_loader.from_lang(),
},
})
end,
},
-- add any other pugins here
}
require("lazy").setup(plugins, {
root=root.."/plugins",
})
require("lspconfig").lua_ls.setup({
settings= {
capabilities=require("cmp_nvim_lsp").default_capabilities(),
Lua= {
runtime= {
version="LuaJIT",
},
workspace= {
library= {
"/usr/local/share/nvim/runtime",
},
},
completion= {
callSnippet="Replace",
},
},
},
})
vim.cmd([[colorscheme tokyonight]])
Description
Some chars are swallowed when expanding:
typing sequence : vim.sc<cr>fun<cr> result in right pair missing;
typing sequence : vim.sc<cr><cr> has correct result,
typing sequence : vim.schedule()<left>fun<cr> has correct result,
iShot_2024-12-24_08.10.18.mp4
I debug to find cmp removing the pair before snippet expanding, needs more investment.
The whole process is following, | stands for cursor:
type vim.sc<cr> expanding to vim.schedule(|fn)
lua_ls interprets it as if user types vim.schedule(fn) suggesting fun as a snippet completion item
user continues typing fun, completion item stays unchanged, but cmp knows before expanding the snippets, it needs to clear the fun typed by user, to let snippet engine expand correctly.
user types <cr>, cmp turn vim.schedule(fun) to vim.schedule() correctly, BUT, it calls vim.lsp.util.apply_text_edits before expanding, while the TextEdit looks like this:
cmp stage before { "vim.schedule()" } -- This is before apply text edit
function#function#if completion_item.textEdit: {
_index = 1,
newText = "",
range = {
["end"] = {
character = 15,
line = 765
},
start = {
character = 13,
line = 765
}
}
}
cmp stage after { "vim.schedule(" } -- This is after appying
notice the range is [13,15) which stands for fn in the original placeholder.
vim.snippet.expand works correctly because it stays in select mode, does not trigger completion at all, only after user typing fun lua_ls will begin to send correct TextEdits, anyway, by that time placeholder is already gone.
To my understanding, the fix would be suspending completion request to stop step 2 from firing when first expanding.
Steps to reproduce
above
Expected behavior
no outdated completion item
Actual behavior
outdated completion item swallows ')'
Additional context
No response
The text was updated successfully, but these errors were encountered:
FAQ
Announcement
Minimal reproducible full config
repro.lua, run with
nvim -u repro.lua
Description
Some chars are swallowed when expanding:
typing sequence :
vim.sc<cr>fun<cr>
result in right pair missing;typing sequence :
vim.sc<cr><cr>
has correct result,typing sequence :
vim.schedule()<left>fun<cr>
has correct result,iShot_2024-12-24_08.10.18.mp4
I debug to find cmp removing the pair before snippet expanding, needs more investment.
The whole process is following,
|
stands for cursor:vim.sc<cr>
expanding tovim.schedule(|fn)
vim.schedule(fn)
suggestingfun
as a snippet completion itemfun
, completion item stays unchanged, but cmp knows before expanding the snippets, it needs to clear thefun
typed by user, to let snippet engine expand correctly.<cr>
, cmp turnvim.schedule(fun)
tovim.schedule()
correctly, BUT, it calls vim.lsp.util.apply_text_edits before expanding, while the TextEdit looks like this:notice the range is [13,15) which stands for
fn
in the original placeholder.vim.snippet.expand
works correctly because it stays in select mode, does not trigger completion at all, only after user typingfun
lua_ls will begin to send correct TextEdits, anyway, by that time placeholder is already gone.To my understanding, the fix would be suspending completion request to stop step 2 from firing when first expanding.
Steps to reproduce
above
Expected behavior
no outdated completion item
Actual behavior
outdated completion item swallows ')'
Additional context
No response
The text was updated successfully, but these errors were encountered: