extHostLanguageFeatures.test.ts 37.1 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import * as assert from 'assert';
9
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
J
Johannes Rieken 已提交
10
import { setUnexpectedErrorHandler, errorHandler } from 'vs/base/common/errors';
11
import URI from 'vs/base/common/uri';
J
Johannes Rieken 已提交
12
import * as types from 'vs/workbench/api/node/extHostTypes';
A
Alex Dima 已提交
13
import { TextModel as EditorModel } from 'vs/editor/common/model/textModel';
J
Johannes Rieken 已提交
14 15
import { Position as EditorPosition } from 'vs/editor/common/core/position';
import { Range as EditorRange } from 'vs/editor/common/core/range';
A
Alex Dima 已提交
16
import { TestRPCProtocol } from './testRPCProtocol';
J
Johannes Rieken 已提交
17
import { IMarkerService } from 'vs/platform/markers/common/markers';
18
import { MarkerService } from 'vs/platform/markers/common/markerService';
J
Johannes Rieken 已提交
19
import { ExtHostLanguageFeatures } from 'vs/workbench/api/node/extHostLanguageFeatures';
20
import { MainThreadLanguageFeatures } from 'vs/workbench/api/electron-browser/mainThreadLanguageFeatures';
J
Johannes Rieken 已提交
21
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
22 23
import { MainThreadCommands } from 'vs/workbench/api/electron-browser/mainThreadCommands';
import { IHeapService } from 'vs/workbench/api/electron-browser/mainThreadHeapService';
J
Johannes Rieken 已提交
24
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
J
Johannes Rieken 已提交
25
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
26
import { getDocumentSymbols } from 'vs/editor/contrib/quickOpen/quickOpen';
27
import { DocumentSymbolProviderRegistry, DocumentHighlightKind, Hover, ResourceTextEdit } from 'vs/editor/common/modes';
28 29 30 31 32 33
import { getCodeLensData } from 'vs/editor/contrib/codelens/codelens';
import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition } from 'vs/editor/contrib/goToDeclaration/goToDeclaration';
import { getHover } from 'vs/editor/contrib/hover/getHover';
import { getOccurrencesAtPosition } from 'vs/editor/contrib/wordHighlighter/wordHighlighter';
import { provideReferences } from 'vs/editor/contrib/referenceSearch/referenceSearch';
import { getCodeActions } from 'vs/editor/contrib/quickFix/quickFix';
J
Johannes Rieken 已提交
34
import { getWorkspaceSymbols } from 'vs/workbench/parts/search/common/search';
35 36 37 38 39
import { rename } from 'vs/editor/contrib/rename/rename';
import { provideSignatureHelp } from 'vs/editor/contrib/parameterHints/provideSignatureHelp';
import { provideSuggestionItems } from 'vs/editor/contrib/suggest/suggest';
import { getDocumentFormattingEdits, getDocumentRangeFormattingEdits, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/format';
import { getLinks } from 'vs/editor/contrib/links/getLinks';
J
Johannes Rieken 已提交
40 41 42 43
import { asWinJsPromise } from 'vs/base/common/async';
import { MainContext, ExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
44
import * as vscode from 'vscode';
B
Benjamin Pasero 已提交
45
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
46
import { NullLogService } from 'vs/platform/log/common/log';
A
Alex Dima 已提交
47
import { ITextModel, EndOfLineSequence } from 'vs/editor/common/model';
48 49

const defaultSelector = { scheme: 'far' };
A
Alex Dima 已提交
50
const model: ITextModel = EditorModel.createFromString(
51 52 53 54 55
	[
		'This is the first line',
		'This is the second line',
		'This is the third line',
	].join('\n'),
56
	undefined,
57
	undefined,
J
Johannes Rieken 已提交
58
	URI.parse('far://testing/file.a'));
59 60 61 62

let extHost: ExtHostLanguageFeatures;
let mainThread: MainThreadLanguageFeatures;
let disposables: vscode.Disposable[] = [];
A
Alex Dima 已提交
63
let rpcProtocol: TestRPCProtocol;
64 65
let originalErrorHandler: (e: any) => any;

J
Johannes Rieken 已提交
66
suite('ExtHostLanguageFeatures', function () {
67 68 69

	suiteSetup(() => {

A
Alex Dima 已提交
70
		rpcProtocol = new TestRPCProtocol();
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

		// Use IInstantiationService to get typechecking when instantiating
		let inst: IInstantiationService;
		{
			let instantiationService = new TestInstantiationService();
			instantiationService.stub(IMarkerService, MarkerService);
			instantiationService.stub(IHeapService, {
				_serviceBrand: undefined,
				trackRecursive(args) {
					// nothing
					return args;
				}
			});
			inst = instantiationService;
		}
J
Johannes Rieken 已提交
86

87 88 89
		originalErrorHandler = errorHandler.getUnexpectedErrorHandler();
		setUnexpectedErrorHandler(() => { });

A
Alex Dima 已提交
90
		const extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol);
J
Johannes Rieken 已提交
91 92 93 94 95
		extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
			addedDocuments: [{
				isDirty: false,
				versionId: model.getVersionId(),
				modeId: model.getLanguageIdentifier().language,
96
				uri: model.uri,
J
Johannes Rieken 已提交
97 98 99
				lines: model.getValue().split(model.getEOL()),
				EOL: model.getEOL(),
			}]
100
		});
A
Alex Dima 已提交
101 102
		const extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
		rpcProtocol.set(ExtHostContext.ExtHostDocuments, extHostDocuments);
103

104 105
		const heapService = new ExtHostHeapService();

A
Alex Dima 已提交
106 107 108
		const commands = new ExtHostCommands(rpcProtocol, heapService, new NullLogService());
		rpcProtocol.set(ExtHostContext.ExtHostCommands, commands);
		rpcProtocol.set(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, rpcProtocol));
109

A
Alex Dima 已提交
110 111
		const diagnostics = new ExtHostDiagnostics(rpcProtocol);
		rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, diagnostics);
112

A
Alex Dima 已提交
113 114
		extHost = new ExtHostLanguageFeatures(rpcProtocol, extHostDocuments, commands, heapService, diagnostics);
		rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, extHost);
115

A
Alex Dima 已提交
116
		mainThread = rpcProtocol.set(MainContext.MainThreadLanguageFeatures, inst.createInstance(MainThreadLanguageFeatures, rpcProtocol));
117 118 119 120
	});

	suiteTeardown(() => {
		setUnexpectedErrorHandler(originalErrorHandler);
121
		model.dispose();
J
Johannes Rieken 已提交
122
		mainThread.dispose();
123 124
	});

J
Johannes Rieken 已提交
125
	teardown(function () {
126 127 128
		while (disposables.length) {
			disposables.pop().dispose();
		}
A
Alex Dima 已提交
129
		return rpcProtocol.sync();
130 131
	});

132 133
	// --- outline

J
Johannes Rieken 已提交
134
	test('DocumentSymbols, register/deregister', function () {
135
		assert.equal(DocumentSymbolProviderRegistry.all(model).length, 0);
136
		let d1 = extHost.registerDocumentSymbolProvider(defaultSelector, <vscode.DocumentSymbolProvider>{
137 138 139 140 141
			provideDocumentSymbols() {
				return [];
			}
		});

A
Alex Dima 已提交
142
		return rpcProtocol.sync().then(() => {
143
			assert.equal(DocumentSymbolProviderRegistry.all(model).length, 1);
144
			d1.dispose();
A
Alex Dima 已提交
145
			return rpcProtocol.sync();
146 147 148 149
		});

	});

J
Johannes Rieken 已提交
150
	test('DocumentSymbols, evil provider', function () {
151
		disposables.push(extHost.registerDocumentSymbolProvider(defaultSelector, <vscode.DocumentSymbolProvider>{
152 153 154 155
			provideDocumentSymbols(): any {
				throw new Error('evil document symbol provider');
			}
		}));
156
		disposables.push(extHost.registerDocumentSymbolProvider(defaultSelector, <vscode.DocumentSymbolProvider>{
157
			provideDocumentSymbols(): any {
158
				return [new types.SymbolInformation('test', types.SymbolKind.Field, new types.Range(0, 0, 0, 0))];
159 160 161
			}
		}));

A
Alex Dima 已提交
162
		return rpcProtocol.sync().then(() => {
163

164
			return getDocumentSymbols(model).then(value => {
165 166 167 168 169
				assert.equal(value.entries.length, 1);
			});
		});
	});

J
Johannes Rieken 已提交
170
	test('DocumentSymbols, data conversion', function () {
171
		disposables.push(extHost.registerDocumentSymbolProvider(defaultSelector, <vscode.DocumentSymbolProvider>{
172
			provideDocumentSymbols(): any {
173
				return [new types.SymbolInformation('test', types.SymbolKind.Field, new types.Range(0, 0, 0, 0))];
174 175 176
			}
		}));

A
Alex Dima 已提交
177
		return rpcProtocol.sync().then(() => {
178

179
			return getDocumentSymbols(model).then(value => {
180 181 182
				assert.equal(value.entries.length, 1);

				let entry = value.entries[0];
183 184
				assert.equal(entry.name, 'test');
				assert.deepEqual(entry.location.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
185 186 187
			});
		});
	});
188 189 190

	// --- code lens

J
Johannes Rieken 已提交
191
	test('CodeLens, evil provider', function () {
192

193
		disposables.push(extHost.registerCodeLensProvider(defaultSelector, <vscode.CodeLensProvider>{
J
tslint  
Johannes Rieken 已提交
194
			provideCodeLenses(): any {
B
Benjamin Pasero 已提交
195
				throw new Error('evil');
196 197
			}
		}));
198
		disposables.push(extHost.registerCodeLensProvider(defaultSelector, <vscode.CodeLensProvider>{
199 200 201 202 203
			provideCodeLenses() {
				return [new types.CodeLens(new types.Range(0, 0, 0, 0))];
			}
		}));

A
Alex Dima 已提交
204
		return rpcProtocol.sync().then(() => {
205
			return getCodeLensData(model).then(value => {
206 207 208 209 210
				assert.equal(value.length, 1);
			});
		});
	});

J
Johannes Rieken 已提交
211
	test('CodeLens, do not resolve a resolved lens', function () {
212

213
		disposables.push(extHost.registerCodeLensProvider(defaultSelector, <vscode.CodeLensProvider>{
J
tslint  
Johannes Rieken 已提交
214
			provideCodeLenses(): any {
215 216 217 218
				return [new types.CodeLens(
					new types.Range(0, 0, 0, 0),
					{ command: 'id', title: 'Title' })];
			},
J
tslint  
Johannes Rieken 已提交
219
			resolveCodeLens(): any {
220 221 222 223
				assert.ok(false, 'do not resolve');
			}
		}));

A
Alex Dima 已提交
224
		return rpcProtocol.sync().then(() => {
225

226
			return getCodeLensData(model).then(value => {
227 228 229
				assert.equal(value.length, 1);
				let data = value[0];

230
				return asWinJsPromise((token) => {
231
					return data.provider.resolveCodeLens(model, data.symbol, token);
232
				}).then(symbol => {
J
Johannes Rieken 已提交
233 234
					assert.equal(symbol.command.id, 'id');
					assert.equal(symbol.command.title, 'Title');
235 236 237 238 239
				});
			});
		});
	});

J
Johannes Rieken 已提交
240
	test('CodeLens, missing command', function () {
241

242
		disposables.push(extHost.registerCodeLensProvider(defaultSelector, <vscode.CodeLensProvider>{
243 244 245 246 247
			provideCodeLenses() {
				return [new types.CodeLens(new types.Range(0, 0, 0, 0))];
			}
		}));

A
Alex Dima 已提交
248
		return rpcProtocol.sync().then(() => {
249

250
			return getCodeLensData(model).then(value => {
251 252 253
				assert.equal(value.length, 1);

				let data = value[0];
254
				return asWinJsPromise((token) => {
255
					return data.provider.resolveCodeLens(model, data.symbol, token);
256
				}).then(symbol => {
257

J
Johannes Rieken 已提交
258 259
					assert.equal(symbol.command.id, 'missing');
					assert.equal(symbol.command.title, '<<MISSING COMMAND>>');
260 261 262 263
				});
			});
		});
	});
J
Johannes Rieken 已提交
264 265 266

	// --- definition

J
Johannes Rieken 已提交
267
	test('Definition, data conversion', function () {
J
Johannes Rieken 已提交
268

269
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
J
Johannes Rieken 已提交
270
			provideDefinition(): any {
271
				return [new types.Location(model.uri, new types.Range(1, 2, 3, 4))];
J
Johannes Rieken 已提交
272 273 274
			}
		}));

A
Alex Dima 已提交
275
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
276

277
			return getDefinitionsAtPosition(model, new EditorPosition(1, 1)).then(value => {
J
Johannes Rieken 已提交
278 279 280
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 2, startColumn: 3, endLineNumber: 4, endColumn: 5 });
281
				assert.equal(entry.uri.toString(), model.uri.toString());
J
Johannes Rieken 已提交
282 283 284 285
			});
		});
	});

J
Johannes Rieken 已提交
286
	test('Definition, one or many', function () {
J
Johannes Rieken 已提交
287

288
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
J
Johannes Rieken 已提交
289
			provideDefinition(): any {
290
				return [new types.Location(model.uri, new types.Range(1, 1, 1, 1))];
J
Johannes Rieken 已提交
291 292
			}
		}));
293
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
J
Johannes Rieken 已提交
294
			provideDefinition(): any {
295
				return new types.Location(model.uri, new types.Range(1, 1, 1, 1));
J
Johannes Rieken 已提交
296 297 298
			}
		}));

A
Alex Dima 已提交
299
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
300

301
			return getDefinitionsAtPosition(model, new EditorPosition(1, 1)).then(value => {
J
Johannes Rieken 已提交
302 303 304 305 306
				assert.equal(value.length, 2);
			});
		});
	});

307
	test('Definition, registration order', function () {
J
Johannes Rieken 已提交
308

309
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
J
Johannes Rieken 已提交
310 311 312 313 314
			provideDefinition(): any {
				return [new types.Location(URI.parse('far://first'), new types.Range(2, 3, 4, 5))];
			}
		}));

315 316 317 318 319
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
			provideDefinition(): any {
				return new types.Location(URI.parse('far://second'), new types.Range(1, 2, 3, 4));
			}
		}));
J
Johannes Rieken 已提交
320

A
Alex Dima 已提交
321
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
322

323
			return getDefinitionsAtPosition(model, new EditorPosition(1, 1)).then(value => {
324 325
				assert.equal(value.length, 2);
				// let [first, second] = value;
J
Johannes Rieken 已提交
326

327 328
				assert.equal(value[0].uri.authority, 'second');
				assert.equal(value[1].uri.authority, 'first');
J
Johannes Rieken 已提交
329
			});
330
		});
J
Johannes Rieken 已提交
331 332
	});

J
Johannes Rieken 已提交
333
	test('Definition, evil provider', function () {
J
Johannes Rieken 已提交
334

335
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
J
Johannes Rieken 已提交
336
			provideDefinition(): any {
B
Benjamin Pasero 已提交
337
				throw new Error('evil provider');
J
Johannes Rieken 已提交
338 339
			}
		}));
340
		disposables.push(extHost.registerDefinitionProvider(defaultSelector, <vscode.DefinitionProvider>{
J
Johannes Rieken 已提交
341
			provideDefinition(): any {
342
				return new types.Location(model.uri, new types.Range(1, 1, 1, 1));
J
Johannes Rieken 已提交
343 344 345
			}
		}));

A
Alex Dima 已提交
346
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
347

348
			return getDefinitionsAtPosition(model, new EditorPosition(1, 1)).then(value => {
J
Johannes Rieken 已提交
349 350 351 352
				assert.equal(value.length, 1);
			});
		});
	});
J
Johannes Rieken 已提交
353

354
	// --- implementation
355

M
Matt Bierner 已提交
356
	test('Implementation, data conversion', function () {
357

M
Matt Bierner 已提交
358 359
		disposables.push(extHost.registerImplementationProvider(defaultSelector, <vscode.ImplementationProvider>{
			provideImplementation(): any {
360 361 362 363
				return [new types.Location(model.uri, new types.Range(1, 2, 3, 4))];
			}
		}));

A
Alex Dima 已提交
364
		return rpcProtocol.sync().then(() => {
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
			return getImplementationsAtPosition(model, new EditorPosition(1, 1)).then(value => {
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 2, startColumn: 3, endLineNumber: 4, endColumn: 5 });
				assert.equal(entry.uri.toString(), model.uri.toString());
			});
		});
	});

	// --- type definition

	test('Type Definition, data conversion', function () {

		disposables.push(extHost.registerTypeDefinitionProvider(defaultSelector, <vscode.TypeDefinitionProvider>{
			provideTypeDefinition(): any {
				return [new types.Location(model.uri, new types.Range(1, 2, 3, 4))];
			}
		}));

A
Alex Dima 已提交
384
		return rpcProtocol.sync().then(() => {
385
			return getTypeDefinitionsAtPosition(model, new EditorPosition(1, 1)).then(value => {
386 387 388 389 390 391 392 393
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 2, startColumn: 3, endLineNumber: 4, endColumn: 5 });
				assert.equal(entry.uri.toString(), model.uri.toString());
			});
		});
	});

J
Johannes Rieken 已提交
394 395
	// --- extra info

J
Johannes Rieken 已提交
396
	test('HoverProvider, word range at pos', function () {
J
Johannes Rieken 已提交
397

398
		disposables.push(extHost.registerHoverProvider(defaultSelector, <vscode.HoverProvider>{
J
Johannes Rieken 已提交
399
			provideHover(): any {
B
Benjamin Pasero 已提交
400
				return new types.Hover('Hello');
J
Johannes Rieken 已提交
401 402 403
			}
		}));

A
Alex Dima 已提交
404
		return rpcProtocol.sync().then(() => {
405
			getHover(model, new EditorPosition(1, 1)).then(value => {
J
Johannes Rieken 已提交
406 407 408 409 410 411 412
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 5 });
			});
		});
	});

413

J
Johannes Rieken 已提交
414
	test('HoverProvider, given range', function () {
J
Johannes Rieken 已提交
415

416
		disposables.push(extHost.registerHoverProvider(defaultSelector, <vscode.HoverProvider>{
J
Johannes Rieken 已提交
417 418 419 420 421
			provideHover(): any {
				return new types.Hover('Hello', new types.Range(3, 0, 8, 7));
			}
		}));

A
Alex Dima 已提交
422
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
423

424
			getHover(model, new EditorPosition(1, 1)).then(value => {
J
Johannes Rieken 已提交
425 426 427 428 429 430 431 432
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 4, startColumn: 1, endLineNumber: 9, endColumn: 8 });
			});
		});
	});


433
	test('HoverProvider, registration order', function () {
434
		disposables.push(extHost.registerHoverProvider(defaultSelector, <vscode.HoverProvider>{
J
Johannes Rieken 已提交
435 436 437 438 439 440
			provideHover(): any {
				return new types.Hover('registered first');
			}
		}));


441 442 443 444 445
		disposables.push(extHost.registerHoverProvider(defaultSelector, <vscode.HoverProvider>{
			provideHover(): any {
				return new types.Hover('registered second');
			}
		}));
J
Johannes Rieken 已提交
446

A
Alex Dima 已提交
447
		return rpcProtocol.sync().then(() => {
448
			return getHover(model, new EditorPosition(1, 1)).then(value => {
449
				assert.equal(value.length, 2);
450
				let [first, second] = value as Hover[];
451 452
				assert.equal(first.contents[0].value, 'registered second');
				assert.equal(second.contents[0].value, 'registered first');
J
Johannes Rieken 已提交
453
			});
454
		});
J
Johannes Rieken 已提交
455 456
	});

457

J
Johannes Rieken 已提交
458
	test('HoverProvider, evil provider', function () {
J
Johannes Rieken 已提交
459

460
		disposables.push(extHost.registerHoverProvider(defaultSelector, <vscode.HoverProvider>{
J
Johannes Rieken 已提交
461
			provideHover(): any {
B
Benjamin Pasero 已提交
462
				throw new Error('evil');
J
Johannes Rieken 已提交
463 464
			}
		}));
465
		disposables.push(extHost.registerHoverProvider(defaultSelector, <vscode.HoverProvider>{
J
Johannes Rieken 已提交
466
			provideHover(): any {
B
Benjamin Pasero 已提交
467
				return new types.Hover('Hello');
J
Johannes Rieken 已提交
468 469 470
			}
		}));

A
Alex Dima 已提交
471
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
472

473
			getHover(model, new EditorPosition(1, 1)).then(value => {
474 475 476 477 478 479 480 481

				assert.equal(value.length, 1);
			});
		});
	});

	// --- occurrences

J
Johannes Rieken 已提交
482
	test('Occurrences, data conversion', function () {
483 484 485

		disposables.push(extHost.registerDocumentHighlightProvider(defaultSelector, <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
B
Benjamin Pasero 已提交
486
				return [new types.DocumentHighlight(new types.Range(0, 0, 0, 4))];
487 488 489
			}
		}));

A
Alex Dima 已提交
490
		return rpcProtocol.sync().then(() => {
491

492
			return getOccurrencesAtPosition(model, new EditorPosition(1, 2)).then(value => {
493 494 495
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 5 });
496
				assert.equal(entry.kind, DocumentHighlightKind.Text);
497 498 499 500
			});
		});
	});

J
Johannes Rieken 已提交
501
	test('Occurrences, order 1/2', function () {
502 503 504

		disposables.push(extHost.registerDocumentHighlightProvider(defaultSelector, <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
B
Benjamin Pasero 已提交
505
				return [];
506 507 508 509
			}
		}));
		disposables.push(extHost.registerDocumentHighlightProvider('*', <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
B
Benjamin Pasero 已提交
510
				return [new types.DocumentHighlight(new types.Range(0, 0, 0, 4))];
511 512 513
			}
		}));

A
Alex Dima 已提交
514
		return rpcProtocol.sync().then(() => {
515

516
			return getOccurrencesAtPosition(model, new EditorPosition(1, 2)).then(value => {
517 518 519
				assert.equal(value.length, 1);
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 5 });
520
				assert.equal(entry.kind, DocumentHighlightKind.Text);
521 522 523 524
			});
		});
	});

J
Johannes Rieken 已提交
525
	test('Occurrences, order 2/2', function () {
526 527 528

		disposables.push(extHost.registerDocumentHighlightProvider(defaultSelector, <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
B
Benjamin Pasero 已提交
529
				return [new types.DocumentHighlight(new types.Range(0, 0, 0, 2))];
530 531 532 533
			}
		}));
		disposables.push(extHost.registerDocumentHighlightProvider('*', <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
B
Benjamin Pasero 已提交
534
				return [new types.DocumentHighlight(new types.Range(0, 0, 0, 4))];
535 536 537
			}
		}));

A
Alex Dima 已提交
538
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
539

540
			return getOccurrencesAtPosition(model, new EditorPosition(1, 2)).then(value => {
J
Johannes Rieken 已提交
541
				assert.equal(value.length, 1);
542 543
				let [entry] = value;
				assert.deepEqual(entry.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 3 });
544
				assert.equal(entry.kind, DocumentHighlightKind.Text);
J
Johannes Rieken 已提交
545 546
			});
		});
547 548
	});

J
Johannes Rieken 已提交
549
	test('Occurrences, evil provider', function () {
550 551 552 553 554 555 556 557 558

		disposables.push(extHost.registerDocumentHighlightProvider(defaultSelector, <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
				throw new Error('evil');
			}
		}));

		disposables.push(extHost.registerDocumentHighlightProvider(defaultSelector, <vscode.DocumentHighlightProvider>{
			provideDocumentHighlights(): any {
B
Benjamin Pasero 已提交
559
				return [new types.DocumentHighlight(new types.Range(0, 0, 0, 4))];
560 561 562
			}
		}));

A
Alex Dima 已提交
563
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
564

565
			return getOccurrencesAtPosition(model, new EditorPosition(1, 2)).then(value => {
566 567 568
				assert.equal(value.length, 1);
			});
		});
J
Johannes Rieken 已提交
569
	});
J
Johannes Rieken 已提交
570 571 572

	// --- references

573
	test('References, registration order', function () {
J
Johannes Rieken 已提交
574 575 576 577 578 579 580

		disposables.push(extHost.registerReferenceProvider(defaultSelector, <vscode.ReferenceProvider>{
			provideReferences(): any {
				return [new types.Location(URI.parse('far://register/first'), new types.Range(0, 0, 0, 0))];
			}
		}));

581 582 583 584 585
		disposables.push(extHost.registerReferenceProvider(defaultSelector, <vscode.ReferenceProvider>{
			provideReferences(): any {
				return [new types.Location(URI.parse('far://register/second'), new types.Range(0, 0, 0, 0))];
			}
		}));
J
Johannes Rieken 已提交
586

A
Alex Dima 已提交
587
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
588

589
			return provideReferences(model, new EditorPosition(1, 2)).then(value => {
590
				assert.equal(value.length, 2);
J
Johannes Rieken 已提交
591

592
				let [first, second] = value;
593 594
				assert.equal(first.uri.path, '/second');
				assert.equal(second.uri.path, '/first');
J
Johannes Rieken 已提交
595
			});
596
		});
J
Johannes Rieken 已提交
597 598
	});

J
Johannes Rieken 已提交
599
	test('References, data conversion', function () {
J
Johannes Rieken 已提交
600 601 602

		disposables.push(extHost.registerReferenceProvider(defaultSelector, <vscode.ReferenceProvider>{
			provideReferences(): any {
603
				return [new types.Location(model.uri, new types.Position(0, 0))];
J
Johannes Rieken 已提交
604 605 606
			}
		}));

A
Alex Dima 已提交
607
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
608

609
			return provideReferences(model, new EditorPosition(1, 2)).then(value => {
J
Johannes Rieken 已提交
610 611 612 613
				assert.equal(value.length, 1);

				let [item] = value;
				assert.deepEqual(item.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
614
				assert.equal(item.uri.toString(), model.uri.toString());
J
Johannes Rieken 已提交
615 616 617 618 619
			});

		});
	});

J
Johannes Rieken 已提交
620
	test('References, evil provider', function () {
J
Johannes Rieken 已提交
621 622 623 624 625 626 627 628

		disposables.push(extHost.registerReferenceProvider(defaultSelector, <vscode.ReferenceProvider>{
			provideReferences(): any {
				throw new Error('evil');
			}
		}));
		disposables.push(extHost.registerReferenceProvider(defaultSelector, <vscode.ReferenceProvider>{
			provideReferences(): any {
629
				return [new types.Location(model.uri, new types.Range(0, 0, 0, 0))];
J
Johannes Rieken 已提交
630 631 632
			}
		}));

A
Alex Dima 已提交
633
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
634

635
			return provideReferences(model, new EditorPosition(1, 2)).then(value => {
J
Johannes Rieken 已提交
636 637 638 639 640
				assert.equal(value.length, 1);
			});

		});
	});
J
Johannes Rieken 已提交
641 642 643

	// --- quick fix

M
Matt Bierner 已提交
644
	test('Quick Fix, command data conversion', function () {
J
Johannes Rieken 已提交
645

646 647
		disposables.push(extHost.registerCodeActionProvider(defaultSelector, {
			provideCodeActions(): vscode.Command[] {
J
Johannes Rieken 已提交
648
				return [
649 650
					{ command: 'test1', title: 'Testing1' },
					{ command: 'test2', title: 'Testing2' }
J
Johannes Rieken 已提交
651 652 653 654
				];
			}
		}));

A
Alex Dima 已提交
655
		return rpcProtocol.sync().then(() => {
656
			return getCodeActions(model, model.getFullModelRange()).then(value => {
J
Johannes Rieken 已提交
657 658
				assert.equal(value.length, 2);

659
				const [first, second] = value;
J
Johannes Rieken 已提交
660
				assert.equal(first.title, 'Testing1');
661
				assert.equal(first.command.id, 'test1');
J
Johannes Rieken 已提交
662
				assert.equal(second.title, 'Testing2');
663
				assert.equal(second.command.id, 'test2');
J
Johannes Rieken 已提交
664 665 666 667
			});
		});
	});

M
Matt Bierner 已提交
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
	test('Quick Fix, code action data conversion', function () {

		disposables.push(extHost.registerCodeActionProvider(defaultSelector, {
			provideCodeActions(): vscode.CodeAction[] {
				return [
					{
						title: 'Testing1',
						command: { title: 'Testing1Command', command: 'test1' },
						kind: types.CodeActionKind.Empty.append('test.scope')
					}
				];
			}
		}));

		return rpcProtocol.sync().then(() => {
			return getCodeActions(model, model.getFullModelRange()).then(value => {
				assert.equal(value.length, 1);

				const [first] = value;
				assert.equal(first.title, 'Testing1');
				assert.equal(first.command.title, 'Testing1Command');
				assert.equal(first.command.id, 'test1');
				assert.equal(first.kind, 'test.scope');
			});
		});
	});


J
Johannes Rieken 已提交
696 697 698 699 700 701 702 703 704 705 706 707
	test('Cannot read property \'id\' of undefined, #29469', function () {

		disposables.push(extHost.registerCodeActionProvider(defaultSelector, <vscode.CodeActionProvider>{
			provideCodeActions(): any {
				return [
					undefined,
					null,
					<vscode.Command>{ command: 'test', title: 'Testing' }
				];
			}
		}));

A
Alex Dima 已提交
708
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
709 710
			return getCodeActions(model, model.getFullModelRange()).then(value => {
				assert.equal(value.length, 1);
J
Johannes Rieken 已提交
711 712 713 714
			});
		});
	});

J
Johannes Rieken 已提交
715
	test('Quick Fix, evil provider', function () {
J
Johannes Rieken 已提交
716 717 718 719 720 721 722 723 724 725 726 727

		disposables.push(extHost.registerCodeActionProvider(defaultSelector, <vscode.CodeActionProvider>{
			provideCodeActions(): any {
				throw new Error('evil');
			}
		}));
		disposables.push(extHost.registerCodeActionProvider(defaultSelector, <vscode.CodeActionProvider>{
			provideCodeActions(): any {
				return [<vscode.Command>{ command: 'test', title: 'Testing' }];
			}
		}));

A
Alex Dima 已提交
728
		return rpcProtocol.sync().then(() => {
729
			return getCodeActions(model, model.getFullModelRange()).then(value => {
J
Johannes Rieken 已提交
730 731 732 733
				assert.equal(value.length, 1);
			});
		});
	});
734 735 736

	// --- navigate types

J
Johannes Rieken 已提交
737
	test('Navigate types, evil provider', function () {
738 739 740 741 742 743 744 745 746

		disposables.push(extHost.registerWorkspaceSymbolProvider(<vscode.WorkspaceSymbolProvider>{
			provideWorkspaceSymbols(): any {
				throw new Error('evil');
			}
		}));

		disposables.push(extHost.registerWorkspaceSymbolProvider(<vscode.WorkspaceSymbolProvider>{
			provideWorkspaceSymbols(): any {
B
Benjamin Pasero 已提交
747
				return [new types.SymbolInformation('testing', types.SymbolKind.Array, new types.Range(0, 0, 1, 1))];
748 749 750
			}
		}));

A
Alex Dima 已提交
751
		return rpcProtocol.sync().then(() => {
752

753
			return getWorkspaceSymbols('').then(value => {
754
				assert.equal(value.length, 1);
755 756 757 758
				const [first] = value;
				const [, symbols] = first;
				assert.equal(symbols.length, 1);
				assert.equal(symbols[0].name, 'testing');
759 760
			});
		});
J
Johannes Rieken 已提交
761 762 763 764
	});

	// --- rename

J
Johannes Rieken 已提交
765
	test('Rename, evil provider 0/2', function () {
J
Johannes Rieken 已提交
766 767 768

		disposables.push(extHost.registerRenameProvider(defaultSelector, <vscode.RenameProvider>{
			provideRenameEdits(): any {
J
Johannes Rieken 已提交
769
				throw new class Foo { };
J
Johannes Rieken 已提交
770 771 772
			}
		}));

A
Alex Dima 已提交
773
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
774

775
			return rename(model, new EditorPosition(1, 1), 'newName').then(value => {
J
Johannes Rieken 已提交
776
				throw Error();
J
Johannes Rieken 已提交
777
			}, err => {
778
				// expected
J
Johannes Rieken 已提交
779 780 781 782
			});
		});
	});

J
Johannes Rieken 已提交
783 784 785 786 787 788 789 790
	test('Rename, evil provider 1/2', function () {

		disposables.push(extHost.registerRenameProvider(defaultSelector, <vscode.RenameProvider>{
			provideRenameEdits(): any {
				throw Error('evil');
			}
		}));

A
Alex Dima 已提交
791
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
792 793 794 795 796 797 798

			return rename(model, new EditorPosition(1, 1), 'newName').then(value => {
				assert.equal(value.rejectReason, 'evil');
			});
		});
	});

J
Johannes Rieken 已提交
799
	test('Rename, evil provider 2/2', function () {
J
Johannes Rieken 已提交
800 801 802 803 804 805 806 807 808 809

		disposables.push(extHost.registerRenameProvider('*', <vscode.RenameProvider>{
			provideRenameEdits(): any {
				throw Error('evil');
			}
		}));

		disposables.push(extHost.registerRenameProvider(defaultSelector, <vscode.RenameProvider>{
			provideRenameEdits(): any {
				let edit = new types.WorkspaceEdit();
810
				edit.replace(model.uri, new types.Range(0, 0, 0, 0), 'testing');
J
Johannes Rieken 已提交
811 812 813 814
				return edit;
			}
		}));

A
Alex Dima 已提交
815
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
816

817
			return rename(model, new EditorPosition(1, 1), 'newName').then(value => {
J
Johannes Rieken 已提交
818 819 820 821 822
				assert.equal(value.edits.length, 1);
			});
		});
	});

J
Johannes Rieken 已提交
823
	test('Rename, ordering', function () {
J
Johannes Rieken 已提交
824 825 826 827

		disposables.push(extHost.registerRenameProvider('*', <vscode.RenameProvider>{
			provideRenameEdits(): any {
				let edit = new types.WorkspaceEdit();
828 829
				edit.replace(model.uri, new types.Range(0, 0, 0, 0), 'testing');
				edit.replace(model.uri, new types.Range(1, 0, 1, 0), 'testing');
J
Johannes Rieken 已提交
830 831 832 833 834 835 836 837 838 839
				return edit;
			}
		}));

		disposables.push(extHost.registerRenameProvider(defaultSelector, <vscode.RenameProvider>{
			provideRenameEdits(): any {
				return;
			}
		}));

A
Alex Dima 已提交
840
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
841

842
			return rename(model, new EditorPosition(1, 1), 'newName').then(value => {
843 844
				assert.equal(value.edits.length, 1); // least relevant renamer
				assert.equal((<ResourceTextEdit[]>value.edits)[0].edits.length, 2); // least relevant renamer
J
Johannes Rieken 已提交
845 846 847
			});
		});
	});
848 849 850

	// --- parameter hints

J
Johannes Rieken 已提交
851 852 853 854 855 856 857 858 859 860
	test('Parameter Hints, order', function () {

		disposables.push(extHost.registerSignatureHelpProvider(defaultSelector, <vscode.SignatureHelpProvider>{
			provideSignatureHelp(): any {
				return undefined;
			}
		}, []));

		disposables.push(extHost.registerSignatureHelpProvider(defaultSelector, <vscode.SignatureHelpProvider>{
			provideSignatureHelp(): vscode.SignatureHelp {
861 862 863 864 865
				return {
					signatures: [],
					activeParameter: 0,
					activeSignature: 0
				};
J
Johannes Rieken 已提交
866 867 868
			}
		}, []));

A
Alex Dima 已提交
869
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
870 871 872 873 874 875

			return provideSignatureHelp(model, new EditorPosition(1, 1)).then(value => {
				assert.ok(value);
			});
		});
	});
J
Johannes Rieken 已提交
876
	test('Parameter Hints, evil provider', function () {
877 878 879 880 881 882 883

		disposables.push(extHost.registerSignatureHelpProvider(defaultSelector, <vscode.SignatureHelpProvider>{
			provideSignatureHelp(): any {
				throw new Error('evil');
			}
		}, []));

A
Alex Dima 已提交
884
		return rpcProtocol.sync().then(() => {
885

886
			return provideSignatureHelp(model, new EditorPosition(1, 1)).then(value => {
J
Johannes Rieken 已提交
887
				assert.equal(value, undefined);
B
Benjamin Pasero 已提交
888
			});
889
		});
890 891 892 893
	});

	// --- suggestions

J
Johannes Rieken 已提交
894
	test('Suggest, order 1/3', function () {
895 896 897 898 899 900 901 902 903 904 905 906 907

		disposables.push(extHost.registerCompletionItemProvider('*', <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return [new types.CompletionItem('testing1')];
			}
		}, []));

		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return [new types.CompletionItem('testing2')];
			}
		}, []));

A
Alex Dima 已提交
908
		return rpcProtocol.sync().then(() => {
909
			return provideSuggestionItems(model, new EditorPosition(1, 1), 'none').then(value => {
910
				assert.equal(value.length, 1);
911
				assert.equal(value[0].suggestion.insertText, 'testing2');
912 913 914 915
			});
		});
	});

J
Johannes Rieken 已提交
916
	test('Suggest, order 2/3', function () {
917 918 919 920 921 922 923 924 925 926 927 928 929

		disposables.push(extHost.registerCompletionItemProvider('*', <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return [new types.CompletionItem('weak-selector')]; // weaker selector but result
			}
		}, []));

		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return []; // stronger selector but not a good result;
			}
		}, []));

A
Alex Dima 已提交
930
		return rpcProtocol.sync().then(() => {
931
			return provideSuggestionItems(model, new EditorPosition(1, 1), 'none').then(value => {
932
				assert.equal(value.length, 1);
933
				assert.equal(value[0].suggestion.insertText, 'weak-selector');
934 935
			});
		});
B
Benjamin Pasero 已提交
936
	});
937

938
	test('Suggest, order 2/3', function () {
939 940 941 942 943 944 945

		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return [new types.CompletionItem('strong-1')];
			}
		}, []));

946 947 948 949 950 951
		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return [new types.CompletionItem('strong-2')];
			}
		}, []));

A
Alex Dima 已提交
952
		return rpcProtocol.sync().then(() => {
953
			return provideSuggestionItems(model, new EditorPosition(1, 1), 'none').then(value => {
954
				assert.equal(value.length, 2);
955 956
				assert.equal(value[0].suggestion.insertText, 'strong-1'); // sort by label
				assert.equal(value[1].suggestion.insertText, 'strong-2');
957
			});
958
		});
B
Benjamin Pasero 已提交
959
	});
960

J
Johannes Rieken 已提交
961
	test('Suggest, evil provider', function () {
962 963 964 965 966 967 968 969 970 971 972 973 974 975

		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				throw new Error('evil');
			}
		}, []));

		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
				return [new types.CompletionItem('testing')];
			}
		}, []));


A
Alex Dima 已提交
976
		return rpcProtocol.sync().then(() => {
977

978
			return provideSuggestionItems(model, new EditorPosition(1, 1), 'none').then(value => {
979
				assert.equal(value[0].container.incomplete, undefined);
980 981 982
			});
		});
	});
983

J
Johannes Rieken 已提交
984
	test('Suggest, CompletionList', function () {
985 986 987

		disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
			provideCompletionItems(): any {
J
Johannes Rieken 已提交
988
				return new types.CompletionList([<any>new types.CompletionItem('hello')], true);
989 990 991
			}
		}, []));

A
Alex Dima 已提交
992
		return rpcProtocol.sync().then(() => {
993

994
			provideSuggestionItems(model, new EditorPosition(1, 1), 'none').then(value => {
995
				assert.equal(value[0].container.incomplete, true);
996 997 998 999
			});
		});
	});

1000 1001
	// --- format

J
Johannes Rieken 已提交
1002
	test('Format Doc, data conversion', function () {
1003 1004
		disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
			provideDocumentFormattingEdits(): any {
1005
				return [new types.TextEdit(new types.Range(0, 0, 0, 0), 'testing'), types.TextEdit.setEndOfLine(types.EndOfLine.LF)];
1006 1007 1008
			}
		}));

A
Alex Dima 已提交
1009
		return rpcProtocol.sync().then(() => {
1010
			return getDocumentFormattingEdits(model, { insertSpaces: true, tabSize: 4 }).then(value => {
1011 1012
				assert.equal(value.length, 2);
				let [first, second] = value;
1013
				assert.equal(first.text, 'testing');
J
Johannes Rieken 已提交
1014
				assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
1015

1016
				assert.equal(second.eol, EndOfLineSequence.LF);
1017 1018
				assert.equal(second.text, '');
				assert.equal(second.range, undefined);
1019 1020 1021 1022
			});
		});
	});

J
Johannes Rieken 已提交
1023
	test('Format Doc, evil provider', function () {
1024 1025 1026 1027 1028 1029
		disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
			provideDocumentFormattingEdits(): any {
				throw new Error('evil');
			}
		}));

A
Alex Dima 已提交
1030
		return rpcProtocol.sync().then(() => {
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
			return getDocumentFormattingEdits(model, { insertSpaces: true, tabSize: 4 });
		});
	});

	test('Format Doc, order', function () {
		disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
			provideDocumentFormattingEdits(): any {
				return [new types.TextEdit(new types.Range(0, 0, 0, 0), 'testing')];
			}
		}));

		disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
			provideDocumentFormattingEdits(): any {
				return undefined;
			}
		}));

A
Alex Dima 已提交
1048
		return rpcProtocol.sync().then(() => {
1049 1050 1051 1052 1053 1054
			return getDocumentFormattingEdits(model, { insertSpaces: true, tabSize: 4 }).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;
				assert.equal(first.text, 'testing');
				assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
			});
1055 1056 1057
		});
	});

J
Johannes Rieken 已提交
1058
	test('Format Range, data conversion', function () {
1059 1060
		disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, <vscode.DocumentRangeFormattingEditProvider>{
			provideDocumentRangeFormattingEdits(): any {
J
Johannes Rieken 已提交
1061
				return [new types.TextEdit(new types.Range(0, 0, 0, 0), 'testing')];
1062 1063 1064
			}
		}));

A
Alex Dima 已提交
1065
		return rpcProtocol.sync().then(() => {
1066
			return getDocumentRangeFormattingEdits(model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }).then(value => {
1067 1068 1069
				assert.equal(value.length, 1);
				let [first] = value;
				assert.equal(first.text, 'testing');
J
Johannes Rieken 已提交
1070
				assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
1071 1072
			});
		});
B
Benjamin Pasero 已提交
1073
	});
1074

J
Johannes Rieken 已提交
1075
	test('Format Range, + format_doc', function () {
1076 1077
		disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, <vscode.DocumentRangeFormattingEditProvider>{
			provideDocumentRangeFormattingEdits(): any {
J
Johannes Rieken 已提交
1078
				return [new types.TextEdit(new types.Range(0, 0, 0, 0), 'range')];
1079 1080 1081 1082 1083 1084 1085
			}
		}));
		disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
			provideDocumentFormattingEdits(): any {
				return [new types.TextEdit(new types.Range(0, 0, 1, 1), 'doc')];
			}
		}));
A
Alex Dima 已提交
1086
		return rpcProtocol.sync().then(() => {
1087
			return getDocumentRangeFormattingEdits(model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 }).then(value => {
1088 1089 1090 1091 1092 1093 1094
				assert.equal(value.length, 1);
				let [first] = value;
				assert.equal(first.text, 'range');
			});
		});
	});

J
Johannes Rieken 已提交
1095
	test('Format Range, evil provider', function () {
1096 1097 1098 1099 1100 1101
		disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, <vscode.DocumentRangeFormattingEditProvider>{
			provideDocumentRangeFormattingEdits(): any {
				throw new Error('evil');
			}
		}));

A
Alex Dima 已提交
1102
		return rpcProtocol.sync().then(() => {
1103
			return getDocumentRangeFormattingEdits(model, new EditorRange(1, 1, 1, 1), { insertSpaces: true, tabSize: 4 });
1104
		});
B
Benjamin Pasero 已提交
1105
	});
1106

J
Johannes Rieken 已提交
1107
	test('Format on Type, data conversion', function () {
1108 1109 1110 1111 1112 1113 1114

		disposables.push(extHost.registerOnTypeFormattingEditProvider(defaultSelector, <vscode.OnTypeFormattingEditProvider>{
			provideOnTypeFormattingEdits(): any {
				return [new types.TextEdit(new types.Range(0, 0, 0, 0), arguments[2])];
			}
		}, [';']));

A
Alex Dima 已提交
1115
		return rpcProtocol.sync().then(() => {
1116
			return getOnTypeFormattingEdits(model, new EditorPosition(1, 1), ';', { insertSpaces: true, tabSize: 2 }).then(value => {
1117 1118 1119 1120 1121 1122 1123 1124
				assert.equal(value.length, 1);
				let [first] = value;

				assert.equal(first.text, ';');
				assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
			});
		});
	});
J
Johannes Rieken 已提交
1125 1126 1127 1128 1129

	test('Links, data conversion', function () {

		disposables.push(extHost.registerDocumentLinkProvider(defaultSelector, <vscode.DocumentLinkProvider>{
			provideDocumentLinks() {
1130
				return [new types.DocumentLink(new types.Range(0, 0, 1, 1), URI.parse('foo:bar#3'))];
J
Johannes Rieken 已提交
1131 1132 1133
			}
		}));

A
Alex Dima 已提交
1134
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
			return getLinks(model).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;

				assert.equal(first.url, 'foo:bar#3');
				assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 2, endColumn: 2 });
			});
		});
	});

	test('Links, evil provider', function () {

		disposables.push(extHost.registerDocumentLinkProvider(defaultSelector, <vscode.DocumentLinkProvider>{
			provideDocumentLinks() {
1149
				return [new types.DocumentLink(new types.Range(0, 0, 1, 1), URI.parse('foo:bar#3'))];
J
Johannes Rieken 已提交
1150 1151 1152 1153 1154 1155 1156 1157 1158
			}
		}));

		disposables.push(extHost.registerDocumentLinkProvider(defaultSelector, <vscode.DocumentLinkProvider>{
			provideDocumentLinks(): any {
				throw new Error();
			}
		}));

A
Alex Dima 已提交
1159
		return rpcProtocol.sync().then(() => {
J
Johannes Rieken 已提交
1160 1161 1162 1163 1164 1165 1166 1167 1168
			return getLinks(model).then(value => {
				assert.equal(value.length, 1);
				let [first] = value;

				assert.equal(first.url, 'foo:bar#3');
				assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 2, endColumn: 2 });
			});
		});
	});
J
tslint  
Johannes Rieken 已提交
1169
});