Skip to content

Conversation

@stefanboca
Copy link
Collaborator

This can be used with eg.

filter_snippets = function(ft, file)
  return not (string.match(file, "friendly.snippets") and string.match(file, "framework"))
end,

to disable friendly-snippets frameworks.

Closes #291

Also removes the ignored_filetypes option, which is redundant now that users can filter snippets with more control.

…pet files

This can be used with eg.
```lua
filter_snippets = function(ft, file)
  return not (string.match(file, "friendly.snippets") and string.match(file, "framework"))
end,
```
to disable friendly-snippets frameworks.

Closes saghen#291
This is redundant now that users can filter snippets with more control.
@stefanboca stefanboca added the snippets Built-in provider and library for snippets label Jan 12, 2025
@saghen saghen merged commit 996aba4 into saghen:main Jan 12, 2025
3 checks passed
@saghen
Copy link
Owner

saghen commented Jan 12, 2025

Long term I think we should move the settings for the registry into the top level snippets (maybe under snippets.registry), and make the snippets source options generic to all snippet providers (luasnip, mini.snippets, default). Just something to think about

@stefanboca stefanboca deleted the sb/push-mkzzozoyonst branch January 12, 2025 16:48
@GeoDaoyu
Copy link

This can be used with eg.

filter_snippets = function(ft, file)
  return not (string.match(file, "friendly.snippets") and string.match(file, "framework"))
end,

to disable friendly-snippets frameworks.

Closes #291

Also removes the ignored_filetypes option, which is redundant now that users can filter snippets with more control.

Thanks for your feature~
Where should I write [filter_snippets] config? and there is a not used 'ft'?
I try to set filter_snippets under snippets,such as follow, but it throw error on config.

      snippets = {
        preset = "luasnip",
        filter_snippets = function(_, file)
          return not (string.match(file, "friendly.snippets") and string.match(file, "framework"))
        end,
      },

@stefanboca
Copy link
Collaborator Author

filter_snippets should be in snippets.opts:

providers = {
  snippets = {
    opts = {
      filter_snippets = function(ft, file)
        return not (string.match(file, "friendly.snippets") and string.match(file, "framework"))
      end,
    },
  },
}

You're right that there is a ft parameter (filetype) that is unused in this example, in order to allow disable snippets based on filetype. For instance, you could write

filter_snippets = function(ft, file)
  return ft == "rust" or not (string.match(file, "friendly.snippets") and string.match(file, "framework"))
end,

in order to disable friendly-snippet frameworks, except for in rust.

@sneha-afk
Copy link
Contributor

@stefanboca Could you update the documentation since there are still references to ignored_filetypes, I was stuck until I found your PR. Thank you so much for this feature!

@noidilin
Copy link

It also takes me some time to find this thread.

Here is a use case that

  • disable only javascript snippet from friendly-snippet
  • when the file extension is js, ts, jsx, tsx
  • but keep other snippet from friendly-snippet alive (e.g global.json snippet)
snippet config
sources = {
  providers = {
    snippets = {
      opts = {
        -- disable friendly-snippet frameworks, except for in rust.
        filter_snippets = function(ft, file)
          local disabled_fts = {
            javascript = true,
            javascriptreact = true, -- .jsx
            typescript = true,
            typescriptreact = true, -- .tsx
          }

          -- check if the snippet file path contains 'friendly-snippet' or 'javascript'
          if
            disabled_fts[ft]
            and string.match(file, "friendly.snippets")
            and string.match(file, "javascript")
          then
            return false
          end

          -- allow everything else by default
          return true
        end,
      },
    },
  },
},

The snippet file path can be referenced from friendly-snippet repo.
Hope this example shed some light on the usage of filter_snippets to other people.

noidilin added a commit to noidilin/nvim that referenced this pull request Oct 13, 2025
thanks to: [feat(snippets.default): filter_snippets function for
disabling certain snippet files by stefanboca  Pull Request #996
Saghen/blink.cmp](saghen/blink.cmp#996)
ada4a added a commit to ada4a/lazyvim that referenced this pull request Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snippets Built-in provider and library for snippets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow selectively enabling friendly-snippets frameworks

5 participants