LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

LSP + LuaSnip / Friendly-Snippets multiple popups

Open feekApp opened this issue 3 years ago • 7 comments

Hi, I stumbled upon the following issue, using nvim-cmp, LuaSnip and friendly snippets.

For scss and using for example 'dis' for 'display' [snippet], and letting expand the friendliest snippet I get the following popup: img. As you can see, there is a 'cmp' popup as well a LSP popup. The snip popup is generated by this code.

img

As you can see in the gif above, after pressing <C> first the LuaSnip PopUp appears and shortly after that, the LSP PopUp overlaps the LuaSnip PopUP.

How do I prevent the LSP popup and only use the Lua Snip selection popup on pressing <CR>?

== Feek

feekApp avatar Jul 12 '22 04:07 feekApp

Hey :) Sounds like you'll have to dynamically turn off cmp's autocompletion, take a look at cmps github, maybe there already are instructions on how to do this.

L3MON4D3 avatar Jul 12 '22 06:07 L3MON4D3

HI @L3MON4D3, I already expected some like that, but on searching no results so far....

It happens also for a Lua Snippet:

ls.parser.parse_snippet(
  {trig = "nice"},
  "nice: ${1|test1,test2,test3,test4,test5|} ${2:edit}"
),

but you only want to disable cmp lsp for an option, like ${1|...} but for ${2} (as "inset mode") you definitely want to keep LSP insertions active (for setting variables).

feekApp avatar Jul 12 '22 07:07 feekApp

hi

Maybe something like this:

enabled = function()
  if luasnip.jumpable() then
    return false
  else
    return true
  end
end

see. But I'am not sure what condition of luasnip I should use luasnip.expand_or_jumpable() ? luasnip.expand_or_jump()

feekApp avatar Jul 12 '22 08:07 feekApp

Hi, when using the following code:

enabled = function()
  if ( luasnip.expand_or_jumpable() and luasnip.choice_active() ) then
    return false
  else
    return true
  end
end

the expanding is almost going as expected. But it seems like choice_active() is only true when the choice is expanded as popup not when the cursor is on the current choice position (before pressing tab to expand the choice).

So is there a condition combinations that's return true for entering the choice position?

feekApp avatar Jul 12 '22 11:07 feekApp

Ahh, you could just set some global boolean when the choice-window is opened (set in choice_popup, unset in choice_popup_close) and check it in enabled

L3MON4D3 avatar Jul 12 '22 12:07 L3MON4D3

Hi @L3MON4D3 , thnx again for the prompt reply..... I'am quite new in the vim and lua world, so sorry for being a 'noob' .

No I do not think so, that will do the trick because the LSP is triggered before the choice popup is opened. I'am looking for a kind of "on_choice" (before activate choice).

Ad how do I set a global variable inside the choice_popup?

feekApp avatar Jul 12 '22 12:07 feekApp

I'am quite new in the vim and lua world, so sorry for being a 'noob' .

No worries about that, it's pretty rough to get up to speed

Normally, the choiceNode-popup should open immediately after jumping to the choiceNode, I'd be stumped if it doesn't. Maybe the currently open cmp-window has to be closed too, there's probably some api-call to do so.

I'am looking for a kind of "on_choice" (before activate choice).

Take a look here, that's also how the choiceNode-popup works.

Ad how do I set a global variable inside the choice_popup?

Oh, just

my_global_var = "global value"

(eg. just omit the local from the variable-declaration)

L3MON4D3 avatar Jul 12 '22 14:07 L3MON4D3