workbenchTestServices.ts 46.1 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 } from 'vs/base/common/uri';
12 13
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
B
Benjamin Pasero 已提交
14
import { ConfirmResult, IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent } from 'vs/workbench/common/editor';
B
Benjamin Pasero 已提交
15
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView, EditorGroupsServiceImpl } 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 } from 'vs/workbench/services/backup/common/backup';
19
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
20
import { IPartService, Parts, Position as PartPosition, IDimension } from 'vs/workbench/services/part/common/partService';
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 { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
29
import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent, ICreateFileOptions, ITextSnapshot, IResourceEncodings } from 'vs/platform/files/common/files';
30
import { IModelService } from 'vs/editor/common/services/modelService';
31
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
J
Johannes Rieken 已提交
32 33 34 35 36 37
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IRawTextContent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { parseArgs } from 'vs/platform/environment/node/argv';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
38
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
39
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
40
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration, MenuBarVisibility, IURIToOpen } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
41
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
42
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
B
Benjamin Pasero 已提交
43
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
44
import { IThemeService } from 'vs/platform/theme/common/themeService';
B
Benjamin Pasero 已提交
45
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
46
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
B
Benjamin Pasero 已提交
47
import { IRecentlyOpened } from 'vs/platform/history/common/history';
S
Sandeep Somavarapu 已提交
48
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
49
import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position';
B
Benjamin Pasero 已提交
50
import { IMenuService, MenuId, IMenu, ISerializableCommandAction } from 'vs/platform/actions/common/actions';
R
Ramya Achutha Rao 已提交
51
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
I
isidor 已提交
52
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
B
Benjamin Pasero 已提交
53
import { MockContextKeyService, MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
B
Benjamin Pasero 已提交
54
import { ITextBufferFactory, DefaultEndOfLine, EndOfLinePreference, IModelDecorationOptions, ITextModel } from 'vs/editor/common/model';
55
import { Range } from 'vs/editor/common/core/range';
M
Martin Aeschlimann 已提交
56
import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions, IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
57 58
import { INotificationService } from 'vs/platform/notification/common/notification';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
59
import { IExtensionService, NullExtensionService } from 'vs/workbench/services/extensions/common/extensions';
B
Benjamin Pasero 已提交
60
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
B
Benjamin Pasero 已提交
61
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
J
Joao Moreno 已提交
62
import { IDisposable, toDisposable, Disposable } from 'vs/base/common/lifecycle';
63
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, EditorsOrder, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions } from 'vs/workbench/services/editor/common/editorGroupsService';
M
Matt Bierner 已提交
64
import { IEditorService, IOpenEditorOverrideHandler, IActiveEditor } from 'vs/workbench/services/editor/common/editorService';
B
Benjamin Pasero 已提交
65 66 67
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 已提交
68
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
69
import { Dimension } from 'vs/base/browser/dom';
70
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
I
isidor 已提交
71
import { ILabelService } from 'vs/platform/label/common/label';
72
import { timeout } from 'vs/base/common/async';
73 74 75 76
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IProgressService } from 'vs/platform/progress/common/progress';
77
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
S
Sandeep Somavarapu 已提交
78
import { isLinux, isMacintosh } from 'vs/base/common/platform';
I
isidor 已提交
79
import { LabelService } from 'vs/workbench/services/label/common/labelService';
B
Benjamin Pasero 已提交
80

S
Sandeep Somavarapu 已提交
81
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
R
Rob Lourens 已提交
82
	return instantiationService.createInstance(FileEditorInput, resource, undefined);
S
Sandeep Somavarapu 已提交
83 84
}

85
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
86

87
export class TestContextService implements IWorkspaceContextService {
88
	public _serviceBrand: any;
E
Erich Gamma 已提交
89

S
Sandeep Somavarapu 已提交
90
	private workspace: Workspace;
E
Erich Gamma 已提交
91 92
	private options: any;

M
Matt Bierner 已提交
93 94 95
	private readonly _onDidChangeWorkspaceName: Emitter<void>;
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent>;
	private readonly _onDidChangeWorkbenchState: Emitter<WorkbenchState>;
96

97
	constructor(workspace: any = TestWorkspace, options: any = null) {
E
Erich Gamma 已提交
98
		this.workspace = workspace;
99
		this.options = options || Object.create(null);
100
		this._onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
S
Sandeep Somavarapu 已提交
101
		this._onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
102 103
	}

S
Sandeep Somavarapu 已提交
104 105 106 107
	public get onDidChangeWorkspaceName(): Event<void> {
		return this._onDidChangeWorkspaceName.event;
	}

108
	public get onDidChangeWorkspaceFolders(): Event<IWorkspaceFoldersChangeEvent> {
S
Sandeep Somavarapu 已提交
109
		return this._onDidChangeWorkspaceFolders.event;
110 111
	}

112 113 114 115
	public get onDidChangeWorkbenchState(): Event<WorkbenchState> {
		return this._onDidChangeWorkbenchState.event;
	}

S
Sandeep Somavarapu 已提交
116
	public getFolders(): IWorkspaceFolder[] {
S
Sandeep Somavarapu 已提交
117
		return this.workspace ? this.workspace.folders : [];
E
Erich Gamma 已提交
118 119
	}

120
	public getWorkbenchState(): WorkbenchState {
B
Benjamin Pasero 已提交
121 122 123 124 125
		if (this.workspace.configuration) {
			return WorkbenchState.WORKSPACE;
		}

		if (this.workspace.folders.length) {
126
			return WorkbenchState.FOLDER;
127
		}
B
Benjamin Pasero 已提交
128

129
		return WorkbenchState.EMPTY;
S
Sandeep Somavarapu 已提交
130 131
	}

132 133 134 135
	getCompleteWorkspace(): Promise<IWorkbenchWorkspace> {
		return Promise.resolve(this.getWorkspace());
	}

136
	public getWorkspace(): IWorkbenchWorkspace {
B
Benjamin Pasero 已提交
137
		return this.workspace;
138 139
	}

140
	public getWorkspaceFolder(resource: URI): IWorkspaceFolder | null {
S
Sandeep Somavarapu 已提交
141
		return this.workspace.getFolder(resource);
142 143
	}

D
Daniel Imms 已提交
144 145 146 147
	public setWorkspace(workspace: any): void {
		this.workspace = workspace;
	}

E
Erich Gamma 已提交
148 149 150 151 152 153 154 155 156 157
	public getOptions() {
		return this.options;
	}

	public updateOptions() {

	}

	public isInsideWorkspace(resource: URI): boolean {
		if (resource && this.workspace) {
158
			return resources.isEqualOrParent(resource, this.workspace.folders[0].uri);
E
Erich Gamma 已提交
159 160 161 162 163 164
		}

		return false;
	}

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

168
	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
169
		return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) && resources.isEqual(this.workspace.folders[0].uri, workspaceIdentifier);
170
	}
E
Erich Gamma 已提交
171 172
}

173
export class TestTextFileService extends TextFileService {
174 175
	public cleanupBackupsBeforeShutdownCalled: boolean;

M
Martin Aeschlimann 已提交
176
	private promptPath: URI;
177
	private confirmResult: ConfirmResult;
178
	private resolveTextContentError: FileOperationError | null;
A
Alex Dima 已提交
179 180

	constructor(
181
		@IWorkspaceContextService contextService: IWorkspaceContextService,
182
		@IFileService protected fileService: IFileService,
183
		@IUntitledEditorService untitledEditorService: IUntitledEditorService,
184
		@ILifecycleService lifecycleService: ILifecycleService,
185
		@IInstantiationService instantiationService: IInstantiationService,
186 187 188 189 190
		@IConfigurationService configurationService: IConfigurationService,
		@IModeService modeService: IModeService,
		@IModelService modelService: IModelService,
		@IWindowService windowService: IWindowService,
		@IEnvironmentService environmentService: IEnvironmentService,
191
		@INotificationService notificationService: INotificationService,
192
		@IBackupFileService backupFileService: IBackupFileService,
193
		@IWindowsService windowsService: IWindowsService,
I
isidor 已提交
194
		@IHistoryService historyService: IHistoryService,
B
Benjamin Pasero 已提交
195
		@IContextKeyService contextKeyService: IContextKeyService,
196 197 198
		@IDialogService dialogService: IDialogService,
		@IFileDialogService fileDialogService: IFileDialogService,
		@IEditorService editorService: IEditorService
A
Alex Dima 已提交
199
	) {
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
		super(
			contextService,
			fileService,
			untitledEditorService,
			lifecycleService,
			instantiationService,
			configurationService,
			modeService,
			modelService,
			windowService,
			environmentService,
			notificationService,
			backupFileService,
			windowsService,
			historyService,
			contextKeyService,
			dialogService,
			fileDialogService,
			editorService
		);
A
Alex Dima 已提交
220
	}
221

M
Martin Aeschlimann 已提交
222
	public setPromptPath(path: URI): void {
223 224 225 226 227 228 229
		this.promptPath = path;
	}

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

230
	public setResolveTextContentErrorOnce(error: FileOperationError): void {
231 232 233
		this.resolveTextContentError = error;
	}

J
Johannes Rieken 已提交
234
	public resolveTextContent(resource: URI, options?: IResolveContentOptions): Promise<IRawTextContent> {
235 236 237 238
		if (this.resolveTextContentError) {
			const error = this.resolveTextContentError;
			this.resolveTextContentError = null;

B
Benjamin Pasero 已提交
239
			return Promise.reject(error);
240 241
		}

242 243
		return this.fileService.resolveContent(resource, options).then((content): IRawTextContent => {
			return {
244
				resource: content.resource,
245 246 247 248
				name: content.name,
				mtime: content.mtime,
				etag: content.etag,
				encoding: content.encoding,
249
				value: createTextBufferFactory(content.value)
250 251 252
			};
		});
	}
253

J
Johannes Rieken 已提交
254
	public promptForPath(_resource: URI, _defaultPath: URI): Promise<URI> {
B
Benjamin Pasero 已提交
255
		return Promise.resolve(this.promptPath);
256 257
	}

J
Johannes Rieken 已提交
258
	public confirmSave(_resources?: URI[]): Promise<ConfirmResult> {
B
Benjamin Pasero 已提交
259
		return Promise.resolve(this.confirmResult);
260
	}
D
Daniel Imms 已提交
261

B
Benjamin Pasero 已提交
262 263 264 265
	public confirmOverwrite(_resource: URI): Promise<boolean> {
		return Promise.resolve(true);
	}

266 267
	public onFilesConfigurationChange(configuration: any): void {
		super.onFilesConfigurationChange(configuration);
268 269
	}

J
Johannes Rieken 已提交
270
	protected cleanupBackupsBeforeShutdown(): Promise<void> {
271
		this.cleanupBackupsBeforeShutdownCalled = true;
B
Benjamin Pasero 已提交
272
		return Promise.resolve();
273
	}
A
Alex Dima 已提交
274 275
}

276
export function workbenchInstantiationService(): IInstantiationService {
277
	let instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
278
	instantiationService.stub(IEnvironmentService, TestEnvironmentService);
I
isidor 已提交
279
	instantiationService.stub(IContextKeyService, <IContextKeyService>instantiationService.createInstance(MockContextKeyService));
I
isidor 已提交
280 281
	const workspaceContextService = new TestContextService(TestWorkspace);
	instantiationService.stub(IWorkspaceContextService, workspaceContextService);
282 283 284
	const configService = new TestConfigurationService();
	instantiationService.stub(IConfigurationService, configService);
	instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
285
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
286
	instantiationService.stub(IStorageService, new TestStorageService());
287
	instantiationService.stub(IPartService, new TestPartService());
J
Johannes Rieken 已提交
288
	instantiationService.stub(IModeService, instantiationService.createInstance(ModeServiceImpl));
B
Benjamin Pasero 已提交
289
	instantiationService.stub(IHistoryService, new TestHistoryService());
S
Sandeep Somavarapu 已提交
290
	instantiationService.stub(ITextResourcePropertiesService, new TestTextResourcePropertiesService(configService));
S
Sandeep Somavarapu 已提交
291
	instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
292
	instantiationService.stub(IFileService, new TestFileService());
293
	instantiationService.stub(IBackupFileService, new TestBackupFileService());
294
	instantiationService.stub(ITelemetryService, NullTelemetryService);
295
	instantiationService.stub(INotificationService, new TestNotificationService());
B
Benjamin Pasero 已提交
296
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
297
	instantiationService.stub(IWindowService, new TestWindowService());
B
Benjamin Pasero 已提交
298 299 300 301
	instantiationService.stub(IMenuService, new TestMenuService());
	instantiationService.stub(IKeybindingService, new MockKeybindingService());
	instantiationService.stub(IDecorationsService, new TestDecorationsService());
	instantiationService.stub(IExtensionService, new TestExtensionService());
302
	instantiationService.stub(IWindowsService, new TestWindowsService());
303
	instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(TestTextFileService));
304
	instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
B
Benjamin Pasero 已提交
305
	instantiationService.stub(IThemeService, new TestThemeService());
R
Ramya Achutha Rao 已提交
306
	instantiationService.stub(IHashService, new TestHashService());
I
isidor 已提交
307
	instantiationService.stub(ILogService, new TestLogService());
308
	instantiationService.stub(IEditorGroupsService, new TestEditorGroupsService([new TestEditorGroup(0)]));
M
Martin Aeschlimann 已提交
309
	instantiationService.stub(ILabelService, <ILabelService>instantiationService.createInstance(LabelService));
B
Benjamin Pasero 已提交
310
	const editorService = new TestEditorService();
311
	instantiationService.stub(IEditorService, editorService);
B
Benjamin Pasero 已提交
312
	instantiationService.stub(ICodeEditorService, new TestCodeEditorService());
313
	instantiationService.stub(IViewletService, new TestViewletService());
314 315 316 317

	return instantiationService;
}

I
isidor 已提交
318 319 320
export class TestLogService implements ILogService {
	_serviceBrand: any; onDidChangeLogLevel: Event<LogLevel>;
	getLevel(): LogLevel { return LogLevel.Info; }
321 322 323 324 325 326 327
	setLevel(_level: LogLevel): void { }
	trace(_message: string, ..._args: any[]): void { }
	debug(_message: string, ..._args: any[]): void { }
	info(_message: string, ..._args: any[]): void { }
	warn(_message: string, ..._args: any[]): void { }
	error(_message: string | Error, ..._args: any[]): void { }
	critical(_message: string | Error, ..._args: any[]): void { }
I
isidor 已提交
328 329 330
	dispose(): void { }
}

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

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

export class TestMenuService implements IMenuService {

	public _serviceBrand: any;

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

B
Benjamin Pasero 已提交
353 354 355 356 357 358 359 360 361 362
export class TestHistoryService implements IHistoryService {

	public _serviceBrand: any;

	constructor(private root?: URI) {
	}

	public reopenLastClosedEditor(): void {
	}

363
	public forward(_acrossEditors?: boolean): void {
B
Benjamin Pasero 已提交
364 365
	}

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

369 370 371
	public last(): void {
	}

372
	public remove(_input: IEditorInput | IResourceInput): void {
B
Benjamin Pasero 已提交
373 374 375 376 377
	}

	public clear(): void {
	}

B
Benjamin Pasero 已提交
378 379 380
	public clearRecentlyOpened(): void {
	}

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

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

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

	public openLastEditLocation(): void {
	}
B
Benjamin Pasero 已提交
395 396
}

397
export class TestDialogService implements IDialogService {
398 399

	public _serviceBrand: any;
E
Erich Gamma 已提交
400

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

J
Johannes Rieken 已提交
405
	public show(_severity: Severity, _message: string, _buttons: string[], _options?: IDialogOptions): Promise<number> {
B
Benjamin Pasero 已提交
406
		return Promise.resolve(0);
407
	}
E
Erich Gamma 已提交
408 409
}

M
Martin Aeschlimann 已提交
410 411 412 413
export class TestFileDialogService implements IFileDialogService {

	public _serviceBrand: any;

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

443
export class TestPartService implements IPartService {
B
Benjamin Pasero 已提交
444

445
	public _serviceBrand: any;
E
Erich Gamma 已提交
446

B
Benjamin Pasero 已提交
447 448
	onZenModeChange: Event<boolean> = Event.None;

449
	private _onTitleBarVisibilityChange = new Emitter<void>();
450
	private _onMenubarVisibilityChange = new Emitter<Dimension>();
451 452 453 454 455

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

456 457 458 459
	public get onMenubarVisibilityChange(): Event<Dimension> {
		return this._onMenubarVisibilityChange.event;
	}

B
Benjamin Pasero 已提交
460
	public isRestored(): boolean {
E
Erich Gamma 已提交
461 462 463
		return true;
	}

464
	public hasFocus(_part: Parts): boolean {
E
Erich Gamma 已提交
465 466 467
		return false;
	}

468
	public isVisible(_part: Parts): boolean {
E
Erich Gamma 已提交
469 470 471
		return true;
	}

472
	public getContainer(_part: Parts): HTMLElement | null {
473 474 475
		return null;
	}

B
Benjamin Pasero 已提交
476 477 478 479
	public isTitleBarHidden(): boolean {
		return false;
	}

480 481 482 483
	public getTitleBarOffset(): number {
		return 0;
	}

484 485 486 487
	public isStatusBarHidden(): boolean {
		return false;
	}

S
Sanders Lauture 已提交
488 489 490 491
	public isActivityBarHidden(): boolean {
		return false;
	}

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

E
Erich Gamma 已提交
494 495 496 497
	public isSideBarHidden(): boolean {
		return false;
	}

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

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

I
isidor 已提交
502
	public isPanelHidden(): boolean {
I
isidor 已提交
503 504 505
		return false;
	}

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

I
isidor 已提交
508 509
	public toggleMaximizedPanel(): void { }

B
Benjamin Pasero 已提交
510 511 512 513
	public isPanelMaximized(): boolean {
		return false;
	}

S
SteVen Batten 已提交
514
	public getMenubarVisibility(): MenuBarVisibility {
515
		throw new Error('not implemented');
S
SteVen Batten 已提交
516 517
	}

E
Erich Gamma 已提交
518 519 520 521
	public getSideBarPosition() {
		return 0;
	}

I
isidor 已提交
522 523 524 525
	public getPanelPosition() {
		return 0;
	}

J
Johannes Rieken 已提交
526
	public setPanelPosition(_position: PartPosition): Promise<void> {
527
		return Promise.resolve();
I
isidor 已提交
528 529
	}

530 531
	public addClass(_clazz: string): void { }
	public removeClass(_clazz: string): void { }
532
	public getWorkbenchElement(): HTMLElement { throw new Error('not implemented'); }
B
Benjamin Pasero 已提交
533

I
isidor 已提交
534
	public toggleZenMode(): void { }
535

B
Benjamin Pasero 已提交
536
	public isEditorLayoutCentered(): boolean { return false; }
537
	public centerEditorLayout(_active: boolean): void { }
S
SrTobi 已提交
538 539


540
	public resizePart(_part: Parts, _sizeChange: number): void { }
E
Erich Gamma 已提交
541 542
}

543
export class TestStorageService extends InMemoryStorageService { }
544

B
Benjamin Pasero 已提交
545
export class TestEditorGroupsService implements EditorGroupsServiceImpl {
546 547
	_serviceBrand: ServiceIdentifier<any>;

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

550 551 552 553
	onDidActiveGroupChange: Event<IEditorGroup> = Event.None;
	onDidAddGroup: Event<IEditorGroup> = Event.None;
	onDidRemoveGroup: Event<IEditorGroup> = Event.None;
	onDidMoveGroup: Event<IEditorGroup> = Event.None;
554
	onDidLayout: Event<IDimension> = Event.None;
555 556

	orientation: any;
R
Rob Lourens 已提交
557
	whenRestored: Promise<void> = Promise.resolve(undefined);
558

559
	get activeGroup(): IEditorGroup {
560 561 562 563 564 565 566
		return this.groups[0];
	}

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

567
	getGroups(_order?: GroupsOrder): ReadonlyArray<IEditorGroup> {
568 569 570
		return this.groups;
	}

571
	getGroup(identifier: number): IEditorGroup {
572 573 574
		for (const group of this.groups) {
			if (group.id === identifier) {
				return group;
575 576 577
			}
		}

578
		return undefined!;
579 580
	}

581
	getLabel(_identifier: number): string {
582 583 584
		return 'Group 1';
	}

585
	findGroup(_scope: IFindGroupScope, _source?: number | IEditorGroup, _wrap?: boolean): IEditorGroup {
586
		throw new Error('not implemented');
587 588
	}

589
	activateGroup(_group: number | IEditorGroup): IEditorGroup {
590
		throw new Error('not implemented');
591 592
	}

593
	getSize(_group: number | IEditorGroup): number {
594
		return 100;
595 596
	}

597
	setSize(_group: number | IEditorGroup, _size: number): void { }
598

599
	arrangeGroups(_arrangement: GroupsArrangement): void { }
600

601
	applyLayout(_layout: EditorGroupLayout): void { }
602

603
	setGroupOrientation(_orientation: any): void { }
604

605
	addGroup(_location: number | IEditorGroup, _direction: GroupDirection, _options?: IAddGroupOptions): IEditorGroup {
606
		throw new Error('not implemented');
607 608
	}

609
	removeGroup(_group: number | IEditorGroup): void { }
610

611
	moveGroup(_group: number | IEditorGroup, _location: number | IEditorGroup, _direction: GroupDirection): IEditorGroup {
612
		throw new Error('not implemented');
613 614
	}

615
	mergeGroup(_group: number | IEditorGroup, _target: number | IEditorGroup, _options?: IMergeGroupOptions): IEditorGroup {
616
		throw new Error('not implemented');
617 618
	}

619
	copyGroup(_group: number | IEditorGroup, _location: number | IEditorGroup, _direction: GroupDirection): IEditorGroup {
620
		throw new Error('not implemented');
621 622 623
	}
}

B
Benjamin Pasero 已提交
624
export class TestEditorGroup implements IEditorGroupView {
625 626 627

	constructor(public id: number) { }

628
	get group(): EditorGroup { throw new Error('not implemented'); }
629
	activeControl: IActiveEditor;
630 631 632
	activeEditor: IEditorInput;
	previewEditor: IEditorInput;
	count: number;
B
Benjamin Pasero 已提交
633
	disposed: boolean;
B
Benjamin Pasero 已提交
634
	editors: ReadonlyArray<IEditorInput> = [];
635
	label: string;
R
Rob Lourens 已提交
636
	whenRestored: Promise<void> = Promise.resolve(undefined);
B
Benjamin Pasero 已提交
637 638 639 640 641
	element: HTMLElement;
	minimumWidth: number;
	maximumWidth: number;
	minimumHeight: number;
	maximumHeight: number;
642 643

	onWillDispose: Event<void> = Event.None;
644
	onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
B
Benjamin Pasero 已提交
645 646
	onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
647 648
	onWillOpenEditor: Event<IEditorOpeningEvent> = Event.None;
	onDidOpenEditorFail: Event<IEditorInput> = Event.None;
B
Benjamin Pasero 已提交
649 650
	onDidFocus: Event<void> = Event.None;
	onDidChange: Event<{ width: number; height: number; }> = Event.None;
651

652
	getEditors(_order?: EditorsOrder): ReadonlyArray<IEditorInput> {
B
Benjamin Pasero 已提交
653 654 655
		return [];
	}

656
	getEditor(_index: number): IEditorInput {
657
		throw new Error('not implemented');
658 659
	}

660
	getIndexOfEditor(_editor: IEditorInput): number {
661 662 663
		return -1;
	}

J
Johannes Rieken 已提交
664
	openEditor(_editor: IEditorInput, _options?: IEditorOptions): Promise<IEditor> {
665
		throw new Error('not implemented');
666 667
	}

J
Johannes Rieken 已提交
668
	openEditors(_editors: IEditorInputWithOptions[]): Promise<IEditor> {
669
		throw new Error('not implemented');
670 671
	}

672
	isOpened(_editor: IEditorInput): boolean {
673 674 675
		return false;
	}

676
	isPinned(_editor: IEditorInput): boolean {
677 678 679
		return false;
	}

680
	isActive(_editor: IEditorInput): boolean {
681 682 683
		return false;
	}

684
	moveEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IMoveEditorOptions): void { }
685

686
	copyEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: ICopyEditorOptions): void { }
687

688
	closeEditor(_editor?: IEditorInput, options?: ICloseEditorOptions): Promise<void> {
B
Benjamin Pasero 已提交
689
		return Promise.resolve();
690 691
	}

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

J
Johannes Rieken 已提交
696
	closeAllEditors(): Promise<void> {
B
Benjamin Pasero 已提交
697
		return Promise.resolve();
698 699
	}

J
Johannes Rieken 已提交
700
	replaceEditors(_editors: IEditorReplacement[]): Promise<void> {
B
Benjamin Pasero 已提交
701
		return Promise.resolve();
702 703
	}

704
	pinEditor(_editor?: IEditorInput): void { }
705 706 707 708

	focus(): void { }

	invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T {
709
		throw new Error('not implemented');
710
	}
B
Benjamin Pasero 已提交
711 712

	isEmpty(): boolean { return true; }
713 714
	setActive(_isActive: boolean): void { }
	setLabel(_label: string): void { }
B
Benjamin Pasero 已提交
715 716
	dispose(): void { }
	toJSON(): object { return Object.create(null); }
717
	layout(_width: number, _height: number): void { }
718
	relayout() { }
719 720
}

B
Benjamin Pasero 已提交
721
export class TestEditorService implements EditorServiceImpl {
722 723 724 725 726

	_serviceBrand: ServiceIdentifier<any>;

	onDidActiveEditorChange: Event<void> = Event.None;
	onDidVisibleEditorsChange: Event<void> = Event.None;
B
Benjamin Pasero 已提交
727
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
728 729
	onDidOpenEditorFail: Event<IEditorIdentifier> = Event.None;

M
Matt Bierner 已提交
730
	activeControl: IActiveEditor;
731
	activeTextEditorWidget: any;
732
	activeEditor: IEditorInput;
733
	editors: ReadonlyArray<IEditorInput> = [];
B
Benjamin Pasero 已提交
734
	visibleControls: ReadonlyArray<IEditor> = [];
735
	visibleTextEditorWidgets = [];
B
Benjamin Pasero 已提交
736
	visibleEditors: ReadonlyArray<IEditorInput> = [];
737

738
	overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable {
R
Rob Lourens 已提交
739
		return toDisposable(() => undefined);
740 741
	}

742 743
	openEditor(_editor: any, _options?: any, _group?: any): Promise<any> {
		throw new Error('not implemented');
744 745
	}

746 747
	openEditors(_editors: any, _group?: any): Promise<IEditor[]> {
		throw new Error('not implemented');
748 749
	}

750
	isOpen(_editor: IEditorInput | IResourceInput | IUntitledResourceInput): boolean {
751 752 753
		return false;
	}

754
	getOpened(_editor: IEditorInput | IResourceInput | IUntitledResourceInput): IEditorInput {
755
		throw new Error('not implemented');
756 757
	}

758
	replaceEditors(_editors: any, _group: any) {
R
Rob Lourens 已提交
759
		return Promise.resolve(undefined);
760 761
	}

762
	invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
763
		throw new Error('not implemented');
764 765
	}

766
	createInput(_input: IResourceInput | IUntitledResourceInput | IResourceDiffInput | IResourceSideBySideInput): IEditorInput {
767
		throw new Error('not implemented');
768 769 770
	}
}

771 772 773 774
export class TestFileService implements IFileService {

	public _serviceBrand: any;

775 776
	public encoding: IResourceEncodings;

M
Matt Bierner 已提交
777 778
	private readonly _onFileChanges: Emitter<FileChangesEvent>;
	private readonly _onAfterOperation: Emitter<FileOperationEvent>;
779

780 781
	private content = 'Hello Html';

782 783 784 785 786
	constructor() {
		this._onFileChanges = new Emitter<FileChangesEvent>();
		this._onAfterOperation = new Emitter<FileOperationEvent>();
	}

787 788 789 790 791 792 793 794
	public setContent(content: string): void {
		this.content = content;
	}

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

795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
	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);
	}

J
Johannes Rieken 已提交
811
	resolveFile(resource: URI, _options?: IResolveFileOptions): Promise<IFileStat> {
B
Benjamin Pasero 已提交
812
		return Promise.resolve({
813 814
			resource,
			etag: Date.now().toString(),
B
Benjamin Pasero 已提交
815
			encoding: 'utf8',
B
Benjamin Pasero 已提交
816
			mtime: Date.now(),
817
			isDirectory: false,
B
Benjamin Pasero 已提交
818
			name: resources.basename(resource)
B
Benjamin Pasero 已提交
819
		});
820
	}
B
Benjamin Pasero 已提交
821

J
Johannes Rieken 已提交
822
	resolveFiles(toResolve: { resource: URI, options?: IResolveFileOptions }[]): Promise<IResolveFileResult[]> {
B
Benjamin Pasero 已提交
823
		return Promise.all(toResolve.map(resourceAndOption => this.resolveFile(resourceAndOption.resource, resourceAndOption.options))).then(stats => stats.map(stat => ({ stat, success: true })));
I
isidor 已提交
824 825
	}

J
Johannes Rieken 已提交
826
	existsFile(_resource: URI): Promise<boolean> {
B
Benjamin Pasero 已提交
827
		return Promise.resolve(true);
828
	}
B
Benjamin Pasero 已提交
829

J
Johannes Rieken 已提交
830
	resolveContent(resource: URI, _options?: IResolveContentOptions): Promise<IContent> {
B
Benjamin Pasero 已提交
831
		return Promise.resolve({
B
Benjamin Pasero 已提交
832
			resource: resource,
833
			value: this.content,
834
			etag: 'index.txt',
B
Benjamin Pasero 已提交
835 836
			encoding: 'utf8',
			mtime: Date.now(),
B
Benjamin Pasero 已提交
837
			name: resources.basename(resource)
E
Erich Gamma 已提交
838
		});
839
	}
E
Erich Gamma 已提交
840

J
Johannes Rieken 已提交
841
	resolveStreamContent(resource: URI, _options?: IResolveContentOptions): Promise<IStreamContent> {
B
Benjamin Pasero 已提交
842
		return Promise.resolve({
A
Alex Dima 已提交
843 844
			resource: resource,
			value: {
845
				on: (event: string, callback: Function): void => {
A
Alex Dima 已提交
846
					if (event === 'data') {
847
						callback(this.content);
A
Alex Dima 已提交
848 849 850 851 852 853 854 855
					}
					if (event === 'end') {
						callback();
					}
				}
			},
			etag: 'index.txt',
			encoding: 'utf8',
B
Benjamin Pasero 已提交
856
			mtime: Date.now(),
B
Benjamin Pasero 已提交
857
			name: resources.basename(resource)
A
Alex Dima 已提交
858
		});
859 860
	}

J
Johannes Rieken 已提交
861
	updateContent(resource: URI, _value: string | ITextSnapshot, _options?: IUpdateContentOptions): Promise<IFileStat> {
B
Benjamin Pasero 已提交
862
		return timeout(0).then(() => ({
863 864 865 866 867
			resource,
			etag: 'index.txt',
			encoding: 'utf8',
			mtime: Date.now(),
			isDirectory: false,
B
Benjamin Pasero 已提交
868
			name: resources.basename(resource)
B
Benjamin Pasero 已提交
869
		}));
870
	}
D
Daniel Imms 已提交
871

J
Johannes Rieken 已提交
872
	moveFile(_source: URI, _target: URI, _overwrite?: boolean): Promise<IFileStat> {
873
		return Promise.resolve(null!);
874
	}
D
Daniel Imms 已提交
875

J
Johannes Rieken 已提交
876
	copyFile(_source: URI, _target: URI, _overwrite?: boolean): Promise<IFileStat> {
877
		throw new Error('not implemented');
878
	}
D
Daniel Imms 已提交
879

J
Johannes Rieken 已提交
880
	createFile(_resource: URI, _content?: string, _options?: ICreateFileOptions): Promise<IFileStat> {
881
		throw new Error('not implemented');
E
Erich Gamma 已提交
882
	}
883

C
Christof Marti 已提交
884
	readFolder(_resource: URI) {
B
Benjamin Pasero 已提交
885
		return Promise.resolve([]);
C
Christof Marti 已提交
886 887
	}

J
Johannes Rieken 已提交
888
	createFolder(_resource: URI): Promise<IFileStat> {
889
		throw new Error('not implemented');
890 891
	}

892 893
	onDidChangeFileSystemProviderRegistrations = Event.None;

894
	registerProvider(_scheme: string, _provider) {
895 896 897
		return { dispose() { } };
	}

898 899
	activateProvider(_scheme: string): Promise<void> {
		throw new Error('not implemented');
900 901
	}

902 903 904 905
	canHandleResource(resource: URI): boolean {
		return resource.scheme === 'file';
	}

J
Johannes Rieken 已提交
906
	del(_resource: URI, _options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> {
907
		return Promise.resolve();
908 909
	}

910
	watchFileChanges(_resource: URI): void {
911 912
	}

913
	unwatchFileChanges(_resource: URI): void {
914 915
	}

916
	getWriteEncoding(_resource: URI): string {
917 918
		return 'utf8';
	}
D
Daniel Imms 已提交
919

920
	dispose(): void {
E
Erich Gamma 已提交
921
	}
922
}
923

924 925
export class TestBackupFileService implements IBackupFileService {
	public _serviceBrand: any;
926

J
Johannes Rieken 已提交
927
	public hasBackups(): Promise<boolean> {
B
Benjamin Pasero 已提交
928
		return Promise.resolve(false);
929 930
	}

J
Johannes Rieken 已提交
931
	public hasBackup(_resource: URI): Promise<boolean> {
B
Benjamin Pasero 已提交
932
		return Promise.resolve(false);
933 934
	}

935
	public loadBackupResource(resource: URI): Promise<URI | undefined> {
B
Benjamin Pasero 已提交
936 937
		return this.hasBackup(resource).then(hasBackup => {
			if (hasBackup) {
938
				return this.toBackupResource(resource);
B
Benjamin Pasero 已提交
939 940
			}

R
Rob Lourens 已提交
941
			return undefined;
B
Benjamin Pasero 已提交
942 943 944
		});
	}

J
Johannes Rieken 已提交
945
	public registerResourceForBackup(_resource: URI): Promise<void> {
B
Benjamin Pasero 已提交
946
		return Promise.resolve();
D
Daniel Imms 已提交
947 948
	}

J
Johannes Rieken 已提交
949
	public deregisterResourceForBackup(_resource: URI): Promise<void> {
B
Benjamin Pasero 已提交
950
		return Promise.resolve();
D
Daniel Imms 已提交
951 952
	}

953
	public toBackupResource(_resource: URI): URI {
954
		throw new Error('not implemented');
D
Daniel Imms 已提交
955
	}
956

J
Johannes Rieken 已提交
957
	public backupResource(_resource: URI, _content: ITextSnapshot): Promise<void> {
B
Benjamin Pasero 已提交
958
		return Promise.resolve();
959 960
	}

J
Johannes Rieken 已提交
961
	public getWorkspaceFileBackups(): Promise<URI[]> {
B
Benjamin Pasero 已提交
962
		return Promise.resolve([]);
963 964
	}

965 966 967 968 969
	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);
970 971
	}

J
Johannes Rieken 已提交
972
	public resolveBackupContent(_backup: URI): Promise<ITextBufferFactory> {
973
		throw new Error('not implemented');
974 975
	}

J
Johannes Rieken 已提交
976
	public discardResourceBackup(_resource: URI): Promise<void> {
B
Benjamin Pasero 已提交
977
		return Promise.resolve();
978 979
	}

J
Johannes Rieken 已提交
980
	public discardAllWorkspaceBackups(): Promise<void> {
B
Benjamin Pasero 已提交
981
		return Promise.resolve();
982
	}
983
}
D
Daniel Imms 已提交
984

B
Benjamin Pasero 已提交
985 986 987 988 989 990 991
export class TestCodeEditorService implements ICodeEditorService {
	_serviceBrand: any;

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

994 995
	addCodeEditor(_editor: ICodeEditor): void { }
	removeCodeEditor(_editor: ICodeEditor): void { }
B
Benjamin Pasero 已提交
996
	listCodeEditors(): ICodeEditor[] { return []; }
997 998
	addDiffEditor(_editor: IDiffEditor): void { }
	removeDiffEditor(_editor: IDiffEditor): void { }
B
Benjamin Pasero 已提交
999
	listDiffEditors(): IDiffEditor[] { return []; }
1000
	getFocusedCodeEditor(): ICodeEditor | null { return null; }
1001 1002 1003 1004 1005
	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) { }
1006 1007
	getActiveCodeEditor(): ICodeEditor | null { return null; }
	openCodeEditor(_input: IResourceInput, _source: ICodeEditor, _sideBySide?: boolean): Promise<ICodeEditor | null> { return Promise.resolve(null); }
B
Benjamin Pasero 已提交
1008 1009
}

1010 1011 1012 1013
export class TestWindowService implements IWindowService {

	public _serviceBrand: any;

1014
	onDidChangeFocus: Event<boolean> = new Emitter<boolean>().event;
S
SteVen Batten 已提交
1015
	onDidChangeMaximize: Event<boolean>;
1016

1017 1018
	hasFocus = true;

J
Johannes Rieken 已提交
1019
	isFocused(): Promise<boolean> {
B
Benjamin Pasero 已提交
1020
		return Promise.resolve(false);
1021 1022
	}

J
Johannes Rieken 已提交
1023
	isMaximized(): Promise<boolean> {
B
Benjamin Pasero 已提交
1024
		return Promise.resolve(false);
S
SteVen Batten 已提交
1025 1026
	}

1027 1028 1029 1030
	getConfiguration(): IWindowConfiguration {
		return Object.create(null);
	}

1031 1032 1033 1034
	getCurrentWindowId(): number {
		return 0;
	}

J
Johannes Rieken 已提交
1035
	pickFileFolderAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1036
		return Promise.resolve();
1037 1038
	}

J
Johannes Rieken 已提交
1039
	pickFileAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1040
		return Promise.resolve();
1041 1042
	}

J
Johannes Rieken 已提交
1043
	pickFolderAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1044
		return Promise.resolve();
1045 1046
	}

J
Johannes Rieken 已提交
1047
	pickWorkspaceAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1048
		return Promise.resolve();
1049 1050
	}

J
Johannes Rieken 已提交
1051
	reloadWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1052
		return Promise.resolve();
1053 1054
	}

J
Johannes Rieken 已提交
1055
	openDevTools(): Promise<void> {
B
Benjamin Pasero 已提交
1056
		return Promise.resolve();
1057 1058
	}

J
Johannes Rieken 已提交
1059
	toggleDevTools(): Promise<void> {
B
Benjamin Pasero 已提交
1060
		return Promise.resolve();
1061 1062
	}

J
Johannes Rieken 已提交
1063
	closeWorkspace(): Promise<void> {
B
Benjamin Pasero 已提交
1064
		return Promise.resolve();
1065 1066
	}

M
Matt Bierner 已提交
1067
	enterWorkspace(_path: URI): Promise<IEnterWorkspaceResult | undefined> {
J
Johannes Rieken 已提交
1068
		return Promise.resolve(undefined);
1069 1070
	}

J
Johannes Rieken 已提交
1071
	toggleFullScreen(): Promise<void> {
B
Benjamin Pasero 已提交
1072
		return Promise.resolve();
1073 1074
	}

J
Johannes Rieken 已提交
1075
	setRepresentedFilename(_fileName: string): Promise<void> {
B
Benjamin Pasero 已提交
1076
		return Promise.resolve();
1077 1078
	}

J
Johannes Rieken 已提交
1079
	getRecentlyOpened(): Promise<IRecentlyOpened> {
1080 1081 1082 1083
		return Promise.resolve({
			workspaces: [],
			files: []
		});
1084 1085
	}

J
Johannes Rieken 已提交
1086
	focusWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1087
		return Promise.resolve();
1088 1089
	}

J
Johannes Rieken 已提交
1090
	maximizeWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1091
		return Promise.resolve();
S
SteVen Batten 已提交
1092 1093
	}

J
Johannes Rieken 已提交
1094
	unmaximizeWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1095
		return Promise.resolve();
S
SteVen Batten 已提交
1096 1097
	}

J
Johannes Rieken 已提交
1098
	minimizeWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1099
		return Promise.resolve();
S
SteVen Batten 已提交
1100 1101
	}

1102
	openWindow(_uris: IURIToOpen[], _options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): Promise<void> {
B
Benjamin Pasero 已提交
1103
		return Promise.resolve();
B
Benjamin Pasero 已提交
1104 1105
	}

J
Johannes Rieken 已提交
1106
	closeWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1107
		return Promise.resolve();
1108 1109
	}

J
Johannes Rieken 已提交
1110
	setDocumentEdited(_flag: boolean): Promise<void> {
B
Benjamin Pasero 已提交
1111
		return Promise.resolve();
1112 1113
	}

J
Johannes Rieken 已提交
1114
	onWindowTitleDoubleClick(): Promise<void> {
B
Benjamin Pasero 已提交
1115
		return Promise.resolve();
1116
	}
1117

J
Johannes Rieken 已提交
1118
	show(): Promise<void> {
B
Benjamin Pasero 已提交
1119
		return Promise.resolve();
J
Joao 已提交
1120 1121
	}

J
Johannes Rieken 已提交
1122
	showMessageBox(_options: Electron.MessageBoxOptions): Promise<IMessageBoxResult> {
B
Benjamin Pasero 已提交
1123
		return Promise.resolve({ button: 0 });
1124 1125
	}

J
Johannes Rieken 已提交
1126
	showSaveDialog(_options: Electron.SaveDialogOptions): Promise<string> {
1127
		throw new Error('not implemented');
1128
	}
1129

J
Johannes Rieken 已提交
1130
	showOpenDialog(_options: Electron.OpenDialogOptions): Promise<string[]> {
1131
		throw new Error('not implemented');
1132
	}
1133

J
Johannes Rieken 已提交
1134
	updateTouchBar(_items: ISerializableCommandAction[][]): Promise<void> {
B
Benjamin Pasero 已提交
1135
		return Promise.resolve();
1136
	}
1137 1138

	resolveProxy(url: string): Promise<string | undefined> {
R
Rob Lourens 已提交
1139
		return Promise.resolve(undefined);
1140
	}
1141 1142
}

1143 1144
export class TestLifecycleService implements ILifecycleService {

1145
	public _serviceBrand: any;
1146

1147
	public phase: LifecyclePhase;
1148
	public startupKind: StartupKind;
1149

1150
	private _onBeforeShutdown = new Emitter<BeforeShutdownEvent>();
1151
	private _onWillShutdown = new Emitter<WillShutdownEvent>();
1152
	private _onShutdown = new Emitter<void>();
1153

J
Johannes Rieken 已提交
1154
	when(): Promise<void> {
B
Benjamin Pasero 已提交
1155
		return Promise.resolve();
B
Benjamin Pasero 已提交
1156
	}
1157

1158
	public fireShutdown(reason = ShutdownReason.QUIT): void {
1159
		this._onWillShutdown.fire({
1160 1161 1162
			join: () => { },
			reason
		});
1163 1164
	}

1165 1166 1167 1168 1169 1170
	public fireWillShutdown(event: BeforeShutdownEvent): void {
		this._onBeforeShutdown.fire(event);
	}

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

1173
	public get onWillShutdown(): Event<WillShutdownEvent> {
1174 1175 1176
		return this._onWillShutdown.event;
	}

1177
	public get onShutdown(): Event<void> {
1178 1179
		return this._onShutdown.event;
	}
1180 1181
}

1182 1183 1184 1185
export class TestWindowsService implements IWindowsService {

	_serviceBrand: any;

1186 1187
	public windowCount = 1;

1188 1189
	onWindowOpen: Event<number>;
	onWindowFocus: Event<number>;
1190
	onWindowBlur: Event<number>;
S
SteVen Batten 已提交
1191 1192
	onWindowMaximize: Event<number>;
	onWindowUnmaximize: Event<number>;
S
SteVen Batten 已提交
1193
	onRecentlyOpenedChange: Event<void>;
1194

J
Johannes Rieken 已提交
1195
	isFocused(_windowId: number): Promise<boolean> {
B
Benjamin Pasero 已提交
1196
		return Promise.resolve(false);
1197 1198
	}

J
Johannes Rieken 已提交
1199
	pickFileFolderAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1200
		return Promise.resolve();
1201
	}
1202

J
Johannes Rieken 已提交
1203
	pickFileAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1204
		return Promise.resolve();
1205
	}
1206

J
Johannes Rieken 已提交
1207
	pickFolderAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1208
		return Promise.resolve();
1209
	}
1210

J
Johannes Rieken 已提交
1211
	pickWorkspaceAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
B
Benjamin Pasero 已提交
1212
		return Promise.resolve();
1213 1214
	}

J
Johannes Rieken 已提交
1215
	reloadWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1216
		return Promise.resolve();
1217
	}
1218

J
Johannes Rieken 已提交
1219
	openDevTools(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1220
		return Promise.resolve();
1221
	}
1222

J
Johannes Rieken 已提交
1223
	toggleDevTools(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1224
		return Promise.resolve();
1225
	}
1226

J
Johannes Rieken 已提交
1227
	closeWorkspace(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1228
		return Promise.resolve();
1229
	}
1230

1231
	enterWorkspace(_windowId: number, _path: URI): Promise<IEnterWorkspaceResult | undefined> {
J
Johannes Rieken 已提交
1232
		return Promise.resolve(undefined);
1233 1234
	}

J
Johannes Rieken 已提交
1235
	toggleFullScreen(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1236
		return Promise.resolve();
1237
	}
1238

J
Johannes Rieken 已提交
1239
	setRepresentedFilename(_windowId: number, _fileName: string): Promise<void> {
B
Benjamin Pasero 已提交
1240
		return Promise.resolve();
1241
	}
1242

1243
	addRecentlyOpened(_workspaces: URI[], _folders: URI[], _files: URI[]): Promise<void> {
B
Benjamin Pasero 已提交
1244
		return Promise.resolve();
1245
	}
1246

J
Johannes Rieken 已提交
1247
	removeFromRecentlyOpened(_paths: URI[]): Promise<void> {
B
Benjamin Pasero 已提交
1248
		return Promise.resolve();
1249
	}
1250

J
Johannes Rieken 已提交
1251
	clearRecentlyOpened(): Promise<void> {
B
Benjamin Pasero 已提交
1252
		return Promise.resolve();
C
22768  
Cristian 已提交
1253
	}
1254

J
Johannes Rieken 已提交
1255
	getRecentlyOpened(_windowId: number): Promise<IRecentlyOpened> {
1256 1257 1258 1259
		return Promise.resolve({
			workspaces: [],
			files: []
		});
1260
	}
1261

J
Johannes Rieken 已提交
1262
	focusWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1263
		return Promise.resolve();
1264
	}
1265

J
Johannes Rieken 已提交
1266
	closeWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1267
		return Promise.resolve();
1268 1269
	}

J
Johannes Rieken 已提交
1270
	isMaximized(_windowId: number): Promise<boolean> {
1271
		return Promise.resolve(false);
1272
	}
1273

J
Johannes Rieken 已提交
1274
	maximizeWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1275
		return Promise.resolve();
1276
	}
1277

J
Johannes Rieken 已提交
1278
	minimizeWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1279
		return Promise.resolve();
S
SteVen Batten 已提交
1280 1281
	}

J
Johannes Rieken 已提交
1282
	unmaximizeWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1283
		return Promise.resolve();
1284
	}
1285

J
Johannes Rieken 已提交
1286
	onWindowTitleDoubleClick(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1287
		return Promise.resolve();
1288
	}
1289

J
Johannes Rieken 已提交
1290
	setDocumentEdited(_windowId: number, _flag: boolean): Promise<void> {
B
Benjamin Pasero 已提交
1291
		return Promise.resolve();
1292
	}
1293

J
Johannes Rieken 已提交
1294
	quit(): Promise<void> {
B
Benjamin Pasero 已提交
1295
		return Promise.resolve();
1296
	}
1297

J
Johannes Rieken 已提交
1298
	relaunch(_options: { addArgs?: string[], removeArgs?: string[] }): Promise<void> {
B
Benjamin Pasero 已提交
1299
		return Promise.resolve();
J
Johannes Rieken 已提交
1300
	}
1301

J
Johannes Rieken 已提交
1302
	whenSharedProcessReady(): Promise<void> {
B
Benjamin Pasero 已提交
1303
		return Promise.resolve();
1304
	}
1305

J
Johannes Rieken 已提交
1306
	toggleSharedProcess(): Promise<void> {
B
Benjamin Pasero 已提交
1307
		return Promise.resolve();
1308
	}
1309

1310
	// Global methods
1311
	openWindow(_windowId: number, _uris: IURIToOpen[], _options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): Promise<void> {
B
Benjamin Pasero 已提交
1312
		return Promise.resolve();
1313
	}
1314

J
Johannes Rieken 已提交
1315
	openNewWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1316
		return Promise.resolve();
1317
	}
1318

J
Johannes Rieken 已提交
1319
	showWindow(_windowId: number): Promise<void> {
B
Benjamin Pasero 已提交
1320
		return Promise.resolve();
1321
	}
1322

J
Johannes Rieken 已提交
1323
	getWindows(): Promise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]> {
1324
		throw new Error('not implemented');
1325
	}
1326

J
Johannes Rieken 已提交
1327
	getWindowCount(): Promise<number> {
B
Benjamin Pasero 已提交
1328
		return Promise.resolve(this.windowCount);
1329
	}
1330

J
Johannes Rieken 已提交
1331
	log(_severity: string, ..._messages: string[]): Promise<void> {
B
Benjamin Pasero 已提交
1332
		return Promise.resolve();
1333
	}
1334

M
Martin Aeschlimann 已提交
1335
	showItemInFolder(_path: URI): Promise<void> {
B
Benjamin Pasero 已提交
1336
		return Promise.resolve();
1337 1338
	}

J
Johannes Rieken 已提交
1339
	newWindowTab(): Promise<void> {
B
Benjamin Pasero 已提交
1340
		return Promise.resolve();
1341 1342
	}

J
Johannes Rieken 已提交
1343
	showPreviousWindowTab(): Promise<void> {
B
Benjamin Pasero 已提交
1344
		return Promise.resolve();
1345 1346
	}

J
Johannes Rieken 已提交
1347
	showNextWindowTab(): Promise<void> {
B
Benjamin Pasero 已提交
1348
		return Promise.resolve();
1349 1350
	}

J
Johannes Rieken 已提交
1351
	moveWindowTabToNewWindow(): Promise<void> {
B
Benjamin Pasero 已提交
1352
		return Promise.resolve();
1353 1354
	}

J
Johannes Rieken 已提交
1355
	mergeAllWindowTabs(): Promise<void> {
B
Benjamin Pasero 已提交
1356
		return Promise.resolve();
1357 1358
	}

J
Johannes Rieken 已提交
1359
	toggleWindowTabsBar(): Promise<void> {
B
Benjamin Pasero 已提交
1360
		return Promise.resolve();
1361 1362
	}

J
Johannes Rieken 已提交
1363
	updateTouchBar(_windowId: number, _items: ISerializableCommandAction[][]): Promise<void> {
B
Benjamin Pasero 已提交
1364
		return Promise.resolve();
1365 1366
	}

J
Johannes Rieken 已提交
1367
	getActiveWindowId(): Promise<number | undefined> {
B
Benjamin Pasero 已提交
1368
		return Promise.resolve(undefined);
J
Joao Moreno 已提交
1369 1370
	}

1371 1372
	// This needs to be handled from browser process to prevent
	// foreground ordering issues on Windows
J
Johannes Rieken 已提交
1373
	openExternal(_url: string): Promise<boolean> {
B
Benjamin Pasero 已提交
1374
		return Promise.resolve(true);
1375 1376 1377
	}

	// TODO: this is a bit backwards
J
Johannes Rieken 已提交
1378
	startCrashReporter(_config: Electron.CrashReporterStartOptions): Promise<void> {
B
Benjamin Pasero 已提交
1379
		return Promise.resolve();
1380
	}
1381

J
Johannes Rieken 已提交
1382
	showMessageBox(_windowId: number, _options: Electron.MessageBoxOptions): Promise<IMessageBoxResult> {
1383
		throw new Error('not implemented');
1384 1385
	}

J
Johannes Rieken 已提交
1386
	showSaveDialog(_windowId: number, _options: Electron.SaveDialogOptions): Promise<string> {
1387
		throw new Error('not implemented');
1388 1389
	}

J
Johannes Rieken 已提交
1390
	showOpenDialog(_windowId: number, _options: Electron.OpenDialogOptions): Promise<string[]> {
1391
		throw new Error('not implemented');
1392
	}
J
Joao Moreno 已提交
1393

J
Johannes Rieken 已提交
1394
	openAboutDialog(): Promise<void> {
B
Benjamin Pasero 已提交
1395
		return Promise.resolve();
J
Joao Moreno 已提交
1396
	}
1397 1398

	resolveProxy(windowId: number, url: string): Promise<string | undefined> {
R
Rob Lourens 已提交
1399
		return Promise.resolve(undefined);
1400
	}
1401
}
B
Benjamin Pasero 已提交
1402

1403 1404 1405 1406 1407 1408 1409
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

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

1410
	public onDidChangeConfiguration() {
1411 1412 1413
		return { dispose() { } };
	}

1414
	getValue<T>(resource: URI, arg2?: any, arg3?: any): T {
1415 1416
		const position: IPosition | null = EditorPosition.isIPosition(arg2) ? arg2 : null;
		const section: string | undefined = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
1417
		return this.configurationService.getValue(section, { resource });
1418
	}
B
Benjamin Pasero 已提交
1419 1420
}

S
Sandeep Somavarapu 已提交
1421 1422 1423 1424 1425
export class TestTextResourcePropertiesService implements ITextResourcePropertiesService {

	_serviceBrand: any;

	constructor(
1426
		@IConfigurationService private readonly configurationService: IConfigurationService,
S
Sandeep Somavarapu 已提交
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
	) {
	}

	getEOL(resource: URI): string {
		const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files');
		if (filesConfiguration && filesConfiguration.eol) {
			if (filesConfiguration.eol !== 'auto') {
				return filesConfiguration.eol;
			}
		}
		return (isLinux || isMacintosh) ? '\n' : '\r\n';
	}
}


R
Ramya Achutha Rao 已提交
1442 1443 1444 1445 1446 1447 1448 1449
export class TestHashService implements IHashService {
	_serviceBrand: any;

	createSHA1(content: string): string {
		return content;
	}
}

1450 1451 1452 1453 1454
export class TestViewletService implements IViewletService {

	_serviceBrand: ServiceIdentifier<any>;

	readonly onDidViewletRegister: Event<ViewletDescriptor> = new Emitter<ViewletDescriptor>().event;
1455
	readonly onDidViewletDeregister: Event<ViewletDescriptor> = new Emitter<ViewletDescriptor>().event;
1456 1457 1458
	onDidViewletOpen: Event<IViewlet> = new Emitter<IViewlet>().event;
	onDidViewletClose: Event<IViewlet> = new Emitter<IViewlet>().event;

1459
	openViewlet(_id: string, _focus?: boolean): Promise<IViewlet | null> { return Promise.resolve(null); }
1460

1461
	getActiveViewlet(): IViewlet | null { return null; }
1462

1463
	getDefaultViewletId(): string { return ''; }
1464

1465
	getViewlet(_id: string): ViewletDescriptor | undefined { return undefined; }
1466

1467
	getAllViewlets(): ViewletDescriptor[] { return []; }
1468

1469
	getViewlets(): ViewletDescriptor[] { return []; }
1470

1471
	getProgressIndicator(_id: string): IProgressService | null { return null; }
1472
}