Skip to content

Commit 3aca77c

Browse files
authored
Merge pull request #118777 from jeanp413/fix-118557
Fix strange behavior of files.exclude in workspace with nested folders
2 parents 3eae853 + 3635f11 commit 3aca77c

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

src/vs/workbench/contrib/files/browser/explorerService.ts

+6
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ export class ExplorerService implements IExplorerService {
170170
return this.model.findClosest(resource);
171171
}
172172

173+
findClosestRoot(resource: URI): ExplorerItem | null {
174+
const parentRoots = this.model.roots.filter(r => this.uriIdentityService.extUri.isEqualOrParent(resource, r.resource))
175+
.sort((first, second) => second.resource.path.length - first.resource.path.length);
176+
return parentRoots.length ? parentRoots[0] : null;
177+
}
178+
173179
async setEditable(stat: ExplorerItem, data: IEditableData | null): Promise<void> {
174180
if (!this.view) {
175181
return;

src/vs/workbench/contrib/files/browser/files.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface IExplorerService {
8484
// If undefined is passed checks if any element is currently being edited.
8585
isEditable(stat: ExplorerItem | undefined): boolean;
8686
findClosest(resource: URI): ExplorerItem | null;
87+
findClosestRoot(resource: URI): ExplorerItem | null;
8788
refresh(): Promise<void>;
8889
setToCopy(stats: ExplorerItem[], cut: boolean): Promise<void>;
8990
isCut(stat: ExplorerItem): boolean;

src/vs/workbench/contrib/files/browser/views/explorerView.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,7 @@ export class ExplorerView extends ViewPane {
703703
}
704704

705705
// Expand all stats in the parent chain.
706-
let item: ExplorerItem | undefined = this.explorerService.roots.filter(i => this.uriIdentityService.extUri.isEqualOrParent(resource, i.resource))
707-
// Take the root that is the closest to the stat #72299
708-
.sort((first, second) => second.resource.path.length - first.resource.path.length)[0];
706+
let item: ExplorerItem | null = this.explorerService.findClosestRoot(resource);
709707

710708
while (item && item.resource.toString() !== resource.toString()) {
711709
try {
@@ -719,7 +717,7 @@ export class ExplorerView extends ViewPane {
719717
item = child;
720718
break;
721719
}
722-
item = undefined;
720+
item = null;
723721
}
724722
}
725723

src/vs/workbench/contrib/files/browser/views/explorerViewer.ts

+19-26
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ interface CachedParsedExpression {
532532
* Makes sure that visible editors are always shown in the explorer even if they are filtered out by settings.
533533
*/
534534
export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
535-
private hiddenExpressionPerRoot: Map<string, CachedParsedExpression>;
536-
private uriVisibilityMap = new Map<URI, boolean>();
535+
private hiddenExpressionPerRoot = new Map<string, CachedParsedExpression>();
537536
private editorsAffectingFilter = new Set<IEditorInput>();
538537
private _onDidChange = new Emitter<void>();
539538
private toDispose: IDisposable[] = [];
@@ -545,7 +544,6 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
545544
@IEditorService private readonly editorService: IEditorService,
546545
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService
547546
) {
548-
this.hiddenExpressionPerRoot = new Map<string, CachedParsedExpression>();
549547
this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders(() => this.updateConfiguration()));
550548
this.toDispose.push(this.configurationService.onDidChangeConfiguration((e) => {
551549
if (e.affectsConfiguration('files.exclude')) {
@@ -555,26 +553,30 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
555553
this.toDispose.push(this.editorService.onDidVisibleEditorsChange(() => {
556554
const editors = this.editorService.visibleEditors;
557555
let shouldFire = false;
558-
this.uriVisibilityMap.forEach((visible, uri) => {
559-
if (!visible) {
560-
editors.forEach(e => {
561-
if (e.resource && this.uriIdentityService.extUri.isEqualOrParent(e.resource, uri)) {
562-
// A filtered resource suddenly became visible since user opened an editor
563-
shouldFire = true;
564-
}
565-
});
556+
557+
for (const e of editors) {
558+
if (!e.resource) {
559+
continue;
566560
}
567-
});
568561

569-
this.editorsAffectingFilter.forEach(e => {
562+
const stat = this.explorerService.findClosest(e.resource);
563+
if (stat && stat.isExcluded) {
564+
// A filtered resource suddenly became visible since user opened an editor
565+
shouldFire = true;
566+
break;
567+
}
568+
}
569+
570+
for (const e of this.editorsAffectingFilter) {
570571
if (!editors.includes(e)) {
571572
// Editor that was affecting filtering is no longer visible
572573
shouldFire = true;
574+
break;
573575
}
574-
});
576+
}
577+
575578
if (shouldFire) {
576579
this.editorsAffectingFilter.clear();
577-
this.uriVisibilityMap.clear();
578580
this._onDidChange.fire();
579581
}
580582
}));
@@ -603,21 +605,12 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
603605

604606
if (shouldFire) {
605607
this.editorsAffectingFilter.clear();
606-
this.uriVisibilityMap.clear();
607608
this._onDidChange.fire();
608609
}
609610
}
610611

611612
filter(stat: ExplorerItem, parentVisibility: TreeVisibility): boolean {
612-
const cachedVisibility = this.uriVisibilityMap.get(stat.resource);
613-
if (typeof cachedVisibility === 'boolean') {
614-
return cachedVisibility;
615-
}
616-
617-
const isVisible = this.isVisible(stat, parentVisibility);
618-
this.uriVisibilityMap.set(stat.resource, isVisible);
619-
620-
return isVisible;
613+
return this.isVisible(stat, parentVisibility);
621614
}
622615

623616
private isVisible(stat: ExplorerItem, parentVisibility: TreeVisibility): boolean {
@@ -636,7 +629,7 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
636629
stat.isExcluded = true;
637630
const editors = this.editorService.visibleEditors;
638631
const editor = editors.find(e => e.resource && this.uriIdentityService.extUri.isEqualOrParent(e.resource, stat.resource));
639-
if (editor) {
632+
if (editor && stat.root === this.explorerService.findClosestRoot(stat.resource)) {
640633
this.editorsAffectingFilter.add(editor);
641634
return true; // Show all opened files and their parents
642635
}

0 commit comments

Comments
 (0)