microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.16k stars 29.28k forks source link

Exclude all files except for... #869

Open TheColorRed opened 8 years ago

TheColorRed commented 8 years ago

The files exclude allows you to set true/false values, but it doesn't seem to take them completely into account.

For example, I would like to hide everything except for the scripts folder. You might then assume that this would do this:

{
    "files.exclude":
    {
        "**/*": true,
        "**/Scripts": false
    }
}

It does not do that, it just hides everything. In order to achieve this, you must list every file and directory except for the Scripts directory, and who knows how many directories there are and if a new directory/file gets added you then must edit the list to exclude those.

In the end, their should be a way to hide everything except for xxx.

Reflyer823 commented 4 years ago

Can't believe that this issue has been proposed for nearly five years and this problem still exists in the latest version of VSCode today. Hope this problem can be solved soon.

sanbox-irl commented 4 years ago

lol buddy, they make this for free. the workarounds exist. get that entitled attitude out of here

CharlesWinter commented 4 years ago

This issue is old enough to start school!

On Tue, 15 Sep 2020 at 07:54, Jonathan Spira notifications@github.com wrote:

lol buddy, they make this for free. the workarounds exist. get that entitled attitude out of here

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode/issues/869#issuecomment-692506940, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFHP5WSVTCELQ7HN3FVPOOTSF4FSZANCNFSM4BVRPSSQ .

ladas-larry commented 4 years ago

@sanbox-irl well, this issue fits well the project goals for this year https://github.com/microsoft/vscode/wiki/Roadmap#themes so it's not bad to raise awareness

kien5436 commented 4 years ago

This shit still exists for now, very annoying. I want to exclude some folders so I have to define:

"files.excludes": {
  "node_modules/folder1": true,
  "node_modules/folder2": true,
  "node_modules/folder3": true,
}

But there are tons of folders. Not only node_modules. Don't understand why they can't handle this

TomaszGasior commented 4 years ago

People, please stop endless complaining! Yep, there is no working solution, only workarounds. Yep, it sucks. But endless complaining does not solve the problem and only causes spam for people subscribed to the topic. If you find this problem as serious and important, just take some time to fix that yourself and then send pull request to the upstream. Don't spam! In other more mature open source projects like GNOME desktop environment this kind of complaints and spam would cause locking the whole thread without any way for discussion. I wonder why Microsoft doesn't locked this issue at all.

Don't spam! Fix the problem and provide solution or wait until someone will do it for you.

AlexBrasileiro commented 3 years ago

I don't know if they already solved it or not, but one option that worked for me was:

"public/*[!images/**]": true

That is, I wanted to hide everything that was inside the public folder, however, to make visible everything that was inside the images folder.

Screen Shot 2020-11-29 at 15 08 38

I hope it helps :)

Reflyer823 commented 3 years ago

I don't know if they already solved it or not, but one option that worked for me was:

"public/*[!images/**]": true

That is, I wanted to hide everything that was inside the public folder, however, to make visible everything that was inside the images folder.

Screen Shot 2020-11-29 at 15 08 38

I hope it helps :)

Thank you very much ! I found it really works for me. And I can even exclude files except for two folders like this: "arch/*[!(arm|mips)]": true I hope it can help others in this issue.

kien5436 commented 3 years ago

@AlexBrasileiro

Not working for me 😞. Don't know how it work.

Before: image

After: image

AlexBrasileiro commented 3 years ago

Hey @shhlkien one way is to use the logic of two ** after the folder you want to keep, in your case:

"client/*[!webpack]**": true

Screen Shot 2020-12-02 at 00 20 04

hope it works :)

AlexBrasileiro commented 3 years ago

I don't know if they already solved it or not, but one option that worked for me was: "public/*[!images/**]": true That is, I wanted to hide everything that was inside the public folder, however, to make visible everything that was inside the images folder. Screen Shot 2020-11-29 at 15 08 38 I hope it helps :)

Thank you very much ! I found it really works for me. And I can even exclude files except for two folders like this: "arch/*[!(arm|mips)]": true I hope it can help others in this issue.

That Cool! One more possibility, thanks for sharing o/

kien5436 commented 3 years ago

Hey @shhlkien one way is to use the logic of two ** after the folder you want to keep, in your case:

"client/*[!webpack]**": true

Screen Shot 2020-12-02 at 00 20 04

hope it works :)

Thank for your help, I tried many combinations but the result still wasn't as expected. In your way, the folder is appear but all files inside it aren't visible.

AlexBrasileiro commented 3 years ago

Hey @shhlkien one way is to use the logic of two ** after the folder you want to keep, in your case: "client/*[!webpack]**": true Screen Shot 2020-12-02 at 00 20 04 hope it works :)

Thank for your help, I tried many combinations but the result still wasn't as expected. In your way, the folder is appear but all files inside it aren't visible.

@shhlkien that's weird! But in your case, just reverse the logic and use to delete the other folders / files like @Reflyer823 sais before...

"client/*[(src|**eslint**)]": true

Screen Shot 2020-12-02 at 11 40 14

hope it works :)

kien5436 commented 3 years ago

Hey @shhlkien one way is to use the logic of two ** after the folder you want to keep, in your case:

"client/*[!webpack]**": true

Screen Shot 2020-12-02 at 00 20 04

hope it works :)

Thank for your help, I tried many combinations but the result still wasn't as expected. In your way, the folder is appear but all files inside it aren't visible.

@shhlkien that's weird! But in your case, just reverse the logic and use to delete the other folders / files like @Reflyer823 sais before...

"client/*[(src|**eslint**)]": true

Screen Shot 2020-12-02 at 11 40 14

hope it works :)

Yeah, it did work. I really appreciate your help. But that the main problem of this issue when we have to work with terrible folders like node_modules, we can't exclude each of them by typing their name until the last things we want to see

Reflyer823 commented 3 years ago

@AlexBrasileiro

Not working for me . Don't know how it work.

Before: image

After: image

After analysing your problem, I found that the pattern doesn't work as we expected and can not fulfill our requirement. The glob pattern client/*[!webpack] means that it will match all the files or folders where the last character of its name is not in the list: {w, e, b, p, a, c, k}. Because here * matches any text, and [!webpack] matches only ONE character that is not given in the bracket. You can see how glob patterns work in glob (programming) - Wikipedia. image image So the folder "src" ends with the letter "c", and it is in this list. Thus it will not be excluded. You will find your problem fixed when you change the pattern to client/*[!k]. This pattern will exclude all the files and folders where the last character of its name is not 'k'. image image But this way doesn't solve all of this issue. Folders like 'pack' still can't be excluded. We still can't exclude all files except for some files.

t0byman commented 3 years ago

I hope this get fixed soon so that this will work:

"search.exclude": { "**/dist": true, "vendor/*[!magento]": true, },

Jothay commented 3 years ago

I found this stack overflow issue and it resolved my need (replicated the equivalent answer here):

https://stackoverflow.com/questions/36646108/visual-studio-code-make-exception-to-files-exclude

I wanted to exclude node_modules except for the bootstrap folder (so I could hunt css classes in the sass). Effectively, you have to spell out the name of the folder to keep. Not sure how this will work with multiple exception folders.

"node_modules": false,
"node_modules/[^b]*": true,
"node_modules/?[^o]*": true,
"node_modules/??[^o]*": true,
"node_modules/???[^t]*": true,
"node_modules/????[^s]*": true,
"node_modules/?????[^t]*": true,
"node_modules/??????[^r]*": true,
"node_modules/???????[^a]*": true,
"node_modules/????????[^p]*": true,

This is ugly as sin, but it does work: Image of Solution

hunterknepshield commented 3 years ago

I was having issues trying to include multiple subdirs, e.g. vendor/foo and vendor/bar, since double nested regexes (e.g. "vendor/{{[^f],?[^o],??[^o]},{[^b],?[^a],??[^r]}}") don't work in this context. Really, I want to keep a much longer list that could be satisfied with just a couple wildcards, but I couldn't find anything that worked well enough with the existing implementation of this setting.

The alternative is of course listing every single dir except those you want to include. I whipped up a quick little shell snippet to handle this, since my directory of interest doesn't change particularly often:

dir_to_exclude=vendor;
subdirs_to_keep=('*foo*' bar);
for subdir in $(ls "$dir_to_exclude"); do
  for keep in "${subdirs_to_keep[@]}"; do
    if [[ "$subdir" == $keep ]]; then # Globs match with ==
      continue 2;
    fi;
  done;
  # Not a dir we want to keep, so print the exclusion rule.
  echo "\"$dir_to_exclude/$subdir\": true,"
done;
t0byman commented 3 years ago

I hope this get fixed soon so that this will work:

"search.exclude": { "**/dist": true, "vendor/*[!magento]": true, },

Finally got this working for me! My vendor folder is in my ignore file and by default vscode doesn't search in ignored folders. So all I had to was to set search.useIgnoreFiles to false.

"search.useIgnoreFiles": false, "search.exclude": { "**/dist": true, "vendor/*[!magento]": true, },

neodon commented 3 years ago

I just ran into the problem described by this issue. I was surprised that setting the value to false for exclude entries does not make an exception to the other entries. Otherwise why have an object for the exclude definitions? Seems like an array of patterns would make more sense. I was also surprised that glob patterns prefixed with ! do not work. Finally, I'm surprised to see this issue was opened in 2015 and doesn't have a resolution.

Thank you for the hard work on VSCode, I still love it! I'll keep waiting patiently for a more expressive way to exclude (with exceptions) files and folders from a workspace. 😸 ❤️

Jaakkonen commented 3 years ago

I have a folder with 100's of folders of which I'm only interested in the ones that contain some word. This would be really helpful feature. Currently doing hack shown in https://github.com/Microsoft/vscode/issues/869#issuecomment-804615384 for about 10 directories is extremely ugly.

infacto commented 3 years ago

How to search.exclude all but src folder? (Include src folder only.)

{
  "**/*": true,
  "!src/**/*": true
}

(not working) I tried a lot but found nothing. Not sure if there is already a solution posted.

nwalker85 commented 3 years ago

Using negated glob patterns with "!" is currently not supported.

Comment from 2015 is still relevant in 2021. The glob pattern "*/.!(git)" should "just work" in my opinion.

thany commented 3 years ago

What is true meant to convery in these settings?

Surely, we should be able to get false to mean the opposite? Kind of really makes sense if that's the opposite...

{
  "ExcludeThis/*": true,
  "ExcludeThis/ButNotThis": false
}

What else would true/false be for on each of these lines??

marcospgp commented 3 years ago

Are there any plans to support this behavior?

Kiekerti commented 3 years ago

Hit me when it became real.

marcospgp commented 3 years ago

Tired of waiting for such a basic feature, jumping into the source code.

I found this section which seems related to negated exclusion paths, though there were a few other results for files.exclude in this repo so I'm not sure if this is where the magic happens:

https://github.com/microsoft/vscode/blob/c15cb13a383dc9ff2dc0828152e374a6b9ecc2b3/src/vs/workbench/contrib/markers/browser/markersFilterOptions.ts#L82

Maybe this has something to do with it? "Do not apply negated filters on resources instead use exclude patterns". Not sure what it means.

https://github.com/microsoft/vscode/blob/ef55a57968e30be8cbe82a2844277550d5c79da4/src/vs/workbench/contrib/markers/browser/markersTreeViewer.ts#L543

Digged down into the refilter() method that seems to get called when the exclusion list gets updated:

https://github.com/microsoft/vscode/blob/4168941deec97e4416493daf844e516740c716b3/src/vs/base/browser/ui/tree/indexTreeModel.ts#L583

Another place that seems worth looking at:

https://github.com/microsoft/vscode/blob/4168941deec97e4416493daf844e516740c716b3/src/vs/workbench/contrib/files/browser/views/explorerViewer.ts#L591

This ResourceGlobMatcher class seems to play an important role as well:

https://github.com/microsoft/vscode/blob/5f3d88ad79fbdad08778620a639b6113e0e677dd/src/vs/workbench/contrib/markers/browser/markersFilterOptions.ts#L14

Though it's in a folder that doesn't look too important. Maybe this is the real deal:

https://github.com/microsoft/vscode/blob/5f3d88ad79fbdad08778620a639b6113e0e677dd/src/vs/workbench/common/resources.ts#L124

And this ResourceGlobMatcher is used in what looks like... the place where we started:

https://github.com/microsoft/vscode/blob/5f3d88ad79fbdad08778620a639b6113e0e677dd/src/vs/workbench/contrib/markers/browser/markersFilterOptions.ts#L100

ThaDaVos commented 3 years ago

Any progress of this? Really wanting this feature too - needing to filter out everything in the vendor folder except our own packages

marcospgp commented 3 years ago

@ThaDaVos I tried looking at the code but got lost 😁 hopefully the developers can get back to us on this 🙂

bphunter1972 commented 3 years ago

It's pretty absurd how long this has taken to implement. Considering the performance boost so many would see if we didn't have to index so many files just to get to the ones we want, I'd have thought this would be a priority.

dgarbs33922 commented 3 years ago

I too would find this feature very helpful! I am interested in setting up a very minimal project that only includes .h and .c files within the directories I've provided in my workspace. I've got build artifacts that are easy to exclude with the existing settings. However, there are quite a few sub-directories with various other file types that I don't particularly care about. It's painful to try to get all of the other file extensions into the exclude list, and the list could evolve over time.

I just ran a quick command to list out all of the file extensions within my project, and I have over 100 unique file extensions. It is not practical to include all of these, when I should just be able to tell the workspace to ignore everything but .c and .h files (or whatever else I want to include).

Spown commented 3 years ago

how about files.include that runs as a second layer after files.exclude?

Griffork commented 2 years ago

Another voice added to the masses!

thany commented 2 years ago

Almost 6 years... Wow.

/edit Yeah, I know right? Please don't thumb-down me for that though, I can't help that some features in vscode take ages and ages and ages...

bingtimren commented 2 years ago

I'm also after this feature, and finally created a VS Code extension to solve this. You can define glob patterns and organize the patterns into "Pockets". Then with just one click, you can add the patterns into "files.exclude" or "pin" the patterns into another explorer (Tidy Explorer). When you pin a pattern, only files matching that pattern is shown in the "Tidy Explorer", sort of achieving "exclude all files except for..." or "include only" feature.

Check out my extension at here: https://marketplace.visualstudio.com/items?itemName=bingtimren.tidy-explorer

bartroozendaal commented 2 years ago

I'm also after this feature, and finally created a VS Code extension to solve this. You can define glob patterns and organize the patterns into "Pockets". Then with just one click, you can add the patterns into "files.exclude" or "pin" the patterns into another explorer (Tidy Explorer). When you pin a pattern, only files matching that pattern is shown in the "Tidy Explorer", sort of achieving "exclude all files except for..." or "include only" feature.

Check out my extension at here: https://marketplace.visualstudio.com/items?itemName=bingtimren.tidy-explorer

I like it, but I want the negated functionality. Based on the selectors, I would want to hide everything apart from the matching files. I created a concept that is taking the files to be shown from a codeowners file in a monorepo. Works fine, but the list of files to exclude becomes so long, it impacts the searching feature in vscode (it cannot handle an extreme long list of excludes). Still in prototyping phase of this extension; not sure if I will push on with it or not.

bingtimren commented 2 years ago

Thanks for trying out my extension.

I like it, but I want the negated functionality. Based on the selectors, I would want to hide everything apart from the matching files.

I thought of the same method - calculating a "files.exclude" to negate some pattern. In the end I concluded that the algorithm would be both too complicated and unreliable. So I end up with this "Tidy Explorer" extension.

My extension cannot achieve the "hide everything apart from the matching files" in the main explorer. However it provides another "tidy explorer" besides the main explorer, and if you pin a pattern (or several patterns), it shows only the matching files in the "tidy explorer". That's as close as "hide everything from the matching files" as I can achieve.

maciejtreder commented 2 years ago

That's not the most elegant way, but you can introduce the following work-around:

Let's say that the file which I want to include is called @myLib, and it resides in the node_modules directory that I want to exclude

        "**/node_modules": false,
        "**/node_modules/.*": true,
        "**/node_modules/[abcdefghijklmnoprstuvxyzqw]*": true, //notice the missing @ in the parenthesis
        "**/node_modules/@[abcdefghijklnoprstuvxyzqw]*": true, //notice the missing m in the parenthesis
        "**/node_modules/@m[abcdefghijklmnoprstuvxzqw]*": true, //notice the missing y in the parenthesis
         //and so on, and so on
geiregjo commented 2 years ago

I lost a few hours of my time not knowing negation in a glob pattern is not supported. I'd love to see this fixed!

Thaina commented 2 years ago

For me using unity3d project I want to use "Library/!(PackageCache)":true, to exclude Library folder but still show PackageCache folder

chrisirhc commented 2 years ago

In case anyone else finds this useful: To exclude all folders except myfolder, you can do exclude {[a-l]*,[n-z]*} as a hack (using the first letter). In most scenarios, you'd probably get some improvements you were seeking.

Shayan-To commented 2 years ago

As a workaround, I crafted this: (I want to exclude Client/* except for Client/data.)

"Client/{[^d]*,?[^a]*,??[^t]*,???[^a]*}": true,
aswinkumar863 commented 2 years ago

As a workaround, I crafted this: (I want to exclude Client/* except for Client/data.)

"Client/{[^d]*,?[^a]*,??[^t]*,???[^a]*}": true,

@Shayan-To Thanks for sharing.

Workaround for multiple folders of same length would be as follows. (To exclude Client/data and Client/json)

 "Client/{[^dj]*,?[^as]*,??[^to]*,???[^an]*}": true,

Is there any workaround for different lengths such as Client/data and Client/css?

Shayan-To commented 2 years ago

@aswinkumar863 This would work fine:

"Client/{[^dc]*,?[^as]*,??[^ts]*,???[^a]*}": true,

BTW, this is a more exact version of my previous pattern: (excluding Client/* but Client/data)

"Client/{[^d]*,d[^a]*,da[^t]*,dat[^a]*,data?*}": true,

And this is a more exact version of your case: (excluding Client/* but Client/data and Client/css)

"Client/{[^dc]*,[dc][^as]*,[dc][as][^ts]*,[dc][as][ts][^a]*,data?*,css?*}": true,

(Though this last one will also include Client/dss and Client/dats!)

YuriScarbaci commented 2 years ago

When using VSCode with unity, this feature would be EXTREMELY useful for almost every scenario... Hopefully this get picked somewhere in the near future!

Based on previously provided workarounds, if you want to ignore all .unity files in all the folders BUT Scenes folder

"{[^S]**,?[^c]**,??[^e]**,???[^n]**,????[^e]**,?????[^s]**}/*.unity":true,

marklnz commented 2 years ago

Kinda shocking that this is still a thing, more than 6 years after the issue was raised, and with this amount of feedback.

GyorgyFerenc commented 2 years ago

Just reminding them, we are still looking forward for this feature!

Dragomir2020 commented 2 years ago

Yes please fix this. Still waiting and have a comment in our team's code for this.

TheNalex commented 2 years ago

Any progress on the fix of this issue? The only solution we have to circumvent this issue is to list EVERY files and folders to hide which is painful and a nightmare to maintain.

bartroozendaal commented 2 years ago

FYI: I’ve created an extension to manage these settings from a code-owners file in a monorepo. It works quite well, and I’m allowed to open source it if anybody is interested. I might need to make it a bit more generic as it might be tailored to our specific set up, but if there’s interest, I might do it.

Bart Roozendaal +31625754345

[MVP_Reconnect_Logo_Blue_Color_CMYK]

From: TheNalex @.> Sent: donderdag 2 juni 2022 11:50 To: microsoft/vscode @.> Cc: Bart Roozendaal @.>; Manual @.> Subject: Re: [microsoft/vscode] Exclude all files except for... (#869)

Any progress on the fix of this issue? The only solution we have to circumvent this issue is to list EVERY files and folders to hide which is painful and a nightmare to maintain.

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/vscode/issues/869#issuecomment-1144667262, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGRYLOJRLGDYFOU7TPI4W43VNB7TNANCNFSM4BVRPSSQ. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>