mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-27 19:08:21 +01:00
files - add method affects() for file changes (#108255)
* add a containsChildren method for #108164 * change to affects * comment
This commit is contained in:
@@ -542,12 +542,24 @@ export class FileChangesEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this change event contains the provided file
|
||||
* with the given change type (if provided). In case of type
|
||||
* DELETED, this method will also return true if a folder got
|
||||
* deleted that is the parent of the provided file path.
|
||||
* Find out if the file change events match the provided resource.
|
||||
*
|
||||
* Note: when passing `FileChangeType.DELETED`, we consider a match
|
||||
* also when the parent of the resource got deleted.
|
||||
*/
|
||||
contains(resource: URI, ...types: FileChangeType[]): boolean {
|
||||
return this.doContains(resource, { includeChildren: false }, ...types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if the file change events either match the provided
|
||||
* resource, or contain a child of this resource.
|
||||
*/
|
||||
affects(resource: URI, ...types: FileChangeType[]): boolean {
|
||||
return this.doContains(resource, { includeChildren: true }, ...types);
|
||||
}
|
||||
|
||||
private doContains(resource: URI, options: { includeChildren: boolean }, ...types: FileChangeType[]): boolean {
|
||||
if (!resource) {
|
||||
return false;
|
||||
}
|
||||
@@ -559,6 +571,10 @@ export class FileChangesEvent {
|
||||
if (this.added?.get(resource)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.includeChildren && this.added?.findSuperstr(resource)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Updated
|
||||
@@ -566,6 +582,10 @@ export class FileChangesEvent {
|
||||
if (this.updated?.get(resource)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.includeChildren && this.updated?.findSuperstr(resource)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Deleted
|
||||
@@ -573,6 +593,10 @@ export class FileChangesEvent {
|
||||
if (this.deleted?.findSubstr(resource) /* deleted also considers parent folders */) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.includeChildren && this.deleted?.findSuperstr(resource)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -26,19 +26,26 @@ suite('Files', () => {
|
||||
const event = new FileChangesEvent(changes, ignorePathCasing);
|
||||
|
||||
assert(!event.contains(toResource.call(this, '/foo'), FileChangeType.UPDATED));
|
||||
assert(event.affects(toResource.call(this, '/foo'), FileChangeType.UPDATED));
|
||||
assert(event.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED));
|
||||
assert(event.affects(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED));
|
||||
assert(event.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED, FileChangeType.ADDED));
|
||||
assert(event.affects(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED, FileChangeType.ADDED));
|
||||
assert(event.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED, FileChangeType.ADDED, FileChangeType.DELETED));
|
||||
assert(!event.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.ADDED, FileChangeType.DELETED));
|
||||
assert(!event.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.ADDED));
|
||||
assert(!event.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.DELETED));
|
||||
assert(!event.affects(toResource.call(this, '/foo/updated.txt'), FileChangeType.DELETED));
|
||||
|
||||
assert(event.contains(toResource.call(this, '/bar/folder'), FileChangeType.DELETED));
|
||||
assert(event.contains(toResource.call(this, '/BAR/FOLDER'), FileChangeType.DELETED));
|
||||
assert(event.affects(toResource.call(this, '/BAR'), FileChangeType.DELETED));
|
||||
if (ignorePathCasing) {
|
||||
assert(event.contains(toResource.call(this, '/BAR/folder'), FileChangeType.DELETED));
|
||||
assert(event.affects(toResource.call(this, '/bar'), FileChangeType.DELETED));
|
||||
} else {
|
||||
assert(!event.contains(toResource.call(this, '/BAR/folder'), FileChangeType.DELETED));
|
||||
assert(event.affects(toResource.call(this, '/bar'), FileChangeType.DELETED));
|
||||
}
|
||||
assert(event.contains(toResource.call(this, '/bar/folder/somefile'), FileChangeType.DELETED));
|
||||
assert(event.contains(toResource.call(this, '/bar/folder/somefile/test.txt'), FileChangeType.DELETED));
|
||||
@@ -78,10 +85,18 @@ suite('Files', () => {
|
||||
|
||||
for (const change of changes) {
|
||||
assert(event.contains(change.resource, type));
|
||||
assert(event.affects(change.resource, type));
|
||||
}
|
||||
|
||||
assert(event.affects(toResource.call(this, '/foo'), type));
|
||||
assert(event.affects(toResource.call(this, '/bar'), type));
|
||||
assert(event.affects(toResource.call(this, '/'), type));
|
||||
assert(!event.affects(toResource.call(this, '/foobar'), type));
|
||||
|
||||
assert(!event.contains(toResource.call(this, '/some/foo/bar'), type));
|
||||
assert(!event.affects(toResource.call(this, '/some/foo/bar'), type));
|
||||
assert(!event.contains(toResource.call(this, '/some/bar'), type));
|
||||
assert(!event.affects(toResource.call(this, '/some/bar'), type));
|
||||
|
||||
switch (type) {
|
||||
case FileChangeType.ADDED:
|
||||
|
||||
Reference in New Issue
Block a user