Context: Trying to answer the additional bounty question by @gremo:
TL;DR
This is due to full path
vs filename
matching behavior based on presence of /
. The same is obscurely mentioned in VSCode
docs as well. Read on for details.
Details:
As requested by @gremo, quoting from following reputable source:
Language Support in Visual Studio Code
Note that the pattern is a glob pattern that will match on the full
path of the file if it contains a / and will match on the file name
otherwise.
Read closely and you'll see the word full path of the file
and file name
stand out!
i.e. from above we can infer that depending on existence of /
it will decide match mode/behavior of full path match
vs partial/filename match
!
This further makes more sense when we see that relative
paths are not yet allowed, as mentioned at issue #12805 Allow workspace relative files.associations setting posted by @Bob_ in his answer.
Hopefully above sheds light on:
Why pattern somefolder/*.txt
doesn't match?
since there is a /
in pattern, this will do a full path
matching
in our case full path of loaded files will be: c:\scratch\VsCodePatternTest\somefolder\foo.txt
and c:\scratch\VsCodePatternTest\foo.txt
so we're essentially trying to match above full path
to pattern: somefolder/*.txt
Result: Neither matched!
Note: Technically this path will NEVER match anything, since on Windows/Linux/Mac
u can't have an absolute path like above..
it needs to be rooted somehow:
E.g. on Windows:
c:/somefolder (or use `\\` for back slashes on windows)
on Linux/Mac:
/somefolder
Why pattern **/somefolder/*.txt
match?
now again since there is a /
in pattern, this will do a full path
matching
like above again the full path of loaded files will be: c:\scratch\VsCodePatternTest\somefolder\foo.txt
and c:\scratch\VsCodePatternTest\foo.txt
so we're essentially trying to match above full path
to pattern: **/somefolder/*.txt
Result: Only one file match!
Bonus: Why pattern foo.txt
match?
now this time since there is NO /
in pattern, this will do filename
matching
like above again the full path of loaded files will be: c:\scratch\VsCodePatternTest\somefolder\foo.txt
and c:\scratch\VsCodePatternTest\foo.txt
so we're essentially trying to match above filename
i.e. foo.txt
and foo.txt
to pattern: foo.txt
Result: Both files match!
Tested above cases with:
Version/OS:
VSCode 1.78.1 on Windows 10 x64
Project/Workspace structure:
c:\scratch\VsCodePatternTest
\.vscode
settings.json
\foo.txt
\somefolder
\foo.txt
Hope this clears things up!