workbenchTestServices.ts 52.6 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import 'vs/workbench/contrib/files/browser/files.contribution'; // load our contribution into the test
7
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
8
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
9
import { join } from 'vs/base/common/path';
10
import * as resources from 'vs/base/common/resources';
11
import { URI, UriComponents } from 'vs/base/common/uri';
12 13
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
14 15
import { ConfirmResult, IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent, IEditorPartOptions } from 'vs/workbench/common/editor';
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
M
Matt Bierner 已提交
16
import { Event, Emitter } from 'vs/base/common/event';
E
Erich Gamma 已提交
17
import Severity from 'vs/base/common/severity';
18
import { IBackupFileService, IResolvedBackup } from 'vs/workbench/services/backup/common/backup';
19
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
B
Benjamin Pasero 已提交
20
import { IWorkbenchLayoutService, Parts, Position as PartPosition } from 'vs/workbench/services/layout/browser/layoutService';
21
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
22
import { ITextModelService } from 'vs/editor/common/services/resolverService';
B
Benjamin Pasero 已提交
23
import { IEditorOptions, IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
24
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
S
Sandeep Somavarapu 已提交
25
import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, Workspace } from 'vs/platform/workspace/common/workspace';
26
import { ILifecycleService, BeforeShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, WillShutdownEvent } from 'vs/platform/lifecycle/common/lifecycle';
J
Johannes Rieken 已提交
27
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
28
import { FileOperationEvent, IFileService, FileOperationError, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, ICreateFileOptions, IFileSystemProvider, FileSystemProviderCapabilities, IFileChange, IWatchOptions, IStat, FileType, FileDeleteOptions, FileOverwriteOptions, FileWriteOptions, FileOpenOptions, IFileStatWithMetadata, IResolveMetadataFileOptions, IWriteFileOptions, IReadFileOptions, IFileContent, IFileStreamContent } from 'vs/platform/files/common/files';
29
import { IModelService } from 'vs/editor/common/services/modelService';
30
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
J
Johannes Rieken 已提交
31
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
32
import { ITextFileStreamContent, ITextFileService, IResourceEncoding, IReadTextFileOptions } from 'vs/workbench/services/textfile/common/textfiles';
33
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
J
Johannes Rieken 已提交
34 35
import { IModeService } from 'vs/editor/common/services/modeService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
36
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
37
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
38
import { MenuBarVisibility, IWindowConfiguration, IWindowOpenable, IOpenWindowOptions, IOpenEmptyWindowOptions, IOpenedWindow } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
39
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
B
Benjamin Pasero 已提交
40
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
41
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
42
import { IThemeService } from 'vs/platform/theme/common/themeService';
B
Benjamin Pasero 已提交
43
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
44
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
S
Sandeep Somavarapu 已提交
45
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
46
import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position';
47
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
I
isidor 已提交
48
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
B
Benjamin Pasero 已提交
49
import { MockContextKeyService, MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
50
import { ITextBufferFactory, DefaultEndOfLine, EndOfLinePreference, IModelDecorationOptions, ITextModel, ITextSnapshot } from 'vs/editor/common/model';
51
import { Range } from 'vs/editor/common/core/range';
52
import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions, IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService, IShowResult } from 'vs/platform/dialogs/common/dialogs';
53 54
import { INotificationService } from 'vs/platform/notification/common/notification';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
55
import { IExtensionService, NullExtensionService } from 'vs/workbench/services/extensions/common/extensions';
B
Benjamin Pasero 已提交
56
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
B
Benjamin Pasero 已提交
57
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
J
Joao Moreno 已提交
58
import { IDisposable, toDisposable, Disposable } from 'vs/base/common/lifecycle';
59
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, EditorsOrder, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions } from 'vs/workbench/services/editor/common/editorGroupsService';
60
import { IEditorService, IOpenEditorOverrideHandler, IVisibleEditor } from 'vs/workbench/services/editor/common/editorService';
B
Benjamin Pasero 已提交
61 62 63
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
B
Benjamin Pasero 已提交
64
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
65
import { Dimension } from 'vs/base/browser/dom';
S
Sandeep Somavarapu 已提交
66
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
I
isidor 已提交
67
import { ILabelService } from 'vs/platform/label/common/label';
68
import { timeout } from 'vs/base/common/async';
69
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
70
import { ViewletDescriptor, Viewlet } from 'vs/workbench/browser/viewlet';
71
import { IViewlet } from 'vs/workbench/common/viewlet';
72
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
73
import { isLinux, isMacintosh, IProcessEnvironment } from 'vs/base/common/platform';
I
isidor 已提交
74
import { LabelService } from 'vs/workbench/services/label/common/labelService';
B
Benjamin Pasero 已提交
75
import { IDimension } from 'vs/platform/layout/browser/layoutService';
76
import { Part } from 'vs/workbench/browser/part';
77 78 79
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPanel } from 'vs/workbench/common/panel';
import { IBadge } from 'vs/workbench/services/activity/common/activity';
80
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
81 82
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { WorkbenchEnvironmentService } from 'vs/workbench/services/environment/node/environmentService';
83
import { VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
84
import { NativeTextFileService } from 'vs/workbench/services/textfile/electron-browser/nativeTextFileService';
85
import { Schemas } from 'vs/base/common/network';
86
import { IProductService } from 'vs/platform/product/common/productService';
87
import product from 'vs/platform/product/common/product';
88
import { IHostService } from 'vs/workbench/services/host/browser/host';
89
import { IElectronService } from 'vs/platform/electron/node/electron';
90
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/node/dialogs';
91 92 93
import { IBackupMainService, IWorkspaceBackupInfo } from 'vs/platform/backup/electron-main/backup';
import { IEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogs';
94
import { find } from 'vs/base/common/arrays';
B
Benjamin Pasero 已提交
95

S
Sandeep Somavarapu 已提交
96
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
97
	return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined);
S
Sandeep Somavarapu 已提交
98 99
}

100
export const TestEnvironmentService = new WorkbenchEnvironmentService(parseArgs(process.argv, OPTIONS) as IWindowConfiguration, process.execPath, 0);
101

102
export class TestContextService implements IWorkspaceContextService {
103
	public _serviceBrand: undefined;
E
Erich Gamma 已提交
104

S
Sandeep Somavarapu 已提交
105
	private workspace: Workspace;
E
Erich Gamma 已提交
106 107
	private options: any;

M
Matt Bierner 已提交
108 109 110
	private readonly _onDidChangeWorkspaceName: Emitter<void>;
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent>;
	private readonly _onDidChangeWorkbenchState: Emitter<WorkbenchState>;
111

112
	constructor(workspace: any = TestWorkspace, options: any = null) {
E
Erich Gamma 已提交
113
		this.workspace = workspace;
114
		this.options = options || Object.create(null);
B
Benjamin Pasero 已提交
115
		this._onDidChangeWorkspaceName = new Emitter<void>();
116
		this._onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
S
Sandeep Somavarapu 已提交
117
		this._onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
118 119
	}

S
Sandeep Somavarapu 已提交
120 121 122 123
	public get onDidChangeWorkspaceName(): Event<void> {
		return this._onDidChangeWorkspaceName.event;
	}

124
	public get onDidChangeWorkspaceFolders(): Event<IWorkspaceFoldersChangeEvent> {
S
Sandeep Somavarapu 已提交
125
		return this._onDidChangeWorkspaceFolders.event;
126 127
	}

128 129 130 131
	public get onDidChangeWorkbenchState(): Event<WorkbenchState> {
		return this._onDidChangeWorkbenchState.event;
	}

S
Sandeep Somavarapu 已提交
132
	public getFolders(): IWorkspaceFolder[] {
S
Sandeep Somavarapu 已提交
133
		return this.workspace ? this.workspace.folders : [];
E
Erich Gamma 已提交
134 135
	}

136
	public getWorkbenchState(): WorkbenchState {
B
Benjamin Pasero 已提交
137 138 139 140 141
		if (this.workspace.configuration) {
			return WorkbenchState.WORKSPACE;
		}

		if (this.workspace.folders.length) {
142
			return WorkbenchState.FOLDER;
143
		}
B
Benjamin Pasero 已提交
144

145
		return WorkbenchState.EMPTY;
S
Sandeep Somavarapu 已提交
146 147
	}

148 149 150 151
	getCompleteWorkspace(): Promise<IWorkbenchWorkspace> {
		return Promise.resolve(this.getWorkspace());
	}

152
	public getWorkspace(): IWorkbenchWorkspace {
B
Benjamin Pasero 已提交
153
		return this.workspace;
154 155
	}

156
	public getWorkspaceFolder(resource: URI): IWorkspaceFolder | null {
S
Sandeep Somavarapu 已提交
157
		return this.workspace.getFolder(resource);
158 159
	}

D
Daniel Imms 已提交
160 161 162 163
	public setWorkspace(workspace: any): void {
		this.workspace = workspace;
	}

E
Erich Gamma 已提交
164 165 166 167 168 169 170 171 172 173
	public getOptions() {
		return this.options;
	}

	public updateOptions() {

	}

	public isInsideWorkspace(resource: URI): boolean {
		if (resource && this.workspace) {
174
			return resources.isEqualOrParent(resource, this.workspace.folders[0].uri);
E
Erich Gamma 已提交
175 176 177 178 179 180
		}

		return false;
	}

	public toResource(workspaceRelativePath: string): URI {
181
		return URI.file(join('C:\\', workspaceRelativePath));
E
Erich Gamma 已提交
182
	}
183

184
	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
185
		return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) && resources.isEqual(this.workspace.folders[0].uri, workspaceIdentifier);
186
	}
E
Erich Gamma 已提交
187 188
}

189
export class TestTextFileService extends NativeTextFileService {
190
	public cleanupBackupsBeforeShutdownCalled!: boolean;
191

192 193 194
	private promptPath!: URI;
	private confirmResult!: ConfirmResult;
	private resolveTextContentError!: FileOperationError | null;
A
Alex Dima 已提交
195 196

	constructor(
197
		@IWorkspaceContextService contextService: IWorkspaceContextService,
198
		@IFileService protected fileService: IFileService,
199
		@IUntitledEditorService untitledEditorService: IUntitledEditorService,
200
		@ILifecycleService lifecycleService: ILifecycleService,
201
		@IInstantiationService instantiationService: IInstantiationService,
202 203 204
		@IConfigurationService configurationService: IConfigurationService,
		@IModeService modeService: IModeService,
		@IModelService modelService: IModelService,
205
		@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
206
		@INotificationService notificationService: INotificationService,
207
		@IBackupFileService backupFileService: IBackupFileService,
I
isidor 已提交
208
		@IHistoryService historyService: IHistoryService,
B
Benjamin Pasero 已提交
209
		@IContextKeyService contextKeyService: IContextKeyService,
210 211
		@IDialogService dialogService: IDialogService,
		@IFileDialogService fileDialogService: IFileDialogService,
B
Benjamin Pasero 已提交
212
		@IEditorService editorService: IEditorService,
213 214
		@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
		@IElectronService electronService: IElectronService
A
Alex Dima 已提交
215
	) {
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
		super(
			contextService,
			fileService,
			untitledEditorService,
			lifecycleService,
			instantiationService,
			configurationService,
			modeService,
			modelService,
			environmentService,
			notificationService,
			backupFileService,
			historyService,
			contextKeyService,
			dialogService,
			fileDialogService,
B
Benjamin Pasero 已提交
232
			editorService,
233 234
			textResourceConfigurationService,
			electronService
235
		);
A
Alex Dima 已提交
236
	}
237

M
Martin Aeschlimann 已提交
238
	public setPromptPath(path: URI): void {
239 240 241 242 243 244 245
		this.promptPath = path;
	}

	public setConfirmResult(result: ConfirmResult): void {
		this.confirmResult = result;
	}

246
	public setResolveTextContentErrorOnce(error: FileOperationError): void {
247 248 249
		this.resolveTextContentError = error;
	}

250
	public readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent> {
251 252 253 254
		if (this.resolveTextContentError) {
			const error = this.resolveTextContentError;
			this.resolveTextContentError = null;

B
Benjamin Pasero 已提交
255
			return Promise.reject(error);
256 257
		}

B
Benjamin Pasero 已提交
258
		return this.fileService.readFileStream(resource, options).then(async (content): Promise<ITextFileStreamContent> => {
259
			return {
260
				resource: content.resource,
261 262 263
				name: content.name,
				mtime: content.mtime,
				etag: content.etag,
B
Benjamin Pasero 已提交
264 265 266
				encoding: 'utf8',
				value: await createTextBufferFactoryFromStream(content.value),
				size: 10
267 268 269
			};
		});
	}
270

J
Johannes Rieken 已提交
271
	public promptForPath(_resource: URI, _defaultPath: URI): Promise<URI> {
B
Benjamin Pasero 已提交
272
		return Promise.resolve(this.promptPath);
273 274
	}

J
Johannes Rieken 已提交
275
	public confirmSave(_resources?: URI[]): Promise<ConfirmResult> {
B
Benjamin Pasero 已提交
276
		return Promise.resolve(this.confirmResult);
277 278
	}

B
Benjamin Pasero 已提交
279 280
	public confirmOverwrite(_resource: URI): Promise<boolean> {
		return Promise.resolve(true);
281
	}
D
Daniel Imms 已提交
282

283 284
	public onFilesConfigurationChange(configuration: any): void {
		super.onFilesConfigurationChange(configuration);
285 286
	}

J
Johannes Rieken 已提交
287
	protected cleanupBackupsBeforeShutdown(): Promise<void> {
288
		this.cleanupBackupsBeforeShutdownCalled = true;
B
Benjamin Pasero 已提交
289
		return Promise.resolve();
290
	}
A
Alex Dima 已提交
291 292
}

293
export function workbenchInstantiationService(): IInstantiationService {
294
	let instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
295
	instantiationService.stub(IEnvironmentService, TestEnvironmentService);
I
isidor 已提交
296
	instantiationService.stub(IContextKeyService, <IContextKeyService>instantiationService.createInstance(MockContextKeyService));
I
isidor 已提交
297 298
	const workspaceContextService = new TestContextService(TestWorkspace);
	instantiationService.stub(IWorkspaceContextService, workspaceContextService);
299 300 301
	const configService = new TestConfigurationService();
	instantiationService.stub(IConfigurationService, configService);
	instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
302
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
303
	instantiationService.stub(IStorageService, new TestStorageService());
304
	instantiationService.stub(IWorkbenchLayoutService, new TestLayoutService());
305
	instantiationService.stub(IElectronService, new TestElectronService());
J
Johannes Rieken 已提交
306
	instantiationService.stub(IModeService, instantiationService.createInstance(ModeServiceImpl));
B
Benjamin Pasero 已提交
307
	instantiationService.stub(IHistoryService, new TestHistoryService());
S
Sandeep Somavarapu 已提交
308
	instantiationService.stub(ITextResourcePropertiesService, new TestTextResourcePropertiesService(configService));
S
Sandeep Somavarapu 已提交
309
	instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
310
	instantiationService.stub(IFileService, new TestFileService());
311
	instantiationService.stub(IBackupFileService, new TestBackupFileService());
312
	instantiationService.stub(ITelemetryService, NullTelemetryService);
313
	instantiationService.stub(INotificationService, new TestNotificationService());
B
Benjamin Pasero 已提交
314
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
B
Benjamin Pasero 已提交
315 316 317 318
	instantiationService.stub(IMenuService, new TestMenuService());
	instantiationService.stub(IKeybindingService, new MockKeybindingService());
	instantiationService.stub(IDecorationsService, new TestDecorationsService());
	instantiationService.stub(IExtensionService, new TestExtensionService());
319
	instantiationService.stub(IHostService, <IHostService>instantiationService.createInstance(TestHostService));
320
	instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(TestTextFileService));
321
	instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
B
Benjamin Pasero 已提交
322
	instantiationService.stub(IThemeService, new TestThemeService());
S
Sandeep Somavarapu 已提交
323
	instantiationService.stub(ILogService, new NullLogService());
324
	instantiationService.stub(IEditorGroupsService, new TestEditorGroupsService([new TestEditorGroup(0)]));
M
Martin Aeschlimann 已提交
325
	instantiationService.stub(ILabelService, <ILabelService>instantiationService.createInstance(LabelService));
B
Benjamin Pasero 已提交
326
	const editorService = new TestEditorService();
327
	instantiationService.stub(IEditorService, editorService);
B
Benjamin Pasero 已提交
328
	instantiationService.stub(ICodeEditorService, new TestCodeEditorService());
329
	instantiationService.stub(IViewletService, new TestViewletService());
330 331 332 333

	return instantiationService;
}

B
Benjamin Pasero 已提交
334
export class TestDecorationsService implements IDecorationsService {
335
	_serviceBrand: undefined;
B
Benjamin Pasero 已提交
336
	onDidChangeDecorations: Event<IResourceDecorationChangeEvent> = Event.None;
337
	registerDecorationsProvider(_provider: IDecorationsProvider): IDisposable { return Disposable.None; }
338
	getDecoration(_uri: URI, _includeChildren: boolean, _overwrite?: IDecorationData): IDecoration | undefined { return undefined; }
B
Benjamin Pasero 已提交
339 340
}

341
export class TestExtensionService extends NullExtensionService { }
B
Benjamin Pasero 已提交
342 343 344

export class TestMenuService implements IMenuService {

345
	public _serviceBrand: undefined;
B
Benjamin Pasero 已提交
346

347
	createMenu(_id: MenuId, _scopedKeybindingService: IContextKeyService): IMenu {
B
Benjamin Pasero 已提交
348 349
		return {
			onDidChange: Event.None,
R
Rob Lourens 已提交
350
			dispose: () => undefined,
B
Benjamin Pasero 已提交
351 352 353 354 355
			getActions: () => []
		};
	}
}

B
Benjamin Pasero 已提交
356 357
export class TestHistoryService implements IHistoryService {

358
	public _serviceBrand: undefined;
B
Benjamin Pasero 已提交
359 360 361 362 363 364 365

	constructor(private root?: URI) {
	}

	public reopenLastClosedEditor(): void {
	}

366
	public forward(_acrossEditors?: boolean): void {
B
Benjamin Pasero 已提交
367 368
	}

369
	public back(_acrossEditors?: boolean): void {
B
Benjamin Pasero 已提交
370 371
	}

372 373 374
	public last(): void {
	}

375
	public remove(_input: IEditorInput | IResourceInput): void {
B
Benjamin Pasero 已提交
376 377 378 379 380
	}

	public clear(): void {
	}

B
Benjamin Pasero 已提交
381 382 383
	public clearRecentlyOpened(): void {
	}

384
	public getHistory(): Array<IEditorInput | IResourceInput> {
B
Benjamin Pasero 已提交
385 386 387
		return [];
	}

388
	public getLastActiveWorkspaceRoot(_schemeFilter: string): URI | undefined {
B
Benjamin Pasero 已提交
389 390
		return this.root;
	}
391

392
	public getLastActiveFile(_schemeFilter: string): URI | undefined {
R
Rob Lourens 已提交
393
		return undefined;
394
	}
B
Benjamin Pasero 已提交
395 396 397

	public openLastEditLocation(): void {
	}
B
Benjamin Pasero 已提交
398 399
}

400
export class TestDialogService implements IDialogService {
401

402
	public _serviceBrand: undefined;
E
Erich Gamma 已提交
403

J
Johannes Rieken 已提交
404
	public confirm(_confirmation: IConfirmation): Promise<IConfirmationResult> {
B
Benjamin Pasero 已提交
405
		return Promise.resolve({ confirmed: false });
406
	}
407

408 409
	public show(_severity: Severity, _message: string, _buttons: string[], _options?: IDialogOptions): Promise<IShowResult> {
		return Promise.resolve({ choice: 0 });
410
	}
411 412 413 414

	public about(): Promise<void> {
		return Promise.resolve();
	}
E
Erich Gamma 已提交
415 416
}

M
Martin Aeschlimann 已提交
417 418
export class TestFileDialogService implements IFileDialogService {

419
	public _serviceBrand: undefined;
M
Martin Aeschlimann 已提交
420

421
	public defaultFilePath(_schemeFilter?: string): URI | undefined {
R
Rob Lourens 已提交
422
		return undefined;
M
Martin Aeschlimann 已提交
423
	}
424
	public defaultFolderPath(_schemeFilter?: string): URI | undefined {
R
Rob Lourens 已提交
425
		return undefined;
M
Martin Aeschlimann 已提交
426
	}
427
	public defaultWorkspacePath(_schemeFilter?: string): URI | undefined {
R
Rob Lourens 已提交
428
		return undefined;
M
Martin Aeschlimann 已提交
429
	}
J
Johannes Rieken 已提交
430
	public pickFileFolderAndOpen(_options: IPickAndOpenOptions): Promise<any> {
B
Benjamin Pasero 已提交
431
		return Promise.resolve(0);
M
Martin Aeschlimann 已提交
432
	}
J
Johannes Rieken 已提交
433
	public pickFileAndOpen(_options: IPickAndOpenOptions): Promise<any> {
B
Benjamin Pasero 已提交
434
		return Promise.resolve(0);
M
Martin Aeschlimann 已提交
435
	}
J
Johannes Rieken 已提交
436
	public pickFolderAndOpen(_options: IPickAndOpenOptions): Promise<any> {
B
Benjamin Pasero 已提交
437
		return Promise.resolve(0);
M
Martin Aeschlimann 已提交
438
	}
J
Johannes Rieken 已提交
439
	public pickWorkspaceAndOpen(_options: IPickAndOpenOptions): Promise<any> {
B
Benjamin Pasero 已提交
440
		return Promise.resolve(0);
M
Martin Aeschlimann 已提交
441
	}
442 443 444
	public pickFileToSave(_options: ISaveDialogOptions): Promise<URI | undefined> {
		return Promise.resolve(undefined);
	}
445
	public showSaveDialog(_options: ISaveDialogOptions): Promise<URI | undefined> {
J
Johannes Rieken 已提交
446
		return Promise.resolve(undefined);
M
Martin Aeschlimann 已提交
447
	}
448
	public showOpenDialog(_options: IOpenDialogOptions): Promise<URI[] | undefined> {
J
Johannes Rieken 已提交
449
		return Promise.resolve(undefined);
M
Martin Aeschlimann 已提交
450 451 452
	}
}

453
export class TestLayoutService implements IWorkbenchLayoutService {
B
Benjamin Pasero 已提交
454

455
	public _serviceBrand: undefined;
E
Erich Gamma 已提交
456

457 458
	dimension: IDimension = { width: 800, height: 600 };

459 460
	container: HTMLElement = window.document.body;

B
Benjamin Pasero 已提交
461
	onZenModeChange: Event<boolean> = Event.None;
S
SteVen Batten 已提交
462 463
	onCenteredLayoutChange: Event<boolean> = Event.None;
	onFullscreenChange: Event<boolean> = Event.None;
464
	onPanelPositionChange: Event<string> = Event.None;
465
	onLayout = Event.None;
B
Benjamin Pasero 已提交
466

467 468
	private readonly _onTitleBarVisibilityChange = new Emitter<void>();
	private readonly _onMenubarVisibilityChange = new Emitter<Dimension>();
469 470 471 472 473

	public get onTitleBarVisibilityChange(): Event<void> {
		return this._onTitleBarVisibilityChange.event;
	}

474 475 476 477
	public get onMenubarVisibilityChange(): Event<Dimension> {
		return this._onMenubarVisibilityChange.event;
	}

B
Benjamin Pasero 已提交
478
	public isRestored(): boolean {
E
Erich Gamma 已提交
479 480 481
		return true;
	}

482
	public hasFocus(_part: Parts): boolean {
E
Erich Gamma 已提交
483 484 485
		return false;
	}

486
	public isVisible(_part: Parts): boolean {
E
Erich Gamma 已提交
487 488 489
		return true;
	}

490 491 492 493
	getDimension(_part: Parts): Dimension {
		return new Dimension(0, 0);
	}

494
	public getContainer(_part: Parts): HTMLElement {
B
Benjamin Pasero 已提交
495
		return null!;
496 497
	}

B
Benjamin Pasero 已提交
498 499 500 501
	public isTitleBarHidden(): boolean {
		return false;
	}

502 503 504 505
	public getTitleBarOffset(): number {
		return 0;
	}

506 507 508 509
	public isStatusBarHidden(): boolean {
		return false;
	}

S
Sanders Lauture 已提交
510 511 512 513
	public isActivityBarHidden(): boolean {
		return false;
	}

514
	public setActivityBarHidden(_hidden: boolean): void { }
S
Sanders Lauture 已提交
515

E
Erich Gamma 已提交
516 517 518 519
	public isSideBarHidden(): boolean {
		return false;
	}

520
	public setEditorHidden(_hidden: boolean): Promise<void> { return Promise.resolve(); }
S
SteVen Batten 已提交
521

522
	public setSideBarHidden(_hidden: boolean): Promise<void> { return Promise.resolve(); }
E
Erich Gamma 已提交
523

I
isidor 已提交
524
	public isPanelHidden(): boolean {
I
isidor 已提交
525 526 527
		return false;
	}

528
	public setPanelHidden(_hidden: boolean): Promise<void> { return Promise.resolve(); }
I
isidor 已提交
529

I
isidor 已提交
530 531
	public toggleMaximizedPanel(): void { }

B
Benjamin Pasero 已提交
532 533 534 535
	public isPanelMaximized(): boolean {
		return false;
	}

S
SteVen Batten 已提交
536
	public getMenubarVisibility(): MenuBarVisibility {
537
		throw new Error('not implemented');
S
SteVen Batten 已提交
538 539
	}

E
Erich Gamma 已提交
540 541 542 543
	public getSideBarPosition() {
		return 0;
	}

I
isidor 已提交
544 545 546 547
	public getPanelPosition() {
		return 0;
	}

J
Johannes Rieken 已提交
548
	public setPanelPosition(_position: PartPosition): Promise<void> {
549
		return Promise.resolve();
I
isidor 已提交
550 551
	}

552 553
	public addClass(_clazz: string): void { }
	public removeClass(_clazz: string): void { }
554

555 556
	public getMaximumEditorDimensions(): Dimension { throw new Error('not implemented'); }

557
	public getWorkbenchContainer(): HTMLElement { throw new Error('not implemented'); }
558
	public getWorkbenchElement(): HTMLElement { throw new Error('not implemented'); }
B
Benjamin Pasero 已提交
559

I
isidor 已提交
560
	public toggleZenMode(): void { }
561

B
Benjamin Pasero 已提交
562
	public isEditorLayoutCentered(): boolean { return false; }
563
	public centerEditorLayout(_active: boolean): void { }
S
SrTobi 已提交
564 565


566
	public resizePart(_part: Parts, _sizeChange: number): void { }
567 568

	public registerPart(part: Part): void { }
E
Erich Gamma 已提交
569 570
}

571
let activeViewlet: Viewlet = {} as any;
572

573
export class TestViewletService implements IViewletService {
574
	public _serviceBrand: undefined;
575 576 577 578 579 580 581 582 583 584 585

	onDidViewletRegisterEmitter = new Emitter<ViewletDescriptor>();
	onDidViewletDeregisterEmitter = new Emitter<ViewletDescriptor>();
	onDidViewletOpenEmitter = new Emitter<IViewlet>();
	onDidViewletCloseEmitter = new Emitter<IViewlet>();

	onDidViewletRegister = this.onDidViewletRegisterEmitter.event;
	onDidViewletDeregister = this.onDidViewletDeregisterEmitter.event;
	onDidViewletOpen = this.onDidViewletOpenEmitter.event;
	onDidViewletClose = this.onDidViewletCloseEmitter.event;

B
Benjamin Pasero 已提交
586 587
	public openViewlet(id: string, focus?: boolean): Promise<IViewlet | undefined> {
		return Promise.resolve(undefined);
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
	}

	public getViewlets(): ViewletDescriptor[] {
		return [];
	}

	public getAllViewlets(): ViewletDescriptor[] {
		return [];
	}

	public getActiveViewlet(): IViewlet {
		return activeViewlet;
	}

	public dispose() {
	}

	public getDefaultViewletId(): string {
		return 'workbench.view.explorer';
	}

	public getViewlet(id: string): ViewletDescriptor | undefined {
		return undefined;
	}

	public getProgressIndicator(id: string) {
B
Benjamin Pasero 已提交
614
		return undefined;
615
	}
616 617 618 619

	public hideActiveViewlet(): void { }

	public getLastActiveViewletId(): string {
M
Matt Bierner 已提交
620
		return undefined!;
621
	}
622 623 624
}

export class TestPanelService implements IPanelService {
625
	public _serviceBrand: undefined;
626 627 628 629

	onDidPanelOpen = new Emitter<{ panel: IPanel, focus: boolean }>().event;
	onDidPanelClose = new Emitter<IPanel>().event;

630 631
	public openPanel(id: string, focus?: boolean): undefined {
		return undefined;
632 633
	}

B
Benjamin Pasero 已提交
634 635 636 637
	public getPanel(id: string): any {
		return activeViewlet;
	}

638
	public getPanels() {
639 640 641
		return [];
	}

642
	public getPinnedPanels() {
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
		return [];
	}

	public getActivePanel(): IViewlet {
		return activeViewlet;
	}

	public setPanelEnablement(id: string, enabled: boolean): void { }

	public dispose() {
	}

	public showActivity(panelId: string, badge: IBadge, clazz?: string): IDisposable {
		throw new Error('Method not implemented.');
	}

B
Benjamin Pasero 已提交
659 660 661 662
	public getProgressIndicator(id: string) {
		return null!;
	}

663 664 665
	public hideActivePanel(): void { }

	public getLastActivePanelId(): string {
M
Matt Bierner 已提交
666
		return undefined!;
667 668 669
	}
}

670
export class TestStorageService extends InMemoryStorageService { }
671

672 673
export class TestEditorGroupsService implements IEditorGroupsService {

674
	_serviceBrand: undefined;
675

B
Benjamin Pasero 已提交
676
	constructor(public groups: TestEditorGroup[] = []) { }
677

678
	onDidActiveGroupChange: Event<IEditorGroup> = Event.None;
B
Benjamin Pasero 已提交
679
	onDidActivateGroup: Event<IEditorGroup> = Event.None;
680 681 682
	onDidAddGroup: Event<IEditorGroup> = Event.None;
	onDidRemoveGroup: Event<IEditorGroup> = Event.None;
	onDidMoveGroup: Event<IEditorGroup> = Event.None;
683
	onDidGroupIndexChange: Event<IEditorGroup> = Event.None;
684
	onDidLayout: Event<IDimension> = Event.None;
685 686

	orientation: any;
R
Rob Lourens 已提交
687
	whenRestored: Promise<void> = Promise.resolve(undefined);
B
Benjamin Pasero 已提交
688
	willRestoreEditors = false;
689

J
Joao Moreno 已提交
690
	contentDimension = { width: 800, height: 600 };
691

692
	get activeGroup(): IEditorGroup {
693 694 695 696 697 698 699
		return this.groups[0];
	}

	get count(): number {
		return this.groups.length;
	}

700
	getGroups(_order?: GroupsOrder): ReadonlyArray<IEditorGroup> {
701 702 703
		return this.groups;
	}

704 705
	getGroup(identifier: number): IEditorGroup | undefined {
		return find(this.groups, group => group.id === identifier);
706 707
	}

708
	getLabel(_identifier: number): string {
709 710 711
		return 'Group 1';
	}

712
	findGroup(_scope: IFindGroupScope, _source?: number | IEditorGroup, _wrap?: boolean): IEditorGroup {
713
		throw new Error('not implemented');
714 715
	}

716
	activateGroup(_group: number | IEditorGroup): IEditorGroup {
717
		throw new Error('not implemented');
718 719
	}

B
Benjamin Pasero 已提交
720 721 722 723
	restoreGroup(_group: number | IEditorGroup): IEditorGroup {
		throw new Error('not implemented');
	}

724 725
	getSize(_group: number | IEditorGroup): { width: number, height: number } {
		return { width: 100, height: 100 };
726 727
	}

728
	setSize(_group: number | IEditorGroup, _size: { width: number, height: number }): void { }
729

730
	arrangeGroups(_arrangement: GroupsArrangement): void { }
731

732
	applyLayout(_layout: EditorGroupLayout): void { }
733

734
	setGroupOrientation(_orientation: any): void { }
735

736
	addGroup(_location: number | IEditorGroup, _direction: GroupDirection, _options?: IAddGroupOptions): IEditorGroup {
737
		throw new Error('not implemented');
738 739
	}

740
	removeGroup(_group: number | IEditorGroup): void { }
741

742
	moveGroup(_group: number | IEditorGroup, _location: number | IEditorGroup, _direction: GroupDirection): IEditorGroup {
743
		throw new Error('not implemented');
744 745
	}

746
	mergeGroup(_group: number | IEditorGroup, _target: number | IEditorGroup, _options?: IMergeGroupOptions): IEditorGroup {
747
		throw new Error('not implemented');
748 749
	}

750
	copyGroup(_group: number | IEditorGroup, _location: number | IEditorGroup, _direction: GroupDirection): IEditorGroup {
751
		throw new Error('not implemented');
752
	}
753 754 755 756 757 758 759

	centerLayout(active: boolean): void { }

	isLayoutCentered(): boolean {
		return false;
	}

760
	partOptions!: IEditorPartOptions;
761 762
	enforcePartOptions(options: IEditorPartOptions): IDisposable {
		return Disposable.None;
763 764 765
	}
}

B
Benjamin Pasero 已提交
766
export class TestEditorGroup implements IEditorGroupView {
767 768 769

	constructor(public id: number) { }

770
	get group(): EditorGroup { throw new Error('not implemented'); }
771 772 773 774 775
	activeControl!: IVisibleEditor;
	activeEditor!: IEditorInput;
	previewEditor!: IEditorInput;
	count!: number;
	disposed!: boolean;
B
Benjamin Pasero 已提交
776
	editors: ReadonlyArray<IEditorInput> = [];
777 778
	label!: string;
	index!: number;
R
Rob Lourens 已提交
779
	whenRestored: Promise<void> = Promise.resolve(undefined);
780 781 782 783 784
	element!: HTMLElement;
	minimumWidth!: number;
	maximumWidth!: number;
	minimumHeight!: number;
	maximumHeight!: number;
785

786 787 788
	isEmpty = true;
	isMinimized = false;

789
	onWillDispose: Event<void> = Event.None;
790
	onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
B
Benjamin Pasero 已提交
791 792
	onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
793 794
	onWillOpenEditor: Event<IEditorOpeningEvent> = Event.None;
	onDidOpenEditorFail: Event<IEditorInput> = Event.None;
B
Benjamin Pasero 已提交
795 796
	onDidFocus: Event<void> = Event.None;
	onDidChange: Event<{ width: number; height: number; }> = Event.None;
797

798
	getEditors(_order?: EditorsOrder): ReadonlyArray<IEditorInput> {
B
Benjamin Pasero 已提交
799 800 801
		return [];
	}

802
	getEditor(_index: number): IEditorInput {
803
		throw new Error('not implemented');
804 805
	}

806
	getIndexOfEditor(_editor: IEditorInput): number {
807 808 809
		return -1;
	}

J
Johannes Rieken 已提交
810
	openEditor(_editor: IEditorInput, _options?: IEditorOptions): Promise<IEditor> {
811
		throw new Error('not implemented');
812 813
	}

J
Johannes Rieken 已提交
814
	openEditors(_editors: IEditorInputWithOptions[]): Promise<IEditor> {
815
		throw new Error('not implemented');
816 817
	}

818
	isOpened(_editor: IEditorInput): boolean {
819 820 821
		return false;
	}

822
	isPinned(_editor: IEditorInput): boolean {
823 824 825
		return false;
	}

826
	isActive(_editor: IEditorInput): boolean {
827 828 829
		return false;
	}

830
	moveEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IMoveEditorOptions): void { }
831

832
	copyEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: ICopyEditorOptions): void { }
833

834
	closeEditor(_editor?: IEditorInput, options?: ICloseEditorOptions): Promise<void> {
B
Benjamin Pasero 已提交
835
		return Promise.resolve();
836 837
	}

838
	closeEditors(_editors: IEditorInput[] | { except?: IEditorInput; direction?: CloseDirection; savedOnly?: boolean; }, options?: ICloseEditorOptions): Promise<void> {
B
Benjamin Pasero 已提交
839
		return Promise.resolve();
840 841
	}

J
Johannes Rieken 已提交
842
	closeAllEditors(): Promise<void> {
B
Benjamin Pasero 已提交
843
		return Promise.resolve();
844 845
	}

J
Johannes Rieken 已提交
846
	replaceEditors(_editors: IEditorReplacement[]): Promise<void> {
B
Benjamin Pasero 已提交
847
		return Promise.resolve();
848 849
	}

850
	pinEditor(_editor?: IEditorInput): void { }
851 852 853 854

	focus(): void { }

	invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T {
855
		throw new Error('not implemented');
856
	}
B
Benjamin Pasero 已提交
857

858
	setActive(_isActive: boolean): void { }
B
Benjamin Pasero 已提交
859
	notifyIndexChanged(_index: number): void { }
B
Benjamin Pasero 已提交
860 861
	dispose(): void { }
	toJSON(): object { return Object.create(null); }
862
	layout(_width: number, _height: number): void { }
863
	relayout() { }
864 865
}

B
Benjamin Pasero 已提交
866
export class TestEditorService implements EditorServiceImpl {
867

868
	_serviceBrand: undefined;
869 870 871

	onDidActiveEditorChange: Event<void> = Event.None;
	onDidVisibleEditorsChange: Event<void> = Event.None;
B
Benjamin Pasero 已提交
872
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
873 874
	onDidOpenEditorFail: Event<IEditorIdentifier> = Event.None;

875
	activeControl!: IVisibleEditor;
876
	activeTextEditorWidget: any;
877
	activeEditor!: IEditorInput;
878
	editors: ReadonlyArray<IEditorInput> = [];
M
Matt Bierner 已提交
879
	visibleControls: ReadonlyArray<IVisibleEditor> = [];
880
	visibleTextEditorWidgets = [];
B
Benjamin Pasero 已提交
881
	visibleEditors: ReadonlyArray<IEditorInput> = [];
882

883
	overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable {
R
Rob Lourens 已提交
884
		return toDisposable(() => undefined);
885 886
	}

887 888
	openEditor(_editor: any, _options?: any, _group?: any): Promise<any> {
		throw new Error('not implemented');
889 890
	}

891 892
	openEditors(_editors: any, _group?: any): Promise<IEditor[]> {
		throw new Error('not implemented');
893 894
	}

895
	isOpen(_editor: IEditorInput | IResourceInput | IUntitledResourceInput): boolean {
896 897 898
		return false;
	}

899
	getOpened(_editor: IEditorInput | IResourceInput | IUntitledResourceInput): IEditorInput {
900
		throw new Error('not implemented');
901 902
	}

903
	replaceEditors(_editors: any, _group: any) {
R
Rob Lourens 已提交
904
		return Promise.resolve(undefined);
905 906
	}

907
	invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
908
		throw new Error('not implemented');
909 910
	}

911
	createInput(_input: IResourceInput | IUntitledResourceInput | IResourceDiffInput | IResourceSideBySideInput): IEditorInput {
912
		throw new Error('not implemented');
913 914 915
	}
}

916 917
export class TestFileService implements IFileService {

918
	public _serviceBrand: undefined;
919

M
Matt Bierner 已提交
920 921
	private readonly _onFileChanges: Emitter<FileChangesEvent>;
	private readonly _onAfterOperation: Emitter<FileOperationEvent>;
922

923
	readonly onWillActivateFileSystemProvider = Event.None;
924
	readonly onError: Event<Error> = Event.None;
925

926
	private content = 'Hello Html';
927
	private lastReadFileUri!: URI;
928

929 930 931 932 933
	constructor() {
		this._onFileChanges = new Emitter<FileChangesEvent>();
		this._onAfterOperation = new Emitter<FileOperationEvent>();
	}

934 935 936 937 938 939 940 941
	public setContent(content: string): void {
		this.content = content;
	}

	public getContent(): string {
		return this.content;
	}

942 943 944 945
	public getLastReadFileUri(): URI {
		return this.lastReadFileUri;
	}

946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
	public get onFileChanges(): Event<FileChangesEvent> {
		return this._onFileChanges.event;
	}

	public fireFileChanges(event: FileChangesEvent): void {
		this._onFileChanges.fire(event);
	}

	public get onAfterOperation(): Event<FileOperationEvent> {
		return this._onAfterOperation.event;
	}

	public fireAfterOperation(event: FileOperationEvent): void {
		this._onAfterOperation.fire(event);
	}

B
Benjamin Pasero 已提交
962 963 964
	resolve(resource: URI, _options?: IResolveFileOptions): Promise<IFileStat>;
	resolve(resource: URI, _options: IResolveMetadataFileOptions): Promise<IFileStatWithMetadata>;
	resolve(resource: URI, _options?: IResolveFileOptions): Promise<IFileStat> {
B
Benjamin Pasero 已提交
965
		return Promise.resolve({
966 967
			resource,
			etag: Date.now().toString(),
B
Benjamin Pasero 已提交
968
			encoding: 'utf8',
B
Benjamin Pasero 已提交
969
			mtime: Date.now(),
970
			size: 42,
971
			isDirectory: false,
B
Benjamin Pasero 已提交
972
			name: resources.basename(resource)
B
Benjamin Pasero 已提交
973
		});
974
	}
B
Benjamin Pasero 已提交
975

B
Benjamin Pasero 已提交
976 977
	resolveAll(toResolve: { resource: URI, options?: IResolveFileOptions }[]): Promise<IResolveFileResult[]> {
		return Promise.all(toResolve.map(resourceAndOption => this.resolve(resourceAndOption.resource, resourceAndOption.options))).then(stats => stats.map(stat => ({ stat, success: true })));
I
isidor 已提交
978 979
	}

B
Benjamin Pasero 已提交
980
	exists(_resource: URI): Promise<boolean> {
B
Benjamin Pasero 已提交
981
		return Promise.resolve(true);
982
	}
B
Benjamin Pasero 已提交
983

984
	readFile(resource: URI, options?: IReadFileOptions | undefined): Promise<IFileContent> {
985 986
		this.lastReadFileUri = resource;

987
		return Promise.resolve({
B
Benjamin Pasero 已提交
988
			resource: resource,
989
			value: VSBuffer.fromString(this.content),
990
			etag: 'index.txt',
B
Benjamin Pasero 已提交
991 992
			encoding: 'utf8',
			mtime: Date.now(),
993 994
			name: resources.basename(resource),
			size: 1
E
Erich Gamma 已提交
995
		});
996
	}
E
Erich Gamma 已提交
997

998
	readFileStream(resource: URI, options?: IReadFileOptions | undefined): Promise<IFileStreamContent> {
999 1000
		this.lastReadFileUri = resource;

1001
		return Promise.resolve({
A
Alex Dima 已提交
1002 1003
			resource: resource,
			value: {
1004
				on: (event: string, callback: Function): void => {
A
Alex Dima 已提交
1005
					if (event === 'data') {
1006
						callback(this.content);
A
Alex Dima 已提交
1007 1008 1009 1010
					}
					if (event === 'end') {
						callback();
					}
B
Benjamin Pasero 已提交
1011 1012 1013 1014
				},
				resume: () => { },
				pause: () => { },
				destroy: () => { }
A
Alex Dima 已提交
1015 1016 1017
			},
			etag: 'index.txt',
			encoding: 'utf8',
B
Benjamin Pasero 已提交
1018
			mtime: Date.now(),
1019 1020
			size: 1,
			name: resources.basename(resource)
A
Alex Dima 已提交
1021
		});
1022 1023
	}

1024
	writeFile(resource: URI, bufferOrReadable: VSBuffer | VSBufferReadable, options?: IWriteFileOptions): Promise<IFileStatWithMetadata> {
B
Benjamin Pasero 已提交
1025
		return timeout(0).then(() => ({
1026 1027 1028 1029
			resource,
			etag: 'index.txt',
			encoding: 'utf8',
			mtime: Date.now(),
1030
			size: 42,
1031
			isDirectory: false,
B
Benjamin Pasero 已提交
1032
			name: resources.basename(resource)
B
Benjamin Pasero 已提交
1033
		}));
1034
	}
D
Daniel Imms 已提交
1035

B
Benjamin Pasero 已提交
1036
	move(_source: URI, _target: URI, _overwrite?: boolean): Promise<IFileStatWithMetadata> {
1037
		return Promise.resolve(null!);
1038
	}
D
Daniel Imms 已提交
1039

B
Benjamin Pasero 已提交
1040
	copy(_source: URI, _target: URI, _overwrite?: boolean): Promise<IFileStatWithMetadata> {
1041
		throw new Error('not implemented');
1042
	}
D
Daniel Imms 已提交
1043

1044
	createFile(_resource: URI, _content?: VSBuffer | VSBufferReadable, _options?: ICreateFileOptions): Promise<IFileStatWithMetadata> {
1045
		throw new Error('not implemented');
E
Erich Gamma 已提交
1046
	}
1047

1048
	createFolder(_resource: URI): Promise<IFileStatWithMetadata> {
1049
		throw new Error('not implemented');
1050 1051
	}

1052 1053
	onDidChangeFileSystemProviderRegistrations = Event.None;

1054 1055 1056 1057 1058 1059
	private providers = new Map<string, IFileSystemProvider>();

	registerProvider(scheme: string, provider: IFileSystemProvider) {
		this.providers.set(scheme, provider);

		return toDisposable(() => this.providers.delete(scheme));
1060 1061
	}

1062 1063
	activateProvider(_scheme: string): Promise<void> {
		throw new Error('not implemented');
1064 1065
	}

1066
	canHandleResource(resource: URI): boolean {
1067
		return resource.scheme === 'file' || this.providers.has(resource.scheme);
1068 1069
	}

1070
	hasCapability(resource: URI, capability: FileSystemProviderCapabilities): boolean { return false; }
1071

J
Johannes Rieken 已提交
1072
	del(_resource: URI, _options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> {
1073
		return Promise.resolve();
1074 1075
	}

1076 1077
	watch(_resource: URI): IDisposable {
		return Disposable.None;
1078 1079
	}

1080 1081
	getWriteEncoding(_resource: URI): IResourceEncoding {
		return { encoding: 'utf8', hasBOM: false };
1082
	}
D
Daniel Imms 已提交
1083

1084
	dispose(): void {
E
Erich Gamma 已提交
1085
	}
1086
}
1087

1088
export class TestBackupFileService implements IBackupFileService {
1089
	public _serviceBrand: undefined;
1090

J
Johannes Rieken 已提交
1091
	public hasBackups(): Promise<boolean> {
B
Benjamin Pasero 已提交
1092
		return Promise.resolve(false);
1093 1094
	}

J
Johannes Rieken 已提交
1095
	public hasBackup(_resource: URI): Promise<boolean> {
B
Benjamin Pasero 已提交
1096
		return Promise.resolve(false);
1097 1098
	}

1099 1100 1101 1102
	public hasBackupSync(resource: URI, versionId?: number): boolean {
		return false;
	}

1103
	public loadBackupResource(resource: URI): Promise<URI | undefined> {
B
Benjamin Pasero 已提交
1104 1105
		return this.hasBackup(resource).then(hasBackup => {
			if (hasBackup) {
1106
				return this.toBackupResource(resource);
B
Benjamin Pasero 已提交
1107 1108
			}

R
Rob Lourens 已提交
1109
			return undefined;
B
Benjamin Pasero 已提交
1110 1111 1112
		});
	}

J
Johannes Rieken 已提交
1113
	public registerResourceForBackup(_resource: URI): Promise<void> {
B
Benjamin Pasero 已提交
1114
		return Promise.resolve();
D
Daniel Imms 已提交
1115 1116
	}

J
Johannes Rieken 已提交
1117
	public deregisterResourceForBackup(_resource: URI): Promise<void> {
B
Benjamin Pasero 已提交
1118
		return Promise.resolve();
D
Daniel Imms 已提交
1119 1120
	}

1121
	public toBackupResource(_resource: URI): URI {
1122
		throw new Error('not implemented');
D
Daniel Imms 已提交
1123
	}
1124

1125
	public backupResource<T extends object>(_resource: URI, _content: ITextSnapshot, versionId?: number, meta?: T): Promise<void> {
B
Benjamin Pasero 已提交
1126
		return Promise.resolve();
1127 1128
	}

J
Johannes Rieken 已提交
1129
	public getWorkspaceFileBackups(): Promise<URI[]> {
B
Benjamin Pasero 已提交
1130
		return Promise.resolve([]);
1131 1132
	}

1133 1134 1135 1136 1137
	public parseBackupContent(textBufferFactory: ITextBufferFactory): string {
		const textBuffer = textBufferFactory.create(DefaultEndOfLine.LF);
		const lineCount = textBuffer.getLineCount();
		const range = new Range(1, 1, lineCount, textBuffer.getLineLength(lineCount) + 1);
		return textBuffer.getValueInRange(range, EndOfLinePreference.TextDefined);
1138 1139
	}

1140
	public resolveBackupContent<T extends object>(_backup: URI): Promise<IResolvedBackup<T>> {
1141
		throw new Error('not implemented');
1142 1143
	}

J
Johannes Rieken 已提交
1144
	public discardResourceBackup(_resource: URI): Promise<void> {
B
Benjamin Pasero 已提交
1145
		return Promise.resolve();
1146 1147
	}

J
Johannes Rieken 已提交
1148
	public discardAllWorkspaceBackups(): Promise<void> {
B
Benjamin Pasero 已提交
1149
		return Promise.resolve();
1150
	}
1151
}
D
Daniel Imms 已提交
1152

B
Benjamin Pasero 已提交
1153
export class TestCodeEditorService implements ICodeEditorService {
1154
	_serviceBrand: undefined;
B
Benjamin Pasero 已提交
1155 1156 1157 1158 1159

	onCodeEditorAdd: Event<ICodeEditor> = Event.None;
	onCodeEditorRemove: Event<ICodeEditor> = Event.None;
	onDiffEditorAdd: Event<IDiffEditor> = Event.None;
	onDiffEditorRemove: Event<IDiffEditor> = Event.None;
A
Alex Dima 已提交
1160
	onDidChangeTransientModelProperty: Event<ITextModel> = Event.None;
B
Benjamin Pasero 已提交
1161

1162 1163
	addCodeEditor(_editor: ICodeEditor): void { }
	removeCodeEditor(_editor: ICodeEditor): void { }
B
Benjamin Pasero 已提交
1164
	listCodeEditors(): ICodeEditor[] { return []; }
1165 1166
	addDiffEditor(_editor: IDiffEditor): void { }
	removeDiffEditor(_editor: IDiffEditor): void { }
B
Benjamin Pasero 已提交
1167
	listDiffEditors(): IDiffEditor[] { return []; }
1168
	getFocusedCodeEditor(): ICodeEditor | undefined { return undefined; }
1169 1170 1171 1172 1173
	registerDecorationType(_key: string, _options: IDecorationRenderOptions, _parentTypeKey?: string): void { }
	removeDecorationType(_key: string): void { }
	resolveDecorationOptions(_typeKey: string, _writable: boolean): IModelDecorationOptions { return Object.create(null); }
	setTransientModelProperty(_model: ITextModel, _key: string, _value: any): void { }
	getTransientModelProperty(_model: ITextModel, _key: string) { }
1174
	getActiveCodeEditor(): ICodeEditor | undefined { return undefined; }
1175
	openCodeEditor(_input: IResourceInput, _source: ICodeEditor, _sideBySide?: boolean): Promise<ICodeEditor | undefined> { return Promise.resolve(undefined); }
B
Benjamin Pasero 已提交
1176 1177
}

1178 1179
export class TestLifecycleService implements ILifecycleService {

1180
	public _serviceBrand: undefined;
1181

1182 1183
	public phase!: LifecyclePhase;
	public startupKind!: StartupKind;
1184

1185 1186 1187
	private readonly _onBeforeShutdown = new Emitter<BeforeShutdownEvent>();
	private readonly _onWillShutdown = new Emitter<WillShutdownEvent>();
	private readonly _onShutdown = new Emitter<void>();
1188

J
Johannes Rieken 已提交
1189
	when(): Promise<void> {
B
Benjamin Pasero 已提交
1190
		return Promise.resolve();
B
Benjamin Pasero 已提交
1191
	}
1192

1193
	public fireShutdown(reason = ShutdownReason.QUIT): void {
1194
		this._onWillShutdown.fire({
1195 1196 1197
			join: () => { },
			reason
		});
1198 1199
	}

1200 1201 1202 1203 1204 1205
	public fireWillShutdown(event: BeforeShutdownEvent): void {
		this._onBeforeShutdown.fire(event);
	}

	public get onBeforeShutdown(): Event<BeforeShutdownEvent> {
		return this._onBeforeShutdown.event;
1206 1207
	}

1208
	public get onWillShutdown(): Event<WillShutdownEvent> {
1209 1210 1211
		return this._onWillShutdown.event;
	}

1212
	public get onShutdown(): Event<void> {
1213 1214
		return this._onShutdown.event;
	}
1215 1216
}

1217 1218
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {

1219
	_serviceBrand: undefined;
1220 1221 1222 1223

	constructor(private configurationService = new TestConfigurationService()) {
	}

1224
	public onDidChangeConfiguration() {
1225 1226 1227
		return { dispose() { } };
	}

1228
	getValue<T>(resource: URI, arg2?: any, arg3?: any): T {
1229 1230
		const position: IPosition | null = EditorPosition.isIPosition(arg2) ? arg2 : null;
		const section: string | undefined = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
1231
		return this.configurationService.getValue(section, { resource });
1232
	}
B
Benjamin Pasero 已提交
1233 1234
}

S
Sandeep Somavarapu 已提交
1235 1236
export class TestTextResourcePropertiesService implements ITextResourcePropertiesService {

1237
	_serviceBrand: undefined;
S
Sandeep Somavarapu 已提交
1238 1239

	constructor(
1240
		@IConfigurationService private readonly configurationService: IConfigurationService,
S
Sandeep Somavarapu 已提交
1241 1242 1243
	) {
	}

1244 1245 1246 1247
	getEOL(resource: URI, language?: string): string {
		const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
		if (eol && eol !== 'auto') {
			return eol;
S
Sandeep Somavarapu 已提交
1248 1249 1250 1251 1252 1253
		}
		return (isLinux || isMacintosh) ? '\n' : '\r\n';
	}
}


1254
export class TestSharedProcessService implements ISharedProcessService {
1255

1256
	_serviceBrand: undefined;
1257

1258 1259 1260
	getChannel(channelName: string): any {
		return undefined;
	}
1261

1262
	registerChannel(channelName: string, channel: any): void { }
1263 1264 1265

	async toggleSharedProcessWindow(): Promise<void> { }
	async whenSharedProcessReady(): Promise<void> { }
1266 1267
}

1268 1269 1270 1271 1272 1273 1274
export class RemoteFileSystemProvider implements IFileSystemProvider {

	constructor(private readonly diskFileSystemProvider: IFileSystemProvider, private readonly remoteAuthority: string) { }

	readonly capabilities: FileSystemProviderCapabilities = this.diskFileSystemProvider.capabilities;
	readonly onDidChangeCapabilities: Event<void> = this.diskFileSystemProvider.onDidChangeCapabilities;

M
Matt Bierner 已提交
1275 1276 1277 1278 1279 1280
	readonly onDidChangeFile: Event<readonly IFileChange[]> = Event.map(this.diskFileSystemProvider.onDidChangeFile, changes => changes.map((c): IFileChange => {
		return {
			type: c.type,
			resource: c.resource.with({ scheme: Schemas.vscodeRemote, authority: this.remoteAuthority }),
		};
	}));
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
	watch(resource: URI, opts: IWatchOptions): IDisposable { return this.diskFileSystemProvider.watch(this.toFileResource(resource), opts); }

	stat(resource: URI): Promise<IStat> { return this.diskFileSystemProvider.stat(this.toFileResource(resource)); }
	mkdir(resource: URI): Promise<void> { return this.diskFileSystemProvider.mkdir(this.toFileResource(resource)); }
	readdir(resource: URI): Promise<[string, FileType][]> { return this.diskFileSystemProvider.readdir(this.toFileResource(resource)); }
	delete(resource: URI, opts: FileDeleteOptions): Promise<void> { return this.diskFileSystemProvider.delete(this.toFileResource(resource), opts); }

	rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { return this.diskFileSystemProvider.rename(this.toFileResource(from), this.toFileResource(to), opts); }
	copy(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { return this.diskFileSystemProvider.copy!(this.toFileResource(from), this.toFileResource(to), opts); }

	readFile(resource: URI): Promise<Uint8Array> { return this.diskFileSystemProvider.readFile!(this.toFileResource(resource)); }
	writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> { return this.diskFileSystemProvider.writeFile!(this.toFileResource(resource), content, opts); }

	open(resource: URI, opts: FileOpenOptions): Promise<number> { return this.diskFileSystemProvider.open!(this.toFileResource(resource), opts); }
	close(fd: number): Promise<void> { return this.diskFileSystemProvider.close!(fd); }
	read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { return this.diskFileSystemProvider.read!(fd, pos, data, offset, length); }
	write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { return this.diskFileSystemProvider.write!(fd, pos, data, offset, length); }

	private toFileResource(resource: URI): URI { return resource.with({ scheme: Schemas.file, authority: '' }); }
J
Joao Moreno 已提交
1300
}
1301 1302

export const productService: IProductService = { _serviceBrand: undefined, ...product };
1303 1304 1305 1306 1307

export class TestHostService implements IHostService {

	_serviceBrand: undefined;

1308 1309 1310
	readonly hasFocus: boolean = true;
	readonly onDidChangeFocus: Event<boolean> = Event.None;

1311 1312
	async restart(): Promise<void> { }
	async reload(): Promise<void> { }
1313

1314 1315
	async focus(): Promise<void> { }

1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
	async openWindow(arg1?: IOpenEmptyWindowOptions | IWindowOpenable[], arg2?: IOpenWindowOptions): Promise<void> { }

	async toggleFullScreen(): Promise<void> { }
}

export class TestElectronService implements IElectronService {
	_serviceBrand: undefined;

	onWindowOpen: Event<number> = Event.None;
	onWindowMaximize: Event<number> = Event.None;
	onWindowUnmaximize: Event<number> = Event.None;
	onWindowFocus: Event<number> = Event.None;
	onWindowBlur: Event<number> = Event.None;

	windowCount = Promise.resolve(1);
	getWindowCount(): Promise<number> { return this.windowCount; }

	async getWindows(): Promise<IOpenedWindow[]> { return []; }
	async getActiveWindowId(): Promise<number | undefined> { return undefined; }

	openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
	openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
	openWindow(arg1?: IOpenEmptyWindowOptions | IWindowOpenable[], arg2?: IOpenWindowOptions): Promise<void> {
		throw new Error('Method not implemented.');
	}
1341

1342
	async toggleFullScreen(): Promise<void> { }
1343 1344 1345 1346 1347 1348 1349
	async handleTitleDoubleClick(): Promise<void> { }
	async isMaximized(): Promise<boolean> { return true; }
	async maximizeWindow(): Promise<void> { }
	async unmaximizeWindow(): Promise<void> { }
	async minimizeWindow(): Promise<void> { }
	async isWindowFocused(): Promise<boolean> { return true; }
	async focusWindow(options?: { windowId?: number | undefined; } | undefined): Promise<void> { }
1350 1351 1352
	async showMessageBox(options: Electron.MessageBoxOptions): Promise<Electron.MessageBoxReturnValue> { throw new Error('Method not implemented.'); }
	async showSaveDialog(options: Electron.SaveDialogOptions): Promise<Electron.SaveDialogReturnValue> { throw new Error('Method not implemented.'); }
	async showOpenDialog(options: Electron.OpenDialogOptions): Promise<Electron.OpenDialogReturnValue> { throw new Error('Method not implemented.'); }
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
	async pickFileFolderAndOpen(options: INativeOpenDialogOptions): Promise<void> { }
	async pickFileAndOpen(options: INativeOpenDialogOptions): Promise<void> { }
	async pickFolderAndOpen(options: INativeOpenDialogOptions): Promise<void> { }
	async pickWorkspaceAndOpen(options: INativeOpenDialogOptions): Promise<void> { }
	async showItemInFolder(path: string): Promise<void> { }
	async setRepresentedFilename(path: string): Promise<void> { }
	async setDocumentEdited(edited: boolean): Promise<void> { }
	async openExternal(url: string): Promise<boolean> { return false; }
	async updateTouchBar(items: { id: string; title: string | { value: string; original: string; }; category?: string | { value: string; original: string; } | undefined; iconLocation?: { dark: UriComponents; light?: { readonly scheme: string; readonly authority: string; readonly path: string; readonly query: string; readonly fragment: string; readonly fsPath: string; with: {}; toString: {}; toJSON: {}; } | undefined; } | undefined; precondition?: { getType: {}; equals: {}; evaluate: {}; serialize: {}; keys: {}; map: {}; negate: {}; } | undefined; toggled?: { getType: {}; equals: {}; evaluate: {}; serialize: {}; keys: {}; map: {}; negate: {}; } | undefined; }[][]): Promise<void> { }
	async newWindowTab(): Promise<void> { }
	async showPreviousWindowTab(): Promise<void> { }
	async showNextWindowTab(): Promise<void> { }
	async moveWindowTabToNewWindow(): Promise<void> { }
	async mergeAllWindowTabs(): Promise<void> { }
	async toggleWindowTabsBar(): Promise<void> { }
	async relaunch(options?: { addArgs?: string[] | undefined; removeArgs?: string[] | undefined; } | undefined): Promise<void> { }
	async reload(): Promise<void> { }
	async closeWindow(): Promise<void> { }
	async quit(): Promise<void> { }
	async openDevTools(options?: Electron.OpenDevToolsOptions | undefined): Promise<void> { }
	async toggleDevTools(): Promise<void> { }
	async startCrashReporter(options: Electron.CrashReporterStartOptions): Promise<void> { }
	async resolveProxy(url: string): Promise<string | undefined> { return undefined; }
	async openExtensionDevelopmentHostWindow(args: minimist.ParsedArgs, env: IProcessEnvironment): Promise<void> { }
1377
}
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441

export class TestBackupMainService implements IBackupMainService {
	_serviceBrand: undefined;

	isHotExitEnabled(): boolean {
		throw new Error('Method not implemented.');
	}

	getWorkspaceBackups(): IWorkspaceBackupInfo[] {
		throw new Error('Method not implemented.');
	}

	getFolderBackupPaths(): URI[] {
		throw new Error('Method not implemented.');
	}

	getEmptyWindowBackupPaths(): IEmptyWindowBackupInfo[] {
		throw new Error('Method not implemented.');
	}

	registerWorkspaceBackupSync(workspace: IWorkspaceBackupInfo, migrateFrom?: string | undefined): string {
		throw new Error('Method not implemented.');
	}

	registerFolderBackupSync(folderUri: URI): string {
		throw new Error('Method not implemented.');
	}

	registerEmptyWindowBackupSync(backupFolder?: string | undefined, remoteAuthority?: string | undefined): string {
		throw new Error('Method not implemented.');
	}

	unregisterWorkspaceBackupSync(workspace: IWorkspaceIdentifier): void {
		throw new Error('Method not implemented.');
	}

	unregisterFolderBackupSync(folderUri: URI): void {
		throw new Error('Method not implemented.');
	}

	unregisterEmptyWindowBackupSync(backupFolder: string): void {
		throw new Error('Method not implemented.');
	}
}

export class TestDialogMainService implements IDialogMainService {
	_serviceBrand: undefined;

	pickFileFolder(options: INativeOpenDialogOptions, window?: Electron.BrowserWindow | undefined): Promise<string[] | undefined> {
		throw new Error('Method not implemented.');
	}

	pickFolder(options: INativeOpenDialogOptions, window?: Electron.BrowserWindow | undefined): Promise<string[] | undefined> {
		throw new Error('Method not implemented.');
	}

	pickFile(options: INativeOpenDialogOptions, window?: Electron.BrowserWindow | undefined): Promise<string[] | undefined> {
		throw new Error('Method not implemented.');
	}

	pickWorkspace(options: INativeOpenDialogOptions, window?: Electron.BrowserWindow | undefined): Promise<string[] | undefined> {
		throw new Error('Method not implemented.');
	}

1442
	showMessageBox(options: Electron.MessageBoxOptions, window?: Electron.BrowserWindow | undefined): Promise<Electron.MessageBoxReturnValue> {
1443 1444 1445
		throw new Error('Method not implemented.');
	}

1446
	showSaveDialog(options: Electron.SaveDialogOptions, window?: Electron.BrowserWindow | undefined): Promise<Electron.SaveDialogReturnValue> {
1447 1448 1449
		throw new Error('Method not implemented.');
	}

1450
	showOpenDialog(options: Electron.OpenDialogOptions, window?: Electron.BrowserWindow | undefined): Promise<Electron.OpenDialogReturnValue> {
1451 1452 1453
		throw new Error('Method not implemented.');
	}
}