Skip to content

Add explorer.autorevealExclude setting #136905

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

Merged
merged 7 commits into from
Nov 14, 2022

Conversation

jzyrobert
Copy link
Contributor

@jzyrobert jzyrobert commented Nov 10, 2021

This PR fixes #87956

Loosely based on the original PR by @joelday and the FilesFilter class, using the suggestion of @JacksonKearl to be in the ExplorerService file.

  • Inherits from files.exclude
  • Defaults to same values as search.exclude: **/node_modules, **/bower_components, **/*.code-search
  • Calls to refresh, selectResource and calls from ExplorerView are all routed to ExplorerService.select(), where the reveal check occurs
  • Recursively checks from the file up to the first root child, if any of them match a pattern then the file is not revealed.

Example of glob matching nested folder:
lx4QuzvqPP

Example of using when clause to hide .js files:
RZ9Ji13Xmh

Some things to consider:

  • Tests: I wasn't sure if there is support for testing whether the reveal correctly shows or not. files.exclude only has tests for the find files function, and not for FilesFilter. I suppose you could create a RevealFilter manually and check the boolean function, but I didn't see other tests having support for mocking contextService etc
    • Edit: Could be added to integration tests?
  • Behaviour if folder is already open:
    • Should the file still be revealed?
    • Should it be ignored? (<- current behaviour)
  • Behaviour if an open folder is added to the setting:
    • Should the tree close the folder?
    • Should it be left as is? (<- current behaviour)
  • Performance:
    • Should the check run on each selection? How much does iterating through the parent tree of an item each time matter (No initial cost, each call only iterates up it's own parent(s))
    • Or should it mirror the files.exclude setting, which runs top-down each time files are updated and sets a cached boolean for each folder/file. (Bigger initial cost as has to check all folder/files, no cost after)

@jzyrobert jzyrobert force-pushed the jzyrobert/explorer_autoreveal branch from 3c42745 to d9e12ce Compare November 17, 2021 18:54
@jzyrobert jzyrobert force-pushed the jzyrobert/explorer_autoreveal branch from d9e12ce to 4e781ac Compare December 1, 2021 18:28
@JacksonKearl
Copy link
Contributor

It's not clear do me what the FilesFilter class does here, it seems to duplicate a lot of the existing functionality of the glob module but with more code to maintain, I'd like to see what the smallest possible diff to implement the desired functionality would look like.

@jzyrobert jzyrobert force-pushed the jzyrobert/explorer_autoreveal branch from 4e781ac to b2cd4ae Compare December 9, 2021 22:50
@jzyrobert
Copy link
Contributor Author

@JacksonKearl I have implemented it using ResourceGlobMatcher instead as you have requested, please take another look.

I'm not sure if its possible the required recursive matching into the matcher, as you cannot import from workbench/contrib

@@ -358,6 +372,25 @@ export class ExplorerService implements IExplorerService {
}
}

// Reveal excludes
private matchesUpToRoot(item: ExplorerItem | undefined): boolean {
Copy link
Contributor

@JacksonKearl JacksonKearl Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple notes:

  • the name of this isn't very discriptive shouldAutoRevealItem might be better?
  • walking up the directly tree for every item isn't great, the glob matcher should be able to know that node_modules/** matches node_modules/abc/d without stepping through every directory?

Edit: Oh, I see it's for the sibiling clauses... we don't typically support those for directories as far as I'm aware, that seems like a failrly expensive operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change the name as you suggested.

The glob matcher can match files if specified, e.g. **/node_modules/* would work fine without recursive checking.
The reason for this implementation is that the settings are inherited from the files.exclude setting, which allows specifying both folder and file patterns for showing files in the explorer. That setting is passed recursively and only needs to be called once for every tree item.
However, I also don't think the performance impact is too serious, as:

  1. Focusing on a file is not a super frequent operation
  2. File structures do not tend to be super deep, in the case of **/node_modules it would be 4-5 match operations for a source file inside

In that case, there are two options I would suggest here:

  1. Keep the matching as is, but only check for sibling clauses with the initial item, and do not pass as sibling clause for the parent matching.
  2. Remove the recursive matching, and edit the default setting and setting description to say that you must explicitly specify file patterns (**/node_modules/*) and not folder patterns (**/node_modules)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzyrobert Did we settle on anything here I think we only support file patterns for files.exclude so this should mirror that.

@jzyrobert jzyrobert force-pushed the jzyrobert/explorer_autoreveal branch from b2cd4ae to 1496945 Compare December 17, 2021 23:52
@Livan-pro
Copy link

It looks very helpful. @JacksonKearl, what about this?

@JacksonKearl JacksonKearl added this to the Backlog milestone Feb 4, 2022
@JacksonKearl
Copy link
Contributor

I wonder how this should interact with recently added file nesting.

@AmitPr
Copy link

AmitPr commented Jun 22, 2022

Hi, any update on this?

@lramos15
Copy link
Member

@jzyrobert Jackson has since left the company so I have taken over reviewing this PR. Please resolve merge conflicts and get CI to pass and then ping me for a review. Hopefully we can get this in for not this release but the next one. Thank you for your contribution.

@lramos15 lramos15 modified the milestones: Backlog, July 2022 Jun 23, 2022
@jzyrobert jzyrobert force-pushed the jzyrobert/explorer_autoreveal branch from 18caae5 to a6d4981 Compare October 24, 2022 22:52
@lramos15 lramos15 modified the milestones: On Deck, November 2022 Oct 25, 2022
@lramos15
Copy link
Member

Thanks for the super detailed response, will review and test this for the November release. Currently busy finishing up October's release, but this is definitely on our radar and I will get back to you shortly 👍

@lramos15
Copy link
Member

lramos15 commented Nov 8, 2022

I'm a bit hesitant in inheriting from files.exclude I quite like that if I do open those files they appear in the explorer so that they can be edited and acted upon. I don't mind sharing the same defaults, but I don't know if I'm comfortable in them always being merged.

Copy link
Collaborator

@isidorn isidorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR. I have left some minor comments. It would be great if @bpasero also gives it a glance for exclude and globs.

'explorer.autoRevealExclude': {
'type': 'object',
'markdownDescription': nls.localize('autoRevealExclude', "Configure glob patterns for excluding files and folders from being revealed and selected in the explorer when they are opened. Inherits all glob patterns from the `#files.exclude#` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options)."),
'default': { '**/node_modules': true, '**/bower_components': true, '**/*.code-search': true },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is code-search and why is it in the default?

@@ -371,6 +371,30 @@ configurationRegistry.registerConfiguration({
],
'description': nls.localize('autoReveal', "Controls whether the explorer should automatically reveal and select files when opening them.")
},
'explorer.autoRevealExclude': {
'type': 'object',
'markdownDescription': nls.localize('autoRevealExclude', "Configure glob patterns for excluding files and folders from being revealed and selected in the explorer when they are opened. Inherits all glob patterns from the `#files.exclude#` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options)."),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand how is the inheriting done and how can the user change that?
How can the user discover that if they miss this desciprtion? We do not have inheritence structure in our settings and I suggest that we do not introduce it now (unless I am missing some case)

@isidorn isidorn requested a review from bpasero November 11, 2022 16:16
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not fully understand the need for glob patterns that check on siblings for this purpose here: imho extending from files.exclude does not really make a lot of sense because the explorer will not show anything that is file.exclude (at least to my knowledge) and as such will not auto-reveal anyway. And for the setting I would believe simple glob patterns are sufficient and not the ones with sibling support?

@jzyrobert
Copy link
Contributor Author

I do not fully understand the need for glob patterns that check on siblings for this purpose here: imho extending from files.exclude does not really make a lot of sense because the explorer will not show anything that is file.exclude (at least to my knowledge) and as such will not auto-reveal anyway. And for the setting I would believe simple glob patterns are sufficient and not the ones with sibling support?
@bpasero

The explorer will show files in file.exclude, for example:
image
The tree shows nothing because I excluded hiddenFolder

Then I access a file in there by some way (Ctrl+ P or if it was imported etc):
image
It shows up in the explorer. What it doesn't show is anything else in that folder.

@isidorn makes a point that it wouldn't be obvious to users unless they find the setting description so that can be removed and users can add back what they want.

I can remove the sibling support if required, but wouldn't it be useful to have? It doesn't interfere with the normal glob functionality and can be useful such as wanting to check a compiled JS file but having it revealed if a TS file exists with the same name in that folder.

@jzyrobert jzyrobert force-pushed the jzyrobert/explorer_autoreveal branch from 1767a5f to 25ea489 Compare November 13, 2022 12:29
@lramos15
Copy link
Member

This looks good to me from the explorer side of things and I'm hoping to take this in either today or tomorrow to get ample testing in insiders.

@bpasero I'll defer to you if we should keep sibling support or not. It does seem like it only is wiring through an existing check via matches so unsure if that still feels like tainting the interface. We can probably gauge via telemetry how often when patterns are used and decide whether or not we should implement it in the future or remove it in the future deciding which way we want to go.

@bpasero bpasero requested review from bpasero and removed request for bpasero November 14, 2022 14:40
@bpasero
Copy link
Member

bpasero commented Nov 14, 2022

Yeah its fine for me, doesn't need to block this PR from merging.

Copy link
Member

@lramos15 lramos15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an amazing contribution, thanks for working with us as we understand how long it takes to get something like this merged in!

@lramos15 lramos15 requested a review from bpasero November 14, 2022 14:50
@lramos15 lramos15 dismissed bpasero’s stale review November 14, 2022 14:51

Decided to keep the sibling check for this iteration

@lramos15 lramos15 removed the request for review from bpasero November 14, 2022 14:51
@lramos15 lramos15 merged commit fbaacfb into microsoft:main Nov 14, 2022
@lramos15
Copy link
Member

lramos15 commented Nov 14, 2022

This will be in tomorrow's insiders.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to set explorer.autoReveal per specific folder