Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jump() doesn't work in select mode/placeholders #1212

Open
DasGandlaf opened this issue Jul 17, 2024 · 4 comments
Open

jump() doesn't work in select mode/placeholders #1212

DasGandlaf opened this issue Jul 17, 2024 · 4 comments

Comments

@DasGandlaf
Copy link

DasGandlaf commented Jul 17, 2024

Hey, thanks for this amazing plugin!

When I have this code:

local ls = require('luasnip')

vim.keymap.set('i', '<tab>', function()
  ls.expand_or_jump()
end)

ls.add_snippets('lua', {
  ls.parser.parse_snippet('foo1', 'foo1($1, $2)'),
  ls.parser.parse_snippet('foo2', 'foo2(${1:one}, ${2:two})'),
}, { key = 'lua' })

vim.keymap.set({"i", "s"}, "<c-n>", function() ls.jump( 1) end, {silent = true, noremap = true})
vim.keymap.set({"i", "s"}, "<c-p>", function() ls.jump(-1) end, {silent = true, noremap = true})

ls.jump() works when using snippet foo1. It doesn't work when using snippet foo2.

When expanding, it selects the placeholder one correctly. But ls.jump() does not work.

When logging session.current_nodes in jump() in luasnip/init.lua it returns {}.

When expanding foo2, session.current_nodes is set to nil (= next_current) in unlink_set_adjacent_as_current_no_log().

What could the problem be?
Thanks!

@pavel-suhakou
Copy link

I also have this issue with vs code snippets ("rafamadriz/friendly-snippets").
Jumps to the first parameter but cannot jump further.

@L3MON4D3
Copy link
Owner

Mhh, the first part of you problem-description sounds like you're just missing the SELECT-keybinding (set via smap or vim.keymap.set({"s", ...}, ...)).
What you observedafter that, with the current_nodes being set to nil happens when the snippet-text is modified in such a way that luasnip can't tell what happened to it, which usually is because the buffer was formatted. Could you disable all formatters, and check what happens?

@DasGandlaf
Copy link
Author

I'm not fully sure what you mean with the select mapping. In the code snippet, I map insert and select mode:

vim.keymap.set({"i", "s"}, "<c-n>", function() ls.jump( 1) end, {silent = true, noremap = true})
vim.keymap.set({"i", "s"}, "<c-p>", function() ls.jump(-1) end, {silent = true, noremap = true})

Do you mean something else?

With regards to the formatting, I do not have any formatting enabled, and when expanding a snippet, the buffer does not get formatted either. So current_nodes is being set to nil even without formatting.

Also I'm not even sure if the problem is with current_nodes, it's just something I found out while trying to find the mistake. It might not have to do anything with the problem, but from my limited knowledge, it seems that it is a problem.

I really appreciate your help!

@L3MON4D3
Copy link
Owner

Ah, I thought you might have used the <Tab>-mapping since that was mapped to ls.expand_or_jump as opposed to just ls.expand
Could you enable logging via ls.log.set_loglevel("info"), produce the issue, and then check your log via ls.log.open()? There should be some information on why the current snippet was unlinked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants