提交 2aa549d5 编写于 作者: J Johannes Rieken

starting with remote file service

上级 6da138c8
......@@ -57,7 +57,8 @@ import { ContextKeyExpr, RawContextKey, IContextKeyService, IContextKey } from '
import { IActivityBarService } from 'vs/workbench/services/activity/common/activityBarService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
import { FileService } from 'vs/workbench/services/files/electron-browser/fileService';
// import { FileService } from 'vs/workbench/services/files/electron-browser/fileService';
import { RemoteFileService } from "vs/workbench/services/files/electron-browser/remoteFileService";
import { IFileService } from 'vs/platform/files/common/files';
import { IListService, ListService } from 'vs/platform/list/browser/listService';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
......@@ -561,7 +562,7 @@ export class Workbench implements IPartService {
serviceCollection.set(ITitleService, this.titlebarPart);
// File Service
const fileService = this.instantiationService.createInstance(FileService);
const fileService = this.instantiationService.createInstance(RemoteFileService);
serviceCollection.set(IFileService, fileService);
this.toDispose.push(fileService.onFileChanges(e => this.configurationService.handleWorkspaceFileEvents(e)));
......
......@@ -41,7 +41,7 @@ export class FileService implements IFileService {
private toUnbind: IDisposable[];
private activeOutOfWorkspaceWatchers: ResourceMap<uri>;
private _onFileChanges: Emitter<FileChangesEvent>;
protected _onFileChanges: Emitter<FileChangesEvent>;
private _onAfterOperation: Emitter<FileOperationEvent>;
constructor(
......@@ -310,4 +310,4 @@ export class FileService implements IFileService {
// Dispose service
this.raw.dispose();
}
}
\ No newline at end of file
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import URI from 'vs/base/common/uri';
import { FileService } from 'vs/workbench/services/files/electron-browser/fileService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IMessageService } from 'vs/platform/message/common/message';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IContent, IStreamContent, IFileStat, IResolveContentOptions, IUpdateContentOptions, FileChangesEvent, FileChangeType } from "vs/platform/files/common/files";
import { TPromise } from "vs/base/common/winjs.base";
import Event from "vs/base/common/event";
import { EventEmitter } from "events";
import { basename } from "path";
import { IDisposable } from "vs/base/common/lifecycle";
export interface IRemoteFileProvider {
onDidChange: Event<URI>;
resolve(resource: URI): TPromise<string>;
update(resource: URI, content: string): TPromise<any>;
}
export class RemoteFileService extends FileService {
private readonly _remoteAuthority: string;
private _provider: IRemoteFileProvider;
constructor(
@IConfigurationService configurationService: IConfigurationService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEnvironmentService environmentService: IEnvironmentService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@ILifecycleService lifecycleService: ILifecycleService,
@IMessageService messageService: IMessageService,
@IStorageService storageService: IStorageService
) {
super(configurationService, contextService, editorService, environmentService, editorGroupService, lifecycleService, messageService, storageService);
this._remoteAuthority = environmentService.args['remote'];
this.registerProvider(new class implements IRemoteFileProvider {
onDidChange: Event<URI> = Event.None;
resolve(resource: URI): TPromise<string> {
return TPromise.as(JSON.stringify(resource, undefined, 4));
}
update(resource: URI, content: string): TPromise<any> {
return TPromise.as(undefined);
}
});
}
private _shouldIntercept(resource: URI): boolean {
return this._provider && resource.authority === this._remoteAuthority;
}
registerProvider(provider: IRemoteFileProvider): IDisposable {
this._provider = provider;
const reg = this._provider.onDidChange(e => {
// forward change events
this._onFileChanges.fire(new FileChangesEvent([{ resource: e, type: FileChangeType.UPDATED }]));
});
return {
dispose: () => {
reg.dispose();
this._provider = undefined;
}
};
}
// --- resolve
resolveContent(resource: URI, options?: IResolveContentOptions): TPromise<IContent> {
if (this._shouldIntercept(resource)) {
return this._doResolveContent(resource);
}
return super.resolveContent(resource, options);
}
resolveStreamContent(resource: URI, options?: IResolveContentOptions): TPromise<IStreamContent> {
if (this._shouldIntercept(resource)) {
return this._doResolveContent(resource).then(RemoteFileService._asStreamContent);
}
return super.resolveStreamContent(resource, options);
}
private async _doResolveContent(resource: URI): TPromise<IContent> {
const stat = RemoteFileService._createFakeStat(resource);
const value = await this._provider.resolve(resource);
return <any>{ ...stat, value };
}
// --- saving
updateContent(resource: URI, value: string, options?: IUpdateContentOptions): TPromise<IFileStat> {
if (this._shouldIntercept(resource)) {
return this._doUpdateContent(resource, value).then(RemoteFileService._createFakeStat);
}
return super.updateContent(resource, value, options);
}
private async _doUpdateContent(resource: URI, content: string): TPromise<URI> {
await this._provider.update(resource, content);
return resource;
}
// --- util
private static _createFakeStat(resource: URI): IFileStat {
return <IFileStat>{
resource,
name: basename(resource.path),
encoding: 'utf8',
mtime: Date.now(),
etag: Date.now().toString(16),
isDirectory: false,
hasChildren: false
};
}
private static _asStreamContent(content: IContent): IStreamContent {
const emitter = new EventEmitter();
const { value } = content;
const result = <IStreamContent><any>content;
result.value = emitter;
setTimeout(() => {
emitter.emit('data', value);
emitter.emit('end');
}, 0);
return result;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册