saadparwaiz1 / cmp_luasnip

luasnip completion source for nvim-cmp
Apache License 2.0
687 stars 32 forks source link

Python open or closing parenthesis same 3 snippets #15

Closed argapost closed 2 years ago

argapost commented 2 years ago

Hello I just re-post here the issue: https://github.com/L3MON4D3/LuaSnip/issues/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.

saadparwaiz1 commented 2 years ago

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

argapost commented 2 years ago

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?

saadparwaiz1 commented 2 years ago

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

L3MON4D3 commented 2 years ago

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.

saadparwaiz1 commented 2 years ago

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

argapost commented 2 years ago

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.

saadparwaiz1 commented 2 years ago

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

Trid-collab commented 2 years ago

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

L3MON4D3 commented 2 years ago

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

IMO there's a few solutions:

saadparwaiz1 commented 2 years ago

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?

argapost commented 2 years ago

Yeap just did.

saadparwaiz1 commented 2 years ago

@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
argapost commented 2 years ago

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
saadparwaiz1 commented 2 years ago

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