Skip to content

Snippets: Scope by specific file or pattern #75955

@brpaz

Description

@brpaz

Global snippets already support being scoped by language and language file snippets are naturally scoped. I would like to expand that "scoping" logic to specific files by matching the filename, for example.

A good use case for this, let's say I want to create snippets for travis.yml file. Right now what I do is to create the snippet scoped to YAML language.

The problem is that it will appear for every YAML file which will pollute the autocomplete with not very useful results if you have snippets for multiple kinds of files that have the same extension. (I don't want to see "travis" related snippets in a "gitlab-ci.yml" file for example) as they are not applicable.

I think this is most critical for configuration files where they have a very specific scope and that you can easily restrict by looking at the filename.

Going further, we could even expand this concept for other kinds of snippets. For example, I can have some project level snippets for building queries and I only want to enable them, in Repository classes and not in Controller classes. You could scope the files it applies using a regex pattern, for example.

I guess this shouldn't be very hard to do and it would vastly improve the suggestions quality of the snippets.

I see adding a new field similar to "scope" called "context" or something where you can specify a regex that will match to the filename.

Metadata

Metadata

Labels

feature-requestRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunitiesinsiders-releasedPatch has been released in VS Code Insiderssnippets

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions