friendly-snippets icon indicating copy to clipboard operation
friendly-snippets copied to clipboard

How to overwrite some snippets

Open ArnoldWolfstein opened this issue 3 years ago • 1 comments

Hi there,

How can we overwrite some snippets that come from the repo? E.g. I want to overwrite function prefix in shell snippets. In my custom user shell.json snippet file, I give priority 2000 to my snippet, but it seems it doesn't work.

{
  "function": {
    "prefix": "function",
    "body": "${1:some_name} ()\n{\n\t${0}\n}",
    "description": [
      "Something something\n",
    ]
    "luasnip": {
      "priority": 2000,
      "autotrigger": true
    }
  },
}

ArnoldWolfstein avatar Aug 17 '22 11:08 ArnoldWolfstein

Hey @ArnoldWolfstein any updates on the status of this? (Did you figure anything out / what leads have you looked into/ etc)

Let us know and then we can get more organized on trying to solve the issue

Cheers :sunglasses:

OkelleyDevelopment avatar Sep 14 '22 04:09 OkelleyDevelopment

I finally had a moment to investigate this myself and after testing the snippet myself, I was able to get the snippets to load when I removed the following line:

"autotrigger": true,

Currently this does not seem to handle priority of the snippets, but I will see what I can find in their documentation.

OkelleyDevelopment avatar Oct 12 '22 21:10 OkelleyDevelopment

Fun fact: after closing neovim and coming back to this after dinner. Priority was working :sunglasses:

Note: Still investigating the reason for

"autotrigger": true

causing the snippets to not show. Though, if we set it to false, then it loads just fine :thinking:

OkelleyDevelopment avatar Oct 13 '22 02:10 OkelleyDevelopment

Hello again @ArnoldWolfstein !

Context

I did some digging and after asking here, learned that if you're using nvim-cmp and cmp_luasnip for completions then the snippets will not expand in the completion listing.

However, the snippet still shows via :LuaSnipListAvailable meaning it is being read though the PR for autosnippet support via cmp_luasnip is still under development.

Answer to the original question:

How can we overwrite some snippets that come from the repo? E.g. I want to overwrite function prefix in shell snippets.

Based on my testing, if you are using nvim-cmp and cmp_luasnip then remove the autotrigger line from your custom snippet and it should load in first:

{
  "function": {
    "prefix": "function",
    "body": "${1:some_name} ()\n{\n\t${0}\n}",
    "description": [
      "Something something\n",
    ]
    "luasnip": {
      "priority": 2000
    }
  },
}

I hope this helps clarify things a bit.

I'm going to close this issue, however, if you questions/concerns feel free to reopen this issue or create another one and I will see what I can do to help. :sunglasses:

OkelleyDevelopment avatar Oct 14 '22 03:10 OkelleyDevelopment