LuaSnip
LuaSnip copied to clipboard
When using luasnip buffer confusion
nvim -v
NVIM v0.6.0-dev+181-g5d633546b
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by #@[email protected]
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-5d63354/share/nvim"
Run :checkhealth for more info
https://user-images.githubusercontent.com/16816655/130549127-165bbd2c-2d92-4729-ac42-48d9bc18deab.mov
luasnip config:
local present, luasnip = pcall(require, "luasnip")
if not present then
return
end
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col "." - 1
if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then
return true
else
return false
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif luasnip and luasnip.expand_or_jumpable() then
return t "<Plug>luasnip-expand-or-jump"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn["compe#complete"]()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif luasnip and luasnip.jumpable(-1) then
return t "<Plug>luasnip-jump-prev"
else
return t "<S-Tab>"
end
end
_G.completions = function()
local npairs
if
not pcall(
function()
npairs = require "nvim-autopairs"
end
)
then
return
end
if vim.fn.pumvisible() == 1 then
if vim.fn.complete_info()["selected"] ~= -1 then
return vim.fn["compe#confirm"] "<CR>"
end
end
return npairs.check_break_line_char()
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<CR>", "v:lua.completions()", {expr = true})
luasnip.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI"
}
require("luasnip/loaders/from_vscode").load()
When using luasnip, save at this time, causing the interface to be confusing and cannot be rolled back or deleted
What??? Does this happen with all snippets?
I tried something else, and so far it’s just the Golang for loop that’s the problem @L3MON4D3
No other language has been tried
Okay, could you post the snippet?
Also, try running :LuaSnipUnlinkCurrent before deleting and see if that fixes your issue
"for statement": {
"prefix": "for",
"body": "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}",
"description": "Snippet for a for loop"
},
If it's this one, it works just fine for me. Maybe turn off all other plugins if you have any and see if the issue persists
When I delete this configuration, saving is normal,
luasnip.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI"
}
or Change the configuration as follows, save is also normal
luasnip.config.set_config {
history = true,
updateevents = "InsertLeave"
}
but When I use the snippet for loop, within the for, using tab, I copy three times
https://user-images.githubusercontent.com/16816655/130580644-840584db-a5d0-444b-87ef-6779845b7899.mov
this is my nvim config https://github.com/amistyrain/nvim-lua.config
Oh, I only tried with updateevents=TextChangedI, I'll check again with your exact settings.
Okay I tried with your settings, but I cannot reproduce it :/ Could you disable other plugins until it works with your original config?
also golang for loop?
I used the one from friendly-snippets, im assuming you're talking about that one. If not, please post the snippet so I can try it.
I used the one from
friendly-snippets, im assuming you're talking about that one. If not, please post the snippet so I can try it.
me too
I deleted other plugins, the same problem
Dammit, could you try the snippet in other filetypes eg.
:lua require("luasnip").snippets = {all={require("luasnip").parser.parse_snippet("for", "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}")}} and see if it still misbehaves?
Dammit, could you try the snippet in other filetypes eg.
:lua require("luasnip").snippets = {all={require("luasnip").parser.parse_snippet("for", "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}")}}and see if it still misbehaves?
use :lua require("luasnip").snippets = {all={require("luasnip").parser.parse_snippet("for", "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}")}} Same as before
https://github.com/amistyrain/nvim-lua.config
branch:main use luasnip
branch:dev use vim-vsnip
All other plugins have the same configuration, Dev branch, and there’s nothing wrong with using vim-vsnip
I'm on NVIM v0.6.0-dev+181-g5d633546b (current master), maybe try updating and see if that fixes anything
Do you still experience the issue?
Do you still experience the issue?
yes
Could you post the output of :lua Luasnip_current_nodes[vim.api.nvim_get_current_buf()].parent:dump() directly after expanding the snippet and after jumping?
Could you post the output of
:lua Luasnip_current_nodes[vim.api.nvim_get_current_buf()].parent:dump()directly after expanding the snippet and after jumping?


Okay, the extmarks are getting messed up pretty bad, does the issue also occur if you expand manually?
Okay, the extmarks are getting messed up pretty bad, does the issue also occur if you expand manually?
Occurs after expansion to save
To save
Oh, does it not occur if you just jump to the next node?
the same as video
Am I the only one in this situation? It’s very strange
Seems like it :/ My only explaination would be another plugin interfering.
It’s almost certainly a problem with gofmt, which I format before saving, but I use vim-vsnip, which gofmt is normal
Before formatting, I executed luasnipunlinkcurrent and everything was OK