Add `!`-prefix parsing to glob util
See original GitHub issueIt’d be potentially useful to have !
as a prefix added to our glob.ts
utils. This could function similarly to how we already handle .gitignore
files in the webworker search here:
- if a file matches a normal line and doesn’t match an
!
-line, exclude it (we do this today) - If it matches both a normal line and a
!
-line, include it - Otherwise, include it (we do this today)
This isn’t quite as powerful as a real.gitignore
as there are only two “layers” of include/exclude, whereas in gitignore
each line introduces a new “layer”, but I believe it would handle the 99% of cases well enough, for instance every example given to-date in https://github.com/microsoft/vscode/issues/869.
To handle the many-layer case requires either:
- migrating to an array to configure
files.exclude
andsearch.exclude
, which is undesirable from a backwards/forwards compatibility perspective - taking care to ensure the existing
*.exclude
objects are handled in a key-order sensitive way, which is potentially undesirable from a JSON/JS object semantics compatibility perspective
cc @bpasero for any and all input on this
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:15 (15 by maintainers)
Top Results From Across the Web
How to add prefix to the starting of an XML element in HCI ...
I am trying to convert a JSON request(coming from External System) to XML(C4C) in HCI. I am using groovy script. My input json...
Read more >Using Tailwind CSS with Angular projects - Nx
To avoid this, you have a couple of options: Add a unique prefix to your Tailwind CSS utility classes. Create unique CSS classes...
Read more >path/filepath - Go Packages
Package filepath implements utility routines for manipulating filename paths ... func Glob(pattern string) (matches []string, err error); func HasPrefix(p, ...
Read more >sbt Reference Manual — Globs
When parsing glob paths, any / characters are automatically converted to \ on windows. ... PathFilter , it will be necessary to add...
Read more >API Reference — GitPython 3.1.30 documentation
This functions calls git interpret-trailers --parse onto the message to extract ... path_prefix – a prefix to be added to the returned paths...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes exactly.
We mostly implement their logic here: https://github.com/microsoft/vscode/blob/2358283d76a0afdf57e60ec2fc76a57b1b0146c7/src/vs/workbench/services/search/common/ignoreFile.ts#L90 but it’d require some significant changes to get that working for excludes, for instance handling filtering specifically directories vs files and following parent pointers differently from how we merge the settings today. Technically we may need to handle ordering as well, but the code above doesn’t, and that wouldn’t really work with our object based model anyways.
Ideally, the following would work:
However that requires some understanding of the ordering that we may not want to rely on, especially given things like settings scope merging.
Absent that, it’d be helpful to have this:
where if a file matches some bare expression and no negated expression, it matches the glob and is included. This way ordering isn’t important, a simple 2 pass approach works. This is actually what we do already in the ignore file parser.
It is somewhat easy to add global negate support for glob, see https://github.com/microsoft/vscode/commit/efa5122689eea38e5c8ca4480f58ae58e97230e6 for a first stab at it.
However, there are a few questions:
splitGlobAware
probably needs to change to account for the leading!
(e.g. change the return type to{ segments: string[]; negated: boolean; }
) [1][1]
Not sure the ripples or adoption cost where it is used, @roblourens in search. Does RipGrep even support these patterns?
[2]
Take this example:
Since glob expressions are basically a
OR
combination of all patterns, the above pattern will match on everything, even though it may look as if this will match every file that is not.js
or.ts
. Not sure how realistic that scenario is though, but wanted to bring it up anyway.