Skip to content

Commit

Permalink
support working copy ops
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Jun 10, 2020
1 parent 72e361d commit d8151fe
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 84 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export namespace WaitUntilEvent {
export function fireAsync<T extends WaitUntilEvent>(
emitter: Emitter<T>,
event: Pick<T, Exclude<keyof T, 'waitUntil'>>,
token: CancellationToken,
token: CancellationToken = CancellationToken.None,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>
): MaybePromise<void> {
Expand Down
7 changes: 3 additions & 4 deletions packages/debug/src/browser/debug-configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-k
import { DebugConfiguration } from '../common/debug-common';
import { WorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
import { TextBuffer } from '@theia/filesystem/lib/common/buffer';
import { TextFileService } from '@theia/filesystem/lib/browser/text-file-service';
import { WorkingCopyFileService } from 'packages/filesystem/lib/browser/working-copy-file-service';

export interface WillProvideDebugConfiguration extends WaitUntilEvent {
}
Expand All @@ -57,8 +56,8 @@ export class DebugConfigurationManager {
@inject(ContextKeyService)
protected readonly contextKeyService: ContextKeyService;

@inject(TextFileService)
protected readonly fileService: TextFileService;
@inject(WorkingCopyFileService)
protected readonly fileService: WorkingCopyFileService;

@inject(PreferenceService)
protected readonly preferences: PreferenceService;
Expand Down
54 changes: 20 additions & 34 deletions packages/filesystem/src/browser/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,19 @@ export class FileService {

private readonly BUFFER_SIZE = 64 * 1024;

private readonly toDispose = new DisposableCollection();

protected _register<T extends Disposable>(disposable: T): T {
this.toDispose.push(disposable);
return disposable;
}

@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;

// #region File System Provider

private _onDidChangeFileSystemProviderRegistrations = this._register(new Emitter<FileSystemProviderRegistrationEvent>());
readonly onDidChangeFileSystemProviderRegistrations = this._onDidChangeFileSystemProviderRegistrations.event;
private onDidChangeFileSystemProviderRegistrationsEmitter = new Emitter<FileSystemProviderRegistrationEvent>();
readonly onDidChangeFileSystemProviderRegistrations = this.onDidChangeFileSystemProviderRegistrationsEmitter.event;

private _onWillActivateFileSystemProvider = this._register(new Emitter<FileSystemProviderActivationEvent>());
readonly onWillActivateFileSystemProvider = this._onWillActivateFileSystemProvider.event;
private onWillActivateFileSystemProviderEmitter = new Emitter<FileSystemProviderActivationEvent>();
readonly onWillActivateFileSystemProvider = this.onWillActivateFileSystemProviderEmitter.event;

private _onDidChangeFileSystemProviderCapabilities = this._register(new Emitter<FileSystemProviderCapabilitiesChangeEvent>());
readonly onDidChangeFileSystemProviderCapabilities = this._onDidChangeFileSystemProviderCapabilities.event;
private onDidChangeFileSystemProviderCapabilitiesEmitter = new Emitter<FileSystemProviderCapabilitiesChangeEvent>();
readonly onDidChangeFileSystemProviderCapabilities = this.onDidChangeFileSystemProviderCapabilitiesEmitter.event;

private readonly provider = new Map<string, FileSystemProvider>();

Expand All @@ -84,15 +77,15 @@ export class FileService {

// Add provider with event
this.provider.set(scheme, provider);
this._onDidChangeFileSystemProviderRegistrations.fire({ added: true, scheme, provider });
this.onDidChangeFileSystemProviderRegistrationsEmitter.fire({ added: true, scheme, provider });

// Forward events from provider
const providerDisposables = new DisposableCollection();
providerDisposables.push(provider.onDidChangeFile(changes => this._onDidFilesChange.fire(new FileChangesEvent(changes))));
providerDisposables.push(provider.onDidChangeCapabilities(() => this._onDidChangeFileSystemProviderCapabilities.fire({ provider, scheme })));
providerDisposables.push(provider.onDidChangeFile(changes => this.onDidFilesChangeEmitter.fire(new FileChangesEvent(changes))));
providerDisposables.push(provider.onDidChangeCapabilities(() => this.onDidChangeFileSystemProviderCapabilitiesEmitter.fire({ provider, scheme })));

return Disposable.create(() => {
this._onDidChangeFileSystemProviderRegistrations.fire({ added: false, scheme, provider });
this.onDidChangeFileSystemProviderRegistrationsEmitter.fire({ added: false, scheme, provider });
this.provider.delete(scheme);

providerDisposables.dispose();
Expand All @@ -104,7 +97,7 @@ export class FileService {
// Emit an event that we are about to activate a provider with the given scheme.
// Listeners can participate in the activation by registering a provider for it.
const joiners: Promise<void>[] = [];
this._onWillActivateFileSystemProvider.fire({
this.onWillActivateFileSystemProviderEmitter.fire({
scheme,
join(promise) {
if (promise) {
Expand Down Expand Up @@ -175,8 +168,8 @@ export class FileService {

// #endregion

private _onDidRunOperation = this._register(new Emitter<FileOperationEvent>());
readonly onDidRunOperation = this._onDidRunOperation.event;
private onDidRunOperationEmitter = new Emitter<FileOperationEvent>();
readonly onDidRunOperation = this.onDidRunOperationEmitter.event;

resolve(resource: URI, options: ResolveMetadataFileOptions): Promise<FileStatWithMetadata>;
resolve(resource: URI, options?: ResolveFileOptions | undefined): Promise<FileStat>;
Expand Down Expand Up @@ -320,7 +313,7 @@ export class FileService {
const fileStat = await this.writeFile(resource, bufferOrReadableOrStream);

// events
this._onDidRunOperation.fire(new FileOperationEvent(resource, FileOperation.CREATE, fileStat));
this.onDidRunOperationEmitter.fire(new FileOperationEvent(resource, FileOperation.CREATE, fileStat));

return fileStat;
}
Expand Down Expand Up @@ -535,7 +528,7 @@ export class FileService {

// resolve and send events
const fileStat = await this.resolve(target, { resolveMetadata: true });
this._onDidRunOperation.fire(new FileOperationEvent(source, mode === 'move' ? FileOperation.MOVE : FileOperation.COPY, fileStat));
this.onDidRunOperationEmitter.fire(new FileOperationEvent(source, mode === 'move' ? FileOperation.MOVE : FileOperation.COPY, fileStat));

return fileStat;
}
Expand All @@ -549,7 +542,7 @@ export class FileService {

// resolve and send events
const fileStat = await this.resolve(target, { resolveMetadata: true });
this._onDidRunOperation.fire(new FileOperationEvent(source, mode === 'copy' ? FileOperation.COPY : FileOperation.MOVE, fileStat));
this.onDidRunOperationEmitter.fire(new FileOperationEvent(source, mode === 'copy' ? FileOperation.COPY : FileOperation.MOVE, fileStat));

return fileStat;
}
Expand Down Expand Up @@ -703,7 +696,7 @@ export class FileService {

// events
const fileStat = await this.resolve(resource, { resolveMetadata: true });
this._onDidRunOperation.fire(new FileOperationEvent(resource, FileOperation.CREATE, fileStat));
this.onDidRunOperationEmitter.fire(new FileOperationEvent(resource, FileOperation.CREATE, fileStat));

return fileStat;
}
Expand Down Expand Up @@ -785,15 +778,15 @@ export class FileService {
await provider.delete(resource, { recursive, useTrash });

// Events
this._onDidRunOperation.fire(new FileOperationEvent(resource, FileOperation.DELETE));
this.onDidRunOperationEmitter.fire(new FileOperationEvent(resource, FileOperation.DELETE));
}

// #endregion

// #region File Watching

private _onDidFilesChange = this._register(new Emitter<FileChangesEvent>());
readonly onDidFilesChange = this._onDidFilesChange.event;
private onDidFilesChangeEmitter = new Emitter<FileChangesEvent>();
readonly onDidFilesChange = this.onDidFilesChangeEmitter.event;

private activeWatchers = new Map<string, { disposable: Disposable, count: number }>();

Expand Down Expand Up @@ -848,13 +841,6 @@ export class FileService {
].join();
}

dispose(): void {
this.toDispose.dispose();

this.activeWatchers.forEach(watcher => watcher.disposable.dispose());
this.activeWatchers.clear();
}

// #endregion

// #region Helpers
Expand Down
6 changes: 6 additions & 0 deletions packages/filesystem/src/browser/filesystem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ These have precedence over the default associations of the languages installed.'
'scope': 'language-overridable',
'included': Object.keys(SUPPORTED_ENCODINGS).length > 1
},
'files.participants.timeout': {
type: 'number',
default: 5000,
markdownDescription: 'Timeout in milliseconds after which file participants for create, rename, and delete are cancelled. Use `0` to disable participants.'
}
}
};

Expand All @@ -81,6 +86,7 @@ export interface FileSystemConfiguration {
'files.associations': { [filepattern: string]: string };
'files.encoding': string;
'files.autoGuessEncoding': boolean;
'files.participants.timeout': number;
}

export const FileSystemPreferences = Symbol('FileSystemPreferences');
Expand Down
45 changes: 0 additions & 45 deletions packages/filesystem/src/browser/text-file-service.ts

This file was deleted.

Loading

0 comments on commit d8151fe

Please sign in to comment.