move mainThread[A-F], #70319

This commit is contained in:
Johannes Rieken
2019-03-19 17:18:00 +01:00
parent d1e6f624ef
commit 63f2d31d3f
19 changed files with 38 additions and 32 deletions

View File

@@ -0,0 +1,68 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { FileChangeType, IFileService, FileOperation } from 'vs/platform/files/common/files';
import { extHostCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { ExtHostContext, FileSystemEvents, IExtHostContext } from '../common/extHost.protocol';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
@extHostCustomer
export class MainThreadFileSystemEventService {
private readonly _listener = new Array<IDisposable>();
constructor(
extHostContext: IExtHostContext,
@IFileService fileService: IFileService,
@ITextFileService textfileService: ITextFileService,
) {
const proxy = extHostContext.getProxy(ExtHostContext.ExtHostFileSystemEventService);
// file system events - (changes the editor and other make)
const events: FileSystemEvents = {
created: [],
changed: [],
deleted: []
};
fileService.onFileChanges(event => {
for (let change of event.changes) {
switch (change.type) {
case FileChangeType.ADDED:
events.created.push(change.resource);
break;
case FileChangeType.UPDATED:
events.changed.push(change.resource);
break;
case FileChangeType.DELETED:
events.deleted.push(change.resource);
break;
}
}
proxy.$onFileEvent(events);
events.created.length = 0;
events.changed.length = 0;
events.deleted.length = 0;
}, undefined, this._listener);
// file operation events - (changes the editor makes)
fileService.onAfterOperation(e => {
if (e.operation === FileOperation.MOVE) {
proxy.$onFileRename(e.resource, e.target!.resource);
}
}, undefined, this._listener);
textfileService.onWillMove(e => {
const promise = proxy.$onWillRename(e.oldResource, e.newResource);
e.waitUntil(promise);
}, undefined, this._listener);
}
dispose(): void {
dispose(this._listener);
}
}