microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.55k stars 28.66k 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.

shaun-cox commented 7 years ago

My example: I would love to create a project-view consisting only of CMakeLists.txt files -- everything else, especially folders that do not contain CMakeLists.txt -- excluded from the file pane. This would make it much easier to navigate and build understanding of the structure without seeing anything distracting.

breathe commented 7 years ago

I would love to have this feature -- sometimes I need to dive into a particular one of my project's node_modules dependencies. I'd really like to mark that package as not excluded and be able to browser the code, set breakpoints, etc with a minimum of fuss... I'm sure this must be a common need ...

adrienharnay commented 7 years ago

Can't believe this issue has been opened for 1 year and a half. The files.exclude config states that it takes a glob, and glob do support the ! pattern.

Anyway, stumbling on this too, this is the kind of details that make VSCode a no-go (for now).

scottpledger commented 7 years ago

Here's a basic patch that adds a "files.include" config to allow you to selectively approve of a restricted set of files/folders. Note that it needs a lot more work before its production ready. add_include_only_ability.patch.txt

ValYouW commented 6 years ago

@Zephir77167 You are so correct with that, every 3-4 months I decide to give "VS Code" a change just to find out it's no good for large scale apps...

asadkn commented 6 years ago

To all those suggesting to use negation or a negative character class (! or ^) have you tested it? In all my tests and from what I saw in source, there seems to be no support for either ! or ^. So all the suggestions made except in this comment will NOT work.

Wish this had at least the limited flexibility of standard glob even if no regex.

CharlesWinter commented 6 years ago

For me at least, the suggestions of @tobia worked well. I wanted to exclude all folders in the github.com folder of my golang project except those I was interested in. Adding the following to my local workspace config was good enough for me.

{
            // Hide all folders expect those beginning with K
        "files.exclude": {
                       "**/github.com/[^K]*": true,
        }
}
csholmq commented 6 years ago

@CharlesWinter I can't get this to work.

    "files.exclude": {
        "**/out/*/*.[^h]": true
    },

Trying to exclude all files except .h files. No dice...

CharlesWinter commented 6 years ago

@csholmq That will most likely be because that regex is looking for files starting with the character h due to the ^. Remove that should give you some more success.

csholmq commented 6 years ago

@CharlesWinter How do you mean? I am expecting the ^ to negate the literal character h and thus match all files except those with the letter h. Am I missing something trivial?

fripSide commented 6 years ago

Why not provide a configure called "file.include" ? #feature request

kerryjiang commented 6 years ago

Actually, this false option doesn't work

"files.exclude": { "node_modules": true, "node_modules/susa": false }

From the intelligence prompt of VSC, it only control if the pattern is enabled.

"files.exclude": { "node_modules": true, "!node_modules/susa": true }

The negative pattern doesn't work either.

Nirmal4G commented 6 years ago

Anyone who is working on this?

Really need this feature!

tonyxiao commented 6 years ago

https://github.com/Microsoft/vscode/issues/869#issuecomment-255660177 how would you hide the js file when either ts or tsx file exist?

ladas-larry commented 6 years ago

Any progress on this?

lonix1 commented 6 years ago

Until this is implemented, has anyone found an extension that does this?

domske commented 6 years ago

In the search tab you can define exclude and include. So exclude true / false is maybe a bit confusing. The value true is only set to have a valid json. Ok, otherwise an array would be a better way to define that. ["firstPath", "anotherPath"]

My suggestion:

{
  "search.exclude": {
    "**": true
  },
  "search.include": {
    "/src": true
  }
}

this allows to only search in src-folder. include > exclude Include should be evaluated after exclude.

To avoid confusion about the boolean value and keep a valid json you can use an array.

{
  "search.exclude": ["**"],
  "search.include": ["/src"]
}

I don't know what's the reason for the object?

jpike88 commented 6 years ago

This is driving me insane. My files.exclude is starting become this long mess, when it could all be achieved in one files.include line. This seriously needs attention!

AlJohri commented 6 years ago

I really need this as well for AWS Lambda's flat package style requirement of putting dependencies right next to your code:

# gitignore all files within apps/<myapp>/src EXCEPT for a single app folder
apps/*/src/*
!apps/*/src/app
fredijude commented 6 years ago

@bpasero : What is the progress with regard to the issue ? There is a lot of conversations regarding the work around for the problem. And seems to me nothing is solving my problem. So, can you please take a look at how you can solve the problem ? Many of developers like me are waiting for an enhancement to specify "everything expect" in files.exclude or another configuration such as files.include.

EZhex1991 commented 5 years ago

This issue has been opened for three years... I tried every method that mentioned above, none of them works...

yvbeek commented 5 years ago

In my scenario I want to hide all files that start with a . but not the .vscode folder. For now I'm using this:

"files.exclude": {
    ".[^v]*": true,
}

Which unfortunately means that I can't use any tools that start with a v 😄

xahon commented 5 years ago

After three years Microsoft still didn't bother to resolve this 2-hour issue. It remains only to close discussion for collaborators and that's all

jamesheazlewood commented 5 years ago

Not only does it not work, there's no way to disable hard-coded exclude entries in Workspace or User, even using "/pattern/": false doesn't work.

A workaround I use is to just use the "files to exclude" and "files to include" in the sidebar search.

mityukov commented 5 years ago

I need Explorer to show only the folders (and all beneath them) matching (against the full path) given pattern& For example, if I type QSL/Backorder, it would only display the following folders:

./classes/XLite/Module/QSL/Backorder/**
./skins/admin/modules/QSL/Backorder/**
./skins/customer/modules/QSL/Backorder/**

And hide all others. Is there anything I can do at the moment to achieve this? Maybe, and extension?

a1300 commented 5 years ago

The following workaround worked for me :heavy_check_mark:

I wanted to exclude /node_modules but include /node_modules/asch-core for search.

In the .vscode/settings.json file I configured:

{
  "search.exclude": {
    "**/node_modules/": true,
  },
  "search.useIgnoreFiles": false,
  "search.useGlobalIgnoreFiles": false
}

search.useIgnoreFiles: false → search uses .gitignore files: no search.useGlobalIgnoreFiles: false → search uses global .gitignore files: no

On the left panel I untoggled the "Use Exclude Settings and Ignore Files"

Then I added the directory I wanted to include (in my case: /node_modules/asch-core, /*) into the files to include TextBox.

search_exclude_hack

dragonares5 commented 5 years ago

I needed this to exclude all the other stuff on /vendor except the /vendor/symfony, so i can use the intellisense autocompletion.

Create symlink object mklink /j "_include" "/vendor/symfony" (You need to use CMD.exe) Now exclude **/vendor, and done.

Now my _include folder redirect to symfony codes(vendor/symfony), without being excluded from VSCode, while hiding everything of vendor folder, making the intellisense caching fast.

nurbles commented 5 years ago

I would really like to hide all of the files that have no '.' in their name (except for "makefile".

I have tried "**/*.*": true and it will INCLUDE the exact list of files I want to EXCLUDE. One would think that changing 'true' to 'false' would produce the opposite result but instead, it excludes nothing.

I also tried "**/!(*.*)": true (and false) and neither of these exclude any files.

Finally, I tried "!(**/*.*)": true (and false) and nothing was excluded.

So is it possible to exclude all files without a dot in their name and if so, how?

[Currently using VS Code Version 1.31.0-insider]

qmshao commented 5 years ago

Here's my way to except /node_modules/foo from the exclude,

"files.exclude": {
    "**/node_modules/{[^f],?[^o],??[^o]}*": true
}
philraj commented 5 years ago

To anyone having trouble using negative character classes (e.g. [^x])...

I discovered that at least on my system, VSCode's implementation of globs breaks depending on the length of the pattern and how many character classes you put into the pattern.

For example, let's say you were trying to exclude all vendor directories except foobar.

This will work:

"**/vendor/[^f]*": true,
"**/vendor/f[^o]*": true,
"**/vendor/fo[^o]*": true,
"**/vendor/foo[^b]*": true,
"**/vendor/foob[^a]*": true,
"**/vendor/fooba[^r]*": true,
"**/vendor/foobar?*": true,

This will not work:

"**/vendor/[^f][^o][^o][^b][^a][^r]*": true,
"**/vendor/foobar?*": true,

I can't quite work out the exact rules for when it breaks, but if you want it to be bulletproof, try it with the working example above.

If you need to do this for more than one directory, e.g. foobar and hhhhhh the following seems to work as well:

"**/vendor/[^fh]*": true,
"**/vendor/[fh][^oh]*": true,
"**/vendor/[fh][oh][^oh]*": true,
"**/vendor/[fh][oh][oh][^bh]*": true,
"**/vendor/[fh][oh][oh][bh][^ah]*": true,
"**/vendor/[fh][oh][oh][bh][ah][^rh]*": true,
"**/vendor/{foobar?*, hhhhhh?*}": true,
kuworking commented 5 years ago

For me, the proposed solution works (e.g. => for gatsby-th*, firstmod*, secondmo*)

"node_modules/[^gfs]*"  : true,

"node_modules/g[^a]*"  : true,
"node_modules/ga[^t]*" : true,
"node_modules/gat[^s]*" : true,
"node_modules/gats[^b]*" : true,
"node_modules/gatsb[^y]*" : true,
"node_modules/gatsby[^-]*" : true,
"node_modules/gatsby-[^t]*" : true,
"node_modules/gatsby-t[^h]*" : true,

"node_modules/f[^i]*" : true,
"node_modules/fi[^r]*" : true,
"node_modules/fir[^s]*" : true,
"node_modules/firs[^t]*" : true,
"node_modules/first[^m]*" : true,
"node_modules/firstm[^o]*" : true,
"node_modules/firstmo[^d]*" : true,

"node_modules/s[^e]*" : true,
"node_modules/se[^c]*" : true,
"node_modules/sec[^o]*" : true,
"node_modules/seco[^n]*" : true,
"node_modules/secon[^d]*" : true,
"node_modules/second[^m]*" : true,
"node_modules/secondm[^o]*" : true,
chongchai commented 5 years ago

Any progress for this? We really need a simple way to include files or folders.

rusnasonov commented 5 years ago

In our corporation we use huge mono repository. For development we must open root of this repo, but project may use 0.1% of common code base. Our use case — include to search/watch only dirs related to concrete project (0.1%) and ignore other (99.9%)

picklit commented 5 years ago

The ! negate exclude for a glob would turn my excludes lines from about 40 to only about 5.

coeal-snap commented 4 years ago

I ended up here trying to hide all directories in node_modules except those that start with @ or . and while this feature would be immensely useful, this line in files.exclude worked for my use case.

"node_modules/[abcdefghijklmnopqrstuvwxyz]*": true

AnmolMago commented 4 years ago

Is there any update on this? It would be much appreciated! @isidorn

dalongi commented 4 years ago

@isidorn @bpasero: If someone were to look at sending a PR for this, is there a direction you'd prefer? (cc @solomatov)

For the large-monorepo use case, supporting this would make it simpler to support focused working-set views into the much larger tree.

I personally prefer adding "files.include" setting, though I think adding "!" or "false" support has better defined conflict resolution, using ordering as the tie-breaker and thus supports more of the use cases described in this issue.

alexandermckay commented 4 years ago

This was frustrating me so I have created a quick and dirty extension that can emulate the desired files.includes behaviour until this feature is added to VS Code.

To use it:

radiantly commented 4 years ago

image

The documentation linked to the setting mentions the usage of pattern negation syntax using ! . Maybe this should be removed until the feature is implemented?

sanbox-irl commented 4 years ago

@isidorn This was linked in the March Iteration plan here https://github.com/microsoft/vscode/issues/92242 but has since dropped off the April Iteration plan. Is this on the back burner for now?

I have been looking forward to this feature as a Unity developer, where we have many folder in the project hierarchy, which could have arbitrary names, but only one folder called "Scripts" where the C# I intend to edit actually lives.

isidorn commented 4 years ago

Not currently on the plan. Might be back in May.

justin-calleja commented 4 years ago

It's not just node_modules. If you open a project like DefinitelyTyped… you're generally only going to be reading / working on a single package under it's types directory.

Without this feature, how can anyone sanely navigate the 6690 directories within?!

ls -l types | wc -l
    6690

(short of opening VSCode directly in the types/<project> you're interested in).

Until this is implemented, I'm making do with this silly setting:

        "types/[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,z]*": true,

Thanks @ArturoDent - this seems to be equivalent:

     "types/[^y]*": true,
ArturoDent commented 4 years ago

@sanbox-irl As a workaround you can use this in your settings to show only the scripts folder:

files.exclude {
    "**/[^s]*": true,
    "**/s[^c]*": true,
    "**/sc[^r]*": true
    // more if necessary
}

You can see the pattern - you may need more or fewer entries depending on your other folder names.

sanbox-irl commented 4 years ago

frankly, in Unity, I just type the other folders out. I believe that trick has some strange platform issues? It's been at least a year. I think it either doesn't work on Mac or doesn't work on PC? I don't exactly recall. Anyway, I look forward to when the team has a chance to bring the issue forward to more robust solution. Lots of dev going on anyway

TimNewport commented 4 years ago

With not being able to do this yet. Is there a way to read a separate file hosting the json objects to exclude? I hate to clutter up my workspace with 900 different folders I want to exclude. I mean it works but its annoying :-)

thinh105 commented 4 years ago

Here's my way to except /node_modules/foo from the exclude,

"files.exclude": {
    "**/node_modules/{[^f],?[^o],??[^o]}*": true
}

thanks, look like this is the best workaround solution I can take from a super looooooong topic!

I want to include Bulma folder ( to work with autocomplete ) and then here is what I set on setting

  "files.exclude": {
    "**/node_modules/{[^b],?[^u],??[^l],???[^m]}*": true
  }
wclr commented 4 years ago

@isidorn I wonder why this ugly old problem has not been resolved yet?

ChengYuan-CY commented 4 years ago

I don't want to spend much time to investigate the script, so I'm using the "Explorer Exclude" extension.

adriantoll commented 4 years ago

For those like me who want to exclude everything except dotfiles in a workspace folder, right-click the folder in the explorer, click Open Folder Settings and search for "exclude". Then in the Files: Exclude list, add these patterns:

!**/.*
**/[0-9]*
**/[a-z]*
**/[A-Z]*
adriantoll commented 4 years ago

For those like me who want to exclude everything except dotfiles in a workspace folder, right-click the folder in the explorer, click Open Folder Settings and search for "exclude". Then in the Files: Exclude list, add these patterns:

!**/.*
**/[0-9]*
**/[a-z]*
**/[A-Z]*

Just an extra note that this also excludes files in dotfile directories (e.g. you can't see anything inside the ~/.ssh directory) so a better pattern is:

!**/.*
[0-9]*
[a-z]*
[A-Z]*