saadparwaiz1/cmp_luasnip

Python open or closing parenthesis same 3 snippets

argapost opened this issue · 14 comments

Hello I just re-post here the issue: L3MON4D3/LuaSnip#179

When I open or close parenthesis in python I get the following 3 snippets no matter the function:

image

Can I disable them somehow? I don't think I had the same problem a couple of days ago.

Thank you in advance.

ah I see. I'm assuming you use LunarVim or something similar. try rolling it back a few commits to see if it solves the issues. I'll add the ability to disable snippets over the weekend

Thanks for the answer!

Yeap I use LunarVim. Should I roll back the cmp_luasnip or LunarVim itself?
Perfect disabling snippets would be helpful. But should those snippets appear every time I open or close parenthesis?

try the new commit out and set the snippet you want to disable as nil in the table and it should work. I'll try to investigate why are they getting triggired by parenthesis

Probably because it's their trigger, see here.
Tbh that's a pretty bad choice for a trigger, maybe friendly-snippets will accept a patch to those.

I was thinking maybe nvim-cmp has an option to not fuzzy match. I'll look into the config to see if that works. If it doesn't then yeah best thing would be to do a pull request for friendly-snippets

Ok now I understand cmp fuzzy match the parenthesis inside the prefix of the snippets that's why I always get these 3 when I open/close paranethesis. But is this a new feat. cause I don't remember having this problem before and the friendly-snippets for python are a couple of months old.

@saadparwaiz1 I PackerSync to download the latest version from cmp_luasnip but I am not sure how can I disable a single snippet. I tried luasnip.snippets.python[66] = nil but it doesn't work.

Weird that it setting it to nil doesn't work. I'll look into it :)

I am facing the exact same issue and as pointed out by @argapost this started happening a week back I guess. I am neovim stable and have seen the issue in neovim nightly as well.
The other challenge is that this affecting the signature pop ups as well as shown.(neovim stable)
Its making it luasnip unusable. Just wanted the signature pop up as before

image

You could do a git bisect to find the commit that introduced the error, but tbh I think everything is working as intended

  • there's a snippet with ( and ) in the trigger
  • it's submitted to completion
  • it is fuzzy-found by nvim-cmp and the completion menu is populated

IMO there's a few solutions:

  • turn off autocompletion, trigger it manually
  • remove the offending snippets from the json
  • blacklist the snippets while loading(would have to be implemented, but I'm honestly a bit hesitant to do that as the same can be achieved by removing the snippets that should be blacklisted from the source-json)
  • (set the snippets to nil before nvim-cmp is loaded, but that's hacky and not really possible with lazy-loaded snippets)

I have tested vim-vsnip as well and the same three offending show up. Maybe try making an issue on friendly-snippets to see if they are fine with fixing these?

Yeap just did.

@argapost with the latest commit you can override the refresh function to block out any snippets you want; here's an example:

local source = require('cmp_luasnip')
local refresh = source.refresh
source.refresh = function()
     local ft = require('luasnip.session').latest_load_ft
     if ft == 'python' then
          require('luasnip').snippets.python[66] = nil
    end
    refresh()
end

Thanks for that but it seems that every time the index of corresponding snippet changes. I print this:

  local snips = require("luasnip").snippets.python
  
  for k, v in pairs(snips) do
      print(k, v.name)
  end

and it is different every time I open a python file. So what I ended up doing is inside the for loop of the snippets I check if the name equals the one I want and I set the corresponding index to nil. If you have a more elegant solution I would be happy to implement.

for k, v in pairs(snips) do
  if v.name == "def(static class method)" then
        require("luasnip").snippets.python[k] = nil
  end
end

@argapost My Preference would still be changing the json file but glad this worked!