Skip to content

Commit a4dafab

Browse files
author
Benjamin Pasero
committed
files - use proper extUri for file events
1 parent e12a3ef commit a4dafab

7 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/vs/platform/files/common/fileService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class FileService extends Disposable implements IFileService {
5454

5555
// Forward events from provider
5656
const providerDisposables = new DisposableStore();
57-
providerDisposables.add(provider.onDidChangeFile(changes => this._onDidFilesChange.fire(new FileChangesEvent(changes))));
57+
providerDisposables.add(provider.onDidChangeFile(changes => this._onDidFilesChange.fire(new FileChangesEvent(changes, this.getExtUri(provider).extUri))));
5858
providerDisposables.add(provider.onDidChangeCapabilities(() => this._onDidChangeFileSystemProviderCapabilities.fire({ provider, scheme })));
5959
if (typeof provider.onDidErrorOccur === 'function') {
6060
providerDisposables.add(provider.onDidErrorOccur(error => this._onError.fire(new Error(error))));

src/vs/platform/files/common/files.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
1111
import { Event } from 'vs/base/common/event';
1212
import { startsWithIgnoreCase } from 'vs/base/common/strings';
1313
import { IDisposable } from 'vs/base/common/lifecycle';
14-
import { isEqualOrParent, isEqual } from 'vs/base/common/resources';
14+
import { ExtUri } from 'vs/base/common/resources';
1515
import { isUndefinedOrNull } from 'vs/base/common/types';
1616
import { VSBuffer, VSBufferReadable, VSBufferReadableStream } from 'vs/base/common/buffer';
1717
import { ReadableStreamEvents } from 'vs/base/common/stream';
@@ -491,7 +491,7 @@ export interface IFileChange {
491491

492492
export class FileChangesEvent {
493493

494-
constructor(public readonly changes: readonly IFileChange[]) { }
494+
constructor(public readonly changes: readonly IFileChange[], private readonly extUri: ExtUri) { }
495495

496496
/**
497497
* Returns true if this change event contains the provided file with the given change type (if provided). In case of
@@ -512,10 +512,10 @@ export class FileChangesEvent {
512512

513513
// For deleted also return true when deleted folder is parent of target path
514514
if (change.type === FileChangeType.DELETED) {
515-
return isEqualOrParent(resource, change.resource);
515+
return this.extUri.isEqualOrParent(resource, change.resource);
516516
}
517517

518-
return isEqual(resource, change.resource);
518+
return this.extUri.isEqual(resource, change.resource);
519519
});
520520
}
521521

@@ -570,6 +570,10 @@ export class FileChangesEvent {
570570
return change.type === type;
571571
});
572572
}
573+
574+
filter(filterFn: (change: IFileChange) => boolean): FileChangesEvent {
575+
return new FileChangesEvent(this.changes.filter(change => filterFn(change)), this.extUri);
576+
}
573577
}
574578

575579
export function isParent(path: string, candidate: string, ignoreCase?: boolean): boolean {

src/vs/platform/files/test/common/files.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { URI } from 'vs/base/common/uri';
88
import { isEqual, isEqualOrParent } from 'vs/base/common/extpath';
99
import { FileChangeType, FileChangesEvent, isParent } from 'vs/platform/files/common/files';
1010
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
11-
// eslint-disable-next-line code-import-patterns
1211
import { toResource } from 'vs/base/test/common/utils';
12+
import { extUri } from 'vs/base/common/resources';
1313

1414
suite('Files', () => {
1515

@@ -22,7 +22,7 @@ suite('Files', () => {
2222
{ resource: toResource.call(this, '/bar/folder'), type: FileChangeType.DELETED }
2323
];
2424

25-
let r1 = new FileChangesEvent(changes);
25+
let r1 = new FileChangesEvent(changes, extUri);
2626

2727
assert(!r1.contains(toResource.call(this, '/foo'), FileChangeType.UPDATED));
2828
assert(r1.contains(toResource.call(this, '/foo/updated.txt'), FileChangeType.UPDATED));

src/vs/platform/files/test/electron-browser/normalizer.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { FileChangeType, FileChangesEvent } from 'vs/platform/files/common/files
99
import { URI as uri } from 'vs/base/common/uri';
1010
import { IDiskFileChange, normalizeFileChanges, toFileChanges } from 'vs/platform/files/node/watcher/watcher';
1111
import { Event, Emitter } from 'vs/base/common/event';
12+
import { extUri } from 'vs/base/common/resources';
1213

1314
function toFileChangesEvent(changes: IDiskFileChange[]): FileChangesEvent {
14-
return new FileChangesEvent(toFileChanges(changes));
15+
return new FileChangesEvent(toFileChanges(changes), extUri);
1516
}
1617

1718
class TestFileWatcher {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export class ExplorerService implements IExplorerService {
362362
}
363363

364364
private filterToViewRelevantEvents(e: FileChangesEvent): FileChangesEvent {
365-
return new FileChangesEvent(e.changes.filter(change => {
365+
return e.filter(change => {
366366
if (change.type === FileChangeType.UPDATED && this._sortOrder !== SortOrder.Modified) {
367367
return false; // we only are about updated if we sort by modified time
368368
}
@@ -376,7 +376,7 @@ export class ExplorerService implements IExplorerService {
376376
}
377377

378378
return true;
379-
}));
379+
});
380380
}
381381

382382
private async onConfigurationUpdated(configuration: IFilesConfiguration, event?: IConfigurationChangeEvent): Promise<void> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
2525
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
2626
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2727
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
28-
import { isEqual } from 'vs/base/common/resources';
28+
import { isEqual, extUri } from 'vs/base/common/resources';
2929
import { URI } from 'vs/base/common/uri';
3030
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
3131
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -99,7 +99,7 @@ suite('Files - TextFileEditorTracker', () => {
9999
await model.save();
100100

101101
// change event (watcher)
102-
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.UPDATED }]));
102+
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.UPDATED }], extUri));
103103

104104
await timeout(0); // due to event updating model async
105105

src/vs/workbench/services/textfile/test/browser/textFileEditorModelManager.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { toResource } from 'vs/base/test/common/utils';
1414
import { ModesRegistry, PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
1515
import { ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles';
1616
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
17+
import { extUri } from 'vs/base/common/resources';
1718

1819
suite('Files - TextFileEditorModelManager', () => {
1920

@@ -184,8 +185,8 @@ suite('Files - TextFileEditorModelManager', () => {
184185
const model1 = await manager.resolve(resource1, { encoding: 'utf8' });
185186
assert.equal(loadedCounter, 1);
186187

187-
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource: resource1, type: FileChangeType.DELETED }]));
188-
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource: resource1, type: FileChangeType.ADDED }]));
188+
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource: resource1, type: FileChangeType.DELETED }], extUri));
189+
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource: resource1, type: FileChangeType.ADDED }], extUri));
189190

190191
const model2 = await manager.resolve(resource2, { encoding: 'utf8' });
191192
assert.equal(loadedCounter, 2);

0 commit comments

Comments
 (0)