mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
92 lines
3.5 KiB
TypeScript
92 lines
3.5 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { DisposableStore } 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';
|
|
import { IProgressService } from 'vs/platform/progress/common/progress';
|
|
import { localize } from 'vs/nls';
|
|
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
|
|
import { Registry } from 'vs/platform/registry/common/platform';
|
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
|
import { ILogService } from 'vs/platform/log/common/log';
|
|
import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
|
|
|
|
@extHostCustomer
|
|
export class MainThreadFileSystemEventService {
|
|
|
|
private readonly _listener = new DisposableStore();
|
|
|
|
constructor(
|
|
extHostContext: IExtHostContext,
|
|
@IFileService fileService: IFileService,
|
|
@ITextFileService textFileService: ITextFileService,
|
|
@IProgressService progressService: IProgressService,
|
|
@IConfigurationService configService: IConfigurationService,
|
|
@ILogService logService: ILogService,
|
|
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService
|
|
) {
|
|
|
|
const proxy = extHostContext.getProxy(ExtHostContext.ExtHostFileSystemEventService);
|
|
|
|
// file system events - (changes the editor and other make)
|
|
const events: FileSystemEvents = {
|
|
created: [],
|
|
changed: [],
|
|
deleted: []
|
|
};
|
|
this._listener.add(fileService.onDidFilesChange(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;
|
|
}));
|
|
|
|
|
|
// BEFORE file operation
|
|
workingCopyFileService.addFileOperationParticipant({
|
|
participate: (target, source, operation, progress, timeout, token) => {
|
|
return proxy.$onWillRunFileOperation(operation, target, source, timeout, token);
|
|
}
|
|
});
|
|
|
|
// AFTER file operation
|
|
this._listener.add(textFileService.onDidCreateTextFile(e => proxy.$onDidRunFileOperation(FileOperation.CREATE, e.resource, undefined)));
|
|
this._listener.add(workingCopyFileService.onDidRunWorkingCopyFileOperation(e => proxy.$onDidRunFileOperation(e.operation, e.target, e.source)));
|
|
}
|
|
|
|
dispose(): void {
|
|
this._listener.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
|
|
id: 'files',
|
|
properties: {
|
|
'files.participants.timeout': {
|
|
type: 'number',
|
|
default: 5000,
|
|
markdownDescription: localize('files.participants.timeout', "Timeout in milliseconds after which file participants for create, rename, and delete are cancelled. Use `0` to disable participants."),
|
|
}
|
|
}
|
|
});
|