Repository navigation
Description
Hello, findFiles's exclude argument says that if you pass in undefined, default excludes will apply.
I have found this to not work in my extension despite my configuration being correct. Consider this piece of code:
const files = await workspace.findFiles('**/*.md'); // https://github.com/Microsoft/vscode/issues/47645
// TODO: Figure out https://github.com/Microsoft/vscode/issues/48674
console.log(workspace.getConfiguration('search.exclude'));
for (const file of files) {
console.log(file.fsPath);
}Above, workspace.getConfiguration('search.exclude') returns:
{
"**/node_modules": true,
"**/bower_components": true
}This is merged from the default settings, I never change this configuration section.
Despite that, the workspace.findFiles('**/*.md') (with or without undefined explicitly passed as a 2nd argument, shouldn't make a difference unless some weird parameter counting is going on) returns MarkDown files from my node_modules directory.
I do not know how to run extension debugging in a "none but this extension" mode, but I installed a published version of my extension and tried installing it alone in my Insiders instance and was able to reproduce the problem.
I am using VS Code 1.22.2 and VS Code Insiders 1.23.0-insider`.
Is there anything else I can do to debug this further?
Activity
roblourens commentedon Apr 26, 2018
This uses
files.exclude, but notsearch.exclude. Johannes Rieken (@jrieken) maybe docs should mention this?TomasHubelbauer commentedon Apr 26, 2018
Indeed in my case
console.log(workspace.getConfiguration('files.exclude'))returns (the default):{ "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true }How can I turn the return value of
workspace.getConfiguration('search.exclude')into somethingfindFileswill accept? I came up with this:This feels hardly optimal. If there is a better way to do this, please, let me know, I'd much rather use something built-in if there's anything. I also tried merging the patterns into something like
**/*.md, !**/node_modulesor**/*.md; !**/node_modules, but that crashes on an invalid use of a glob**pattern.roblourens commentedon Apr 27, 2018
You can combine multiple patterns into a single one by comma-separating inside {}. #38545
You can't combine include and exclude with !
And one thing to watch out for is that the exclude settings can have sibling patterns as their values, rather than
true.For example,
And the findFiles interface doesn't support those. So you would want to think about how you want to handle that.
TomasHubelbauer commentedon May 7, 2018
roblourens Can you please reopen this as a feature request for a better API for
findFileswith a simple way of telling it to useexcludesfromgetConfiguration?chrmarti commentedon May 31, 2018
This would also be helpful in our own code: b845ce9
roblourens commentedon Sep 13, 2018
After #34711, workspaceContains patterns respect
search.exclude. Quickopen does too. So I feel likefindFilesshould as well. But since it's a breaking change, I think it will be hard to do...TomasHubelbauer commentedon Sep 13, 2018
Could that be resolved by adding a new optional flag to it that would toggle this behavior on? Obviously I'd love to see it be the default behavior for this, so if it is possible to survey extension authors and assess the impact, it would be cool to take on a BC, but if that's not feasible, a flag could be an alternative.
TomasHubelbauer commentedon Sep 19, 2018
Here's an updated snippet which will return URIs of workspace files except for those ignored either by
search.excludeorfiles.excludeor.gitignore:I would much rather VS Code extension API provided this out of the box, but alas. I am noticing some new development like
FileSearchProviderwhich natively allows ignoring Git ignored files, but it doesn't seem like this will trickle down to the good ol'findFilesanytime soon.Thus the code above should be the best we have for now unless there is some way to use the Git extension API to query the ignored-or-not status of a URI without using
exec.João Moreno (@joaomoreno) is this API usable from other extensions or is that something internal to only VS Code? If it is, can you give an example of how an extension author could make use of it? I wasn't able to find anything on the topic.
joaomoreno commentedon Sep 20, 2018
Here's the API: https://github.com/Microsoft/vscode/blob/master/extensions/git/src/api/git.d.ts
Here's usage example: https://github.com/Microsoft/vscode-pull-request-github/blob/master/src/extension.ts#L53
It is still pioneering work, so there's no official documentation yet. We also do not yet expose the ignored status for files. Tho we could. Feel free to file an feature request issue for it.
roblourens commentedon Sep 20, 2018
At some point we may want a
findFiles2that takes an options object likefindTextInFilesinstead of a list of params. Exposing the useIgnoreFiles option makes sense for findFiles, it's exposed on findTextInFiles.20 remaining items
andreamah commentedon Feb 9, 2024
I recently introduced a new
FindFiles2API, which is currently proposed. The work is tracked here #204657. Please try it out and let me know if there is anything missing!phil294 commentedon Jun 11, 2024
Just tried it Andrea Mah (@andreamah) and it works great! Being able to exclude gitignored files is a HUGE help. Looking forward to getting this officially shipped with mainline VSCode!
For now, I've written a fallback that first scans the workspace for
.gitignorefiles, reads and parses them and then adds those to the custom exclude string forfindFiles()(v1). I have found this to be much faster than querying forgit check-indexlike Tomáš Hübelbauer (@TomasHubelbauer) did (thanks for sharing), albeit probably some complicated patterns might not be translated perfectly. Some translation is necessary after all, the syntax differs between Git ignores and VSCode globs significantly. Altogether it's still much slower thanfindFiles2().https://github.com/phil294/search-plus-plus-vscode-extension/blob/e11a223b1a0ead7f177b56b1712b2aaed36d6335/src/extension.js#L181-L241
andreamah commentedon Jul 16, 2024
Some news: in case you missed it, I'm finalizing the
FindFiles2(which will become an overload ofworkspace.FindFiles) API with some other related APIs. You can see the status (plus a diagram) here. Since they're so intertwined, I felt that it made the most sense to me to address all the APIs as a group.andreamah commentedon Jul 26, 2024
The (mostly-finalized-but-still-under-discussion) revamped API shape for this is now available in this file.
It will eventually have the
Newmentions removed when it gets merged with the existing proposed API. Then, once it becomes an overload ofworkspace.findFiles, it will just be called usingworkspace.findFiles(but with different args than the existing call).phil294 commentedon Jul 28, 2024
Andrea Mah (@andreamah) this looks great, but I have one question about
useIgnoreFiles: It saysbut that was never the case before, so isn't this about to become a breaking change? (depending on what and when this "May" will apply)
Not that it affects me, just curious☺️
andreamah commentedon Jul 29, 2024
This will just be an alternative call for
workspace.findFiles, but the old one will still work and be valid.phil294 commentedon Oct 5, 2025
Hello Osvaldo Ortega (@osortega), since you seem to have taken over this topic: Do you have any estimation on when the new
findFiles2will be finalized?