Scope selectors are based on the syntax that is used for a file, which is generally done by file extension, but as you noted you can also make a syntax apply based on first_line_match
in a syntax definition as well. It’s just a convention that source code files have a scope that starts with source
and ends with the more common extension of the file type, but this is not always the case. For example, the scope for C# is source.cs
for C#, but Python is source.python
.
The scope
tag in the snippet is matched against the scope at the cursor, so in the general case to constrain a snippet only to a particular type of file you should set the scope
tag in the snippet to the same as the scope
attribute in your syntax definition. You can also use Tools > Developer > Show Scope Name
from the menu to see what the full scope is at the cursor location; the first line in the popup is the scope that describes the file type.
This video has a bunch to say on the particular topic of scopes and how they match.