-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support simple glob patterns for ignore rules #64
Comments
Glob patterns would indeed be useful! There are two ways we could implement them. The simplest approach is to do it in JavaScript, as there are already lots of glob libraries out there. No operating system API supports passing globs directly, so we will have to filter after receiving events anyway. The other way would be to do it in C++. The benefit there would be performance. Since watching occurs on a background thread, we wouldn't overwhelm the JS thread with events that will be ignored anyway. However, implementing glob matching from scratch sounds hard. Perhaps there are some C++ libraries that implement globbing, though I also wouldn't want to bring in a large library if it has the potential for security issues. I suppose we could use Rust for the glob matching... 🤔 Any thoughts on that from your perspective? |
@devongovett unfortunately the JavaScript approach wouldn't be a good solution for VS Code at least: for Linux it is important to apply the ignore rules at the level of where folders are recursively resolved and added to be watched. Since Linux has a natural upper limit of opened file handles, the ignore pattern is the only way for Linux users to avoid hitting that limit (related issue: microsoft/vscode#40898). VS Code is already filtering the events on the receiving end but I would much prefer a native solution in C++ within the watcher. Btw I am not necessarily saying you need full glob support to achieve this. Even VS Code itself implements a simple glob library that supports patterns such as When looking into Maybe that could be used as foundation going forward. |
Together with @bpasero and @lszomoru, I've spend some time figuring out a way forward for this feature request, assuming you'd consider it. As @bpasero already mentioned, today VS Code matches globs at the JS level. Doing that at the C++ level would be ideal for obvious performance reasons. ScenarioLet's consider the classic glob scenario. The user should be able to provide a set of glob patterns, relative to the watched directory. Glob patterns can be positive or negative (starting with Consider the following example:
The following files and directories would match the glob patterns:
The following ones would not:
ImplementationMatching glob patterns against paths is commonly solved by converting glob patterns to regular expressions, eg VS Code, minimatch, etc. We suggest doing the same here. One implementation possibility would be to port VS Code's conversion code to C++, leveraging APIThen, there's the question of API. An option of a set of glob patterns conflicts with the existing We can have both Another solution involves breaking API: drop the Next StepsAsking again, do you still consider glob pattern matching useful? Would you be open to a contribution from our side? What would be your the preferred approach? Do you maybe have other thoughts on the problem and/or approaches? We'd love to hear more from you and help move the Parcel watcher forward as it has provided real value to VS Code since we started using it. |
Thanks for the writeup! I think this would be a great feature for you to contribute. 🥳 In terms of implementation, I like the idea of converting globs to regexes on the JavaScript side and passing them to C++. This only needs to happen once at startup and shouldn't be too expensive performance wise. JS glob libraries are widely used and well tested, and managing C++ dependencies is much more complex, so I think this is a good approach. For the API, another option could be to keep the |
What a fantastic idea to convert from JS to RegEx, I was not even thinking about that. We can then just use our existing code to convert from VSCode 💯 |
Lovely, great idea! I also like the API suggestion, I feel like that's actually the minimal API change we'd need and stays aligned with today's API. Given that, what do you think of directly using |
There is an ECMAScript std::regex flavour which is also the default if not set explicitly in the constructor: https://en.cppreference.com/w/cpp/regex/syntax_option_type |
This is a feature request to enhance the
ignore
option to support simple glob patterns.As an example, I recently came across this PR for
nsfw
that discusses such support for their library: Axosoft/nsfw#124Bottom line: ignore patterns are very important on Linux at least, because of the operating system global limit of opened file handles, so you really need to exclude folders from the file watcher to not run into issues with opening too many file handles. Having support for glob patterns in the ignore option would mean, clients could define a pattern such as
**/node_modules
and have that work regardless of the folder they are in.The text was updated successfully, but these errors were encountered: