extHostLanguageFeatures.ts 37.0 KB
Newer Older
J
Johannes Rieken 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import URI from 'vs/base/common/uri';
J
Johannes Rieken 已提交
8
import { TPromise } from 'vs/base/common/winjs.base';
9
import { mixin } from 'vs/base/common/objects';
J
Johannes Rieken 已提交
10
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
J
Johannes Rieken 已提交
11
import * as vscode from 'vscode';
J
Johannes Rieken 已提交
12
import * as TypeConverters from 'vs/workbench/api/node/extHostTypeConverters';
13
import { Range, Disposable, CompletionList, CompletionItem, SnippetString } from 'vs/workbench/api/node/extHostTypes';
A
Alex Dima 已提交
14
import { ISingleEditOperation } from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
15
import * as modes from 'vs/editor/common/modes';
J
Johannes Rieken 已提交
16 17
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
18
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands';
J
Johannes Rieken 已提交
19
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
20
import { IWorkspaceSymbolProvider } from 'vs/workbench/parts/search/common/search';
21
import { asWinJsPromise } from 'vs/base/common/async';
J
Joao Moreno 已提交
22
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IColorFormatMap } from './extHost.protocol';
J
Johannes Rieken 已提交
23
import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
24 25
import { IPosition } from 'vs/editor/common/core/position';
import { IRange } from 'vs/editor/common/core/range';
J
Johannes Rieken 已提交
26 27 28

// --- adapter

29
class OutlineAdapter {
J
Johannes Rieken 已提交
30

31
	private _documents: ExtHostDocuments;
J
Johannes Rieken 已提交
32 33
	private _provider: vscode.DocumentSymbolProvider;

34
	constructor(documents: ExtHostDocuments, provider: vscode.DocumentSymbolProvider) {
J
Johannes Rieken 已提交
35 36 37 38
		this._documents = documents;
		this._provider = provider;
	}

39
	provideDocumentSymbols(resource: URI): TPromise<modes.SymbolInformation[]> {
40
		let doc = this._documents.getDocumentData(resource).document;
J
Johannes Rieken 已提交
41 42
		return asWinJsPromise(token => this._provider.provideDocumentSymbols(doc, token)).then(value => {
			if (Array.isArray(value)) {
43
				return value.map(TypeConverters.fromSymbolInformation);
J
Johannes Rieken 已提交
44
			}
M
Matt Bierner 已提交
45
			return undefined;
J
Johannes Rieken 已提交
46 47 48 49
		});
	}
}

50
class CodeLensAdapter {
51

52 53
	private static _badCmd: vscode.Command = { command: 'missing', title: '<<MISSING COMMAND>>' };

54
	private _documents: ExtHostDocuments;
55 56
	private _commands: CommandsConverter;
	private _heapService: ExtHostHeapService;
57 58
	private _provider: vscode.CodeLensProvider;

59
	constructor(documents: ExtHostDocuments, commands: CommandsConverter, heapService: ExtHostHeapService, provider: vscode.CodeLensProvider) {
60
		this._documents = documents;
61
		this._commands = commands;
62
		this._heapService = heapService;
63 64 65
		this._provider = provider;
	}

66
	provideCodeLenses(resource: URI): TPromise<modes.ICodeLensSymbol[]> {
67
		const doc = this._documents.getDocumentData(resource).document;
68

69 70 71 72 73 74 75 76
		return asWinJsPromise(token => this._provider.provideCodeLenses(doc, token)).then(lenses => {
			if (Array.isArray(lenses)) {
				return lenses.map(lens => {
					const id = this._heapService.keep(lens);
					return ObjectIdentifier.mixin({
						range: TypeConverters.fromRange(lens.range),
						command: this._commands.toInternal(lens.command)
					}, id);
77 78
				});
			}
M
Matt Bierner 已提交
79
			return undefined;
80
		});
81 82
	}

83
	resolveCodeLens(resource: URI, symbol: modes.ICodeLensSymbol): TPromise<modes.ICodeLensSymbol> {
84

85 86
		const lens = this._heapService.get<vscode.CodeLens>(ObjectIdentifier.of(symbol));
		if (!lens) {
M
Matt Bierner 已提交
87
			return undefined;
88 89
		}

90 91 92 93 94 95
		let resolve: TPromise<vscode.CodeLens>;
		if (typeof this._provider.resolveCodeLens !== 'function' || lens.isResolved) {
			resolve = TPromise.as(lens);
		} else {
			resolve = asWinJsPromise(token => this._provider.resolveCodeLens(lens, token));
		}
96

97 98 99 100
		return resolve.then(newLens => {
			newLens = newLens || lens;
			symbol.command = this._commands.toInternal(newLens.command || CodeLensAdapter._badCmd);
			return symbol;
101 102 103 104
		});
	}
}

105
class DefinitionAdapter {
106
	private _documents: ExtHostDocuments;
J
Johannes Rieken 已提交
107 108
	private _provider: vscode.DefinitionProvider;

109
	constructor(documents: ExtHostDocuments, provider: vscode.DefinitionProvider) {
J
Johannes Rieken 已提交
110 111 112 113
		this._documents = documents;
		this._provider = provider;
	}

114
	provideDefinition(resource: URI, position: IPosition): TPromise<modes.Definition> {
115
		let doc = this._documents.getDocumentData(resource).document;
J
Johannes Rieken 已提交
116 117 118
		let pos = TypeConverters.toPosition(position);
		return asWinJsPromise(token => this._provider.provideDefinition(doc, pos, token)).then(value => {
			if (Array.isArray(value)) {
J
Johannes Rieken 已提交
119
				return value.map(TypeConverters.location.from);
J
Johannes Rieken 已提交
120
			} else if (value) {
J
Johannes Rieken 已提交
121
				return TypeConverters.location.from(value);
J
Johannes Rieken 已提交
122
			}
M
Matt Bierner 已提交
123
			return undefined;
J
Johannes Rieken 已提交
124 125 126 127
		});
	}
}

128 129
class ImplementationAdapter {
	private _documents: ExtHostDocuments;
M
Matt Bierner 已提交
130
	private _provider: vscode.ImplementationProvider;
131

M
Matt Bierner 已提交
132
	constructor(documents: ExtHostDocuments, provider: vscode.ImplementationProvider) {
133 134 135 136
		this._documents = documents;
		this._provider = provider;
	}

M
Matt Bierner 已提交
137
	provideImplementation(resource: URI, position: IPosition): TPromise<modes.Definition> {
138 139
		let doc = this._documents.getDocumentData(resource).document;
		let pos = TypeConverters.toPosition(position);
M
Matt Bierner 已提交
140
		return asWinJsPromise(token => this._provider.provideImplementation(doc, pos, token)).then(value => {
141 142 143 144 145
			if (Array.isArray(value)) {
				return value.map(TypeConverters.location.from);
			} else if (value) {
				return TypeConverters.location.from(value);
			}
M
Matt Bierner 已提交
146
			return undefined;
147 148 149 150
		});
	}
}

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
class TypeDefinitionAdapter {
	private _documents: ExtHostDocuments;
	private _provider: vscode.TypeDefinitionProvider;

	constructor(documents: ExtHostDocuments, provider: vscode.TypeDefinitionProvider) {
		this._documents = documents;
		this._provider = provider;
	}

	provideTypeDefinition(resource: URI, position: IPosition): TPromise<modes.Definition> {
		const doc = this._documents.getDocumentData(resource).document;
		const pos = TypeConverters.toPosition(position);
		return asWinJsPromise(token => this._provider.provideTypeDefinition(doc, pos, token)).then(value => {
			if (Array.isArray(value)) {
				return value.map(TypeConverters.location.from);
			} else if (value) {
				return TypeConverters.location.from(value);
			}
			return undefined;
		});
	}
}


175
class HoverAdapter {
J
Johannes Rieken 已提交
176

177
	private _documents: ExtHostDocuments;
J
Johannes Rieken 已提交
178 179
	private _provider: vscode.HoverProvider;

180
	constructor(documents: ExtHostDocuments, provider: vscode.HoverProvider) {
J
Johannes Rieken 已提交
181 182 183 184
		this._documents = documents;
		this._provider = provider;
	}

185
	public provideHover(resource: URI, position: IPosition): TPromise<modes.Hover> {
J
Johannes Rieken 已提交
186

187
		let doc = this._documents.getDocumentData(resource).document;
J
Johannes Rieken 已提交
188 189 190 191
		let pos = TypeConverters.toPosition(position);

		return asWinJsPromise(token => this._provider.provideHover(doc, pos, token)).then(value => {
			if (!value) {
M
Matt Bierner 已提交
192
				return undefined;
J
Johannes Rieken 已提交
193
			}
194 195
			if (!value.range) {
				value.range = doc.getWordRangeAtPosition(pos);
J
Johannes Rieken 已提交
196
			}
197 198
			if (!value.range) {
				value.range = new Range(pos, pos);
J
Johannes Rieken 已提交
199 200
			}

201
			return TypeConverters.fromHover(value);
J
Johannes Rieken 已提交
202 203 204 205
		});
	}
}

206
class DocumentHighlightAdapter {
207

208
	private _documents: ExtHostDocuments;
209 210
	private _provider: vscode.DocumentHighlightProvider;

211
	constructor(documents: ExtHostDocuments, provider: vscode.DocumentHighlightProvider) {
212 213 214 215
		this._documents = documents;
		this._provider = provider;
	}

216
	provideDocumentHighlights(resource: URI, position: IPosition): TPromise<modes.DocumentHighlight[]> {
217

218
		let doc = this._documents.getDocumentData(resource).document;
219 220 221 222
		let pos = TypeConverters.toPosition(position);

		return asWinJsPromise(token => this._provider.provideDocumentHighlights(doc, pos, token)).then(value => {
			if (Array.isArray(value)) {
223
				return value.map(DocumentHighlightAdapter._convertDocumentHighlight);
224
			}
M
Matt Bierner 已提交
225
			return undefined;
226 227 228
		});
	}

229
	private static _convertDocumentHighlight(documentHighlight: vscode.DocumentHighlight): modes.DocumentHighlight {
230 231
		return {
			range: TypeConverters.fromRange(documentHighlight.range),
232
			kind: documentHighlight.kind
B
Benjamin Pasero 已提交
233
		};
234 235 236
	}
}

237
class ReferenceAdapter {
J
Johannes Rieken 已提交
238

239
	private _documents: ExtHostDocuments;
J
Johannes Rieken 已提交
240 241
	private _provider: vscode.ReferenceProvider;

242
	constructor(documents: ExtHostDocuments, provider: vscode.ReferenceProvider) {
J
Johannes Rieken 已提交
243 244 245 246
		this._documents = documents;
		this._provider = provider;
	}

247
	provideReferences(resource: URI, position: IPosition, context: modes.ReferenceContext): TPromise<modes.Location[]> {
248
		let doc = this._documents.getDocumentData(resource).document;
J
Johannes Rieken 已提交
249 250
		let pos = TypeConverters.toPosition(position);

251
		return asWinJsPromise(token => this._provider.provideReferences(doc, pos, context, token)).then(value => {
J
Johannes Rieken 已提交
252
			if (Array.isArray(value)) {
J
Johannes Rieken 已提交
253
				return value.map(TypeConverters.location.from);
J
Johannes Rieken 已提交
254
			}
M
Matt Bierner 已提交
255
			return undefined;
J
Johannes Rieken 已提交
256 257 258 259
		});
	}
}

260
class QuickFixAdapter {
J
Johannes Rieken 已提交
261

262
	private _documents: ExtHostDocuments;
263
	private _commands: CommandsConverter;
264
	private _diagnostics: ExtHostDiagnostics;
J
Johannes Rieken 已提交
265 266
	private _provider: vscode.CodeActionProvider;

267
	constructor(documents: ExtHostDocuments, commands: CommandsConverter, diagnostics: ExtHostDiagnostics, heapService: ExtHostHeapService, provider: vscode.CodeActionProvider) {
J
Johannes Rieken 已提交
268 269
		this._documents = documents;
		this._commands = commands;
270
		this._diagnostics = diagnostics;
J
Johannes Rieken 已提交
271 272 273
		this._provider = provider;
	}

J
Johannes Rieken 已提交
274
	provideCodeActions(resource: URI, range: IRange): TPromise<modes.Command[]> {
J
Johannes Rieken 已提交
275

276
		const doc = this._documents.getDocumentData(resource).document;
J
Johannes Rieken 已提交
277
		const ran = TypeConverters.toRange(range);
278 279 280 281 282 283 284 285 286 287
		const allDiagnostics: vscode.Diagnostic[] = [];

		this._diagnostics.forEach(collection => {
			if (collection.has(resource)) {
				for (let diagnostic of collection.get(resource)) {
					if (diagnostic.range.intersection(ran)) {
						allDiagnostics.push(diagnostic);
					}
				}
			}
J
Johannes Rieken 已提交
288 289
		});

290
		return asWinJsPromise(token => this._provider.provideCodeActions(doc, ran, { diagnostics: allDiagnostics }, token)).then(commands => {
J
Johannes Rieken 已提交
291
			if (!Array.isArray(commands)) {
M
Matt Bierner 已提交
292
				return undefined;
J
Johannes Rieken 已提交
293
			}
J
Johannes Rieken 已提交
294
			return commands.map(command => this._commands.toInternal(command));
J
Johannes Rieken 已提交
295 296 297 298
		});
	}
}

299
class DocumentFormattingAdapter {
300

301
	private _documents: ExtHostDocuments;
302 303
	private _provider: vscode.DocumentFormattingEditProvider;

304
	constructor(documents: ExtHostDocuments, provider: vscode.DocumentFormattingEditProvider) {
305 306 307 308
		this._documents = documents;
		this._provider = provider;
	}

A
Alex Dima 已提交
309
	provideDocumentFormattingEdits(resource: URI, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
310

311
		const { document } = this._documents.getDocumentData(resource);
312 313

		return asWinJsPromise(token => this._provider.provideDocumentFormattingEdits(document, <any>options, token)).then(value => {
314
			if (Array.isArray(value)) {
315
				return value.map(TypeConverters.TextEdit.from);
316
			}
M
Matt Bierner 已提交
317
			return undefined;
318 319 320 321
		});
	}
}

322
class RangeFormattingAdapter {
323

324
	private _documents: ExtHostDocuments;
325 326
	private _provider: vscode.DocumentRangeFormattingEditProvider;

327
	constructor(documents: ExtHostDocuments, provider: vscode.DocumentRangeFormattingEditProvider) {
328 329 330 331
		this._documents = documents;
		this._provider = provider;
	}

A
Alex Dima 已提交
332
	provideDocumentRangeFormattingEdits(resource: URI, range: IRange, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
333

334
		const { document } = this._documents.getDocumentData(resource);
335
		const ran = TypeConverters.toRange(range);
336

337
		return asWinJsPromise(token => this._provider.provideDocumentRangeFormattingEdits(document, ran, <any>options, token)).then(value => {
338
			if (Array.isArray(value)) {
339
				return value.map(TypeConverters.TextEdit.from);
340
			}
M
Matt Bierner 已提交
341
			return undefined;
342 343 344 345
		});
	}
}

346
class OnTypeFormattingAdapter {
347

348
	private _documents: ExtHostDocuments;
349 350
	private _provider: vscode.OnTypeFormattingEditProvider;

351
	constructor(documents: ExtHostDocuments, provider: vscode.OnTypeFormattingEditProvider) {
352 353 354 355
		this._documents = documents;
		this._provider = provider;
	}

356
	autoFormatTriggerCharacters: string[] = []; // not here
357

A
Alex Dima 已提交
358
	provideOnTypeFormattingEdits(resource: URI, position: IPosition, ch: string, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
359

360
		const { document } = this._documents.getDocumentData(resource);
361
		const pos = TypeConverters.toPosition(position);
362

J
Johannes Rieken 已提交
363
		return asWinJsPromise(token => this._provider.provideOnTypeFormattingEdits(document, pos, ch, <any>options, token)).then(value => {
364
			if (Array.isArray(value)) {
365
				return value.map(TypeConverters.TextEdit.from);
366
			}
M
Matt Bierner 已提交
367
			return undefined;
368 369 370 371
		});
	}
}

372

373
class NavigateTypeAdapter implements IWorkspaceSymbolProvider {
374 375

	private _provider: vscode.WorkspaceSymbolProvider;
376
	private _heapService: ExtHostHeapService;
377

378
	constructor(provider: vscode.WorkspaceSymbolProvider, heapService: ExtHostHeapService) {
379
		this._provider = provider;
380
		this._heapService = heapService;
381 382
	}

383
	provideWorkspaceSymbols(search: string): TPromise<modes.SymbolInformation[]> {
384

385 386
		return asWinJsPromise(token => this._provider.provideWorkspaceSymbols(search, token)).then(value => {
			if (Array.isArray(value)) {
387 388 389 390
				return value.map(item => {
					const id = this._heapService.keep(item);
					const result = TypeConverters.fromSymbolInformation(item);
					return ObjectIdentifier.mixin(result, id);
391
				});
392
			}
M
Matt Bierner 已提交
393
			return undefined;
394 395
		});
	}
396

397
	resolveWorkspaceSymbol(item: modes.SymbolInformation): TPromise<modes.SymbolInformation> {
398 399

		if (typeof this._provider.resolveWorkspaceSymbol !== 'function') {
400
			return TPromise.as(item);
401 402
		}

403
		const symbolInfo = this._heapService.get<vscode.SymbolInformation>(ObjectIdentifier.of(item));
404 405 406 407
		if (symbolInfo) {
			return asWinJsPromise(token => this._provider.resolveWorkspaceSymbol(symbolInfo, token)).then(value => {
				return value && TypeConverters.fromSymbolInformation(value);
			});
408
		}
M
Matt Bierner 已提交
409
		return undefined;
410
	}
411 412
}

413
class RenameAdapter {
J
Johannes Rieken 已提交
414

415
	private _documents: ExtHostDocuments;
J
Johannes Rieken 已提交
416 417
	private _provider: vscode.RenameProvider;

418
	constructor(documents: ExtHostDocuments, provider: vscode.RenameProvider) {
J
Johannes Rieken 已提交
419 420 421 422
		this._documents = documents;
		this._provider = provider;
	}

423
	provideRenameEdits(resource: URI, position: IPosition, newName: string): TPromise<modes.WorkspaceEdit> {
J
Johannes Rieken 已提交
424

425
		let doc = this._documents.getDocumentData(resource).document;
J
Johannes Rieken 已提交
426 427 428 429
		let pos = TypeConverters.toPosition(position);

		return asWinJsPromise(token => this._provider.provideRenameEdits(doc, pos, newName, token)).then(value => {
			if (!value) {
M
Matt Bierner 已提交
430
				return undefined;
J
Johannes Rieken 已提交
431 432
			}

433
			let result = <modes.WorkspaceEdit>{
J
Johannes Rieken 已提交
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
				edits: []
			};

			for (let entry of value.entries()) {
				let [uri, textEdits] = entry;
				for (let textEdit of textEdits) {
					result.edits.push({
						resource: <URI>uri,
						newText: textEdit.newText,
						range: TypeConverters.fromRange(textEdit.range)
					});
				}
			}
			return result;
		}, err => {
			if (typeof err === 'string') {
450
				return <modes.WorkspaceEdit>{
J
Johannes Rieken 已提交
451 452 453 454
					edits: undefined,
					rejectReason: err
				};
			}
455
			return TPromise.wrapError<modes.WorkspaceEdit>(err);
J
Johannes Rieken 已提交
456 457 458 459
		});
	}
}

460

461
class SuggestAdapter {
462

463
	private _documents: ExtHostDocuments;
464
	private _commands: CommandsConverter;
J
Johannes Rieken 已提交
465
	private _heapService: ExtHostHeapService;
466 467
	private _provider: vscode.CompletionItemProvider;

468
	constructor(documents: ExtHostDocuments, commands: CommandsConverter, heapService: ExtHostHeapService, provider: vscode.CompletionItemProvider) {
469
		this._documents = documents;
470
		this._commands = commands;
471
		this._heapService = heapService;
472 473 474
		this._provider = provider;
	}

475
	provideCompletionItems(resource: URI, position: IPosition): TPromise<modes.ISuggestResult> {
476

477
		const doc = this._documents.getDocumentData(resource).document;
478 479
		const pos = TypeConverters.toPosition(position);

J
Johannes Rieken 已提交
480
		return asWinJsPromise<vscode.CompletionItem[] | vscode.CompletionList>(token => this._provider.provideCompletionItems(doc, pos, token)).then(value => {
481

482
			const result: modes.ISuggestResult = {
483 484
				suggestions: [],
			};
485

486
			let list: CompletionList;
487
			if (!value) {
488
				// undefined and null are valid results
M
Matt Bierner 已提交
489
				return undefined;
490 491 492 493

			} else if (Array.isArray(value)) {
				list = new CompletionList(value);

494
			} else {
495 496
				list = value;
				result.incomplete = list.isIncomplete;
497
			}
498

499 500 501
			// the default text edit range
			const wordRangeBeforePos = (doc.getWordRangeAtPosition(pos) || new Range(pos, pos))
				.with({ end: pos });
502

503
			for (const item of list.items) {
504

505
				const suggestion = this._convertCompletionItem(item, pos, wordRangeBeforePos);
506

507 508 509 510
				// bad completion item
				if (!suggestion) {
					// converter did warn
					continue;
511 512
				}

513
				ObjectIdentifier.mixin(suggestion, this._heapService.keep(item));
514
				result.suggestions.push(suggestion);
515 516
			}

517
			return result;
518 519 520
		});
	}

521
	resolveCompletionItem(resource: URI, position: IPosition, suggestion: modes.ISuggestion): TPromise<modes.ISuggestion> {
522 523

		if (typeof this._provider.resolveCompletionItem !== 'function') {
524 525
			return TPromise.as(suggestion);
		}
526

527
		const id = ObjectIdentifier.of(suggestion);
J
Johannes Rieken 已提交
528
		const item = this._heapService.get<CompletionItem>(id);
529 530 531
		if (!item) {
			return TPromise.as(suggestion);
		}
532

533
		return asWinJsPromise(token => this._provider.resolveCompletionItem(item, token)).then(resolvedItem => {
534 535 536 537 538 539 540 541 542 543 544 545 546

			if (!resolvedItem) {
				return suggestion;
			}

			const doc = this._documents.getDocumentData(resource).document;
			const pos = TypeConverters.toPosition(position);
			const wordRangeBeforePos = (doc.getWordRangeAtPosition(pos) || new Range(pos, pos)).with({ end: pos });
			const newSuggestion = this._convertCompletionItem(resolvedItem, pos, wordRangeBeforePos);
			if (newSuggestion) {
				mixin(suggestion, newSuggestion, true);
			}

547
			return suggestion;
548 549
		});
	}
550 551

	private _convertCompletionItem(item: vscode.CompletionItem, position: vscode.Position, defaultRange: vscode.Range): modes.ISuggestion {
J
Johannes Rieken 已提交
552
		if (typeof item.label !== 'string' || item.label.length === 0) {
553
			console.warn('INVALID text edit -> must have at least a label');
M
Matt Bierner 已提交
554
			return undefined;
555 556 557 558 559 560 561 562 563 564 565 566 567
		}

		const result: modes.ISuggestion = {
			//
			label: item.label,
			type: TypeConverters.CompletionItemKind.from(item.kind),
			detail: item.detail,
			documentation: item.documentation,
			filterText: item.filterText,
			sortText: item.sortText,
			//
			insertText: undefined,
			additionalTextEdits: item.additionalTextEdits && item.additionalTextEdits.map(TypeConverters.TextEdit.from),
568 569
			command: this._commands.toInternal(item.command),
			commitCharacters: item.commitCharacters
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
		};

		// 'insertText'-logic
		if (item.textEdit) {
			result.insertText = item.textEdit.newText;
			result.snippetType = 'internal';

		} else if (typeof item.insertText === 'string') {
			result.insertText = item.insertText;
			result.snippetType = 'internal';

		} else if (item.insertText instanceof SnippetString) {
			result.insertText = item.insertText.value;
			result.snippetType = 'textmate';

		} else {
			result.insertText = item.label;
			result.snippetType = 'internal';
		}

		// 'overwrite[Before|After]'-logic
		let range: vscode.Range;
		if (item.textEdit) {
			range = item.textEdit.range;
		} else if (item.range) {
			range = item.range;
		} else {
			range = defaultRange;
		}
		result.overwriteBefore = position.character - range.start.character;
		result.overwriteAfter = range.end.character - position.character;

		if (!range.isSingleLine || range.start.line !== position.line) {
			console.warn('INVALID text edit -> must be single line and on the same line');
M
Matt Bierner 已提交
604
			return undefined;
605 606 607 608
		}

		return result;
	}
609 610
}

A
Alex Dima 已提交
611
class SignatureHelpAdapter {
612

613
	private _documents: ExtHostDocuments;
614 615
	private _provider: vscode.SignatureHelpProvider;

616
	constructor(documents: ExtHostDocuments, provider: vscode.SignatureHelpProvider) {
617 618 619 620
		this._documents = documents;
		this._provider = provider;
	}

621
	provideSignatureHelp(resource: URI, position: IPosition): TPromise<modes.SignatureHelp> {
622

623
		const doc = this._documents.getDocumentData(resource).document;
624 625 626
		const pos = TypeConverters.toPosition(position);

		return asWinJsPromise(token => this._provider.provideSignatureHelp(doc, pos, token)).then(value => {
627
			if (value) {
628
				return TypeConverters.SignatureHelp.from(value);
629
			}
M
Matt Bierner 已提交
630
			return undefined;
631 632 633 634
		});
	}
}

J
Johannes Rieken 已提交
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
class LinkProviderAdapter {

	private _documents: ExtHostDocuments;
	private _provider: vscode.DocumentLinkProvider;

	constructor(documents: ExtHostDocuments, provider: vscode.DocumentLinkProvider) {
		this._documents = documents;
		this._provider = provider;
	}

	provideLinks(resource: URI): TPromise<modes.ILink[]> {
		const doc = this._documents.getDocumentData(resource).document;

		return asWinJsPromise(token => this._provider.provideDocumentLinks(doc, token)).then(links => {
			if (Array.isArray(links)) {
				return links.map(TypeConverters.DocumentLink.from);
			}
M
Matt Bierner 已提交
652
			return undefined;
J
Johannes Rieken 已提交
653 654
		});
	}
655 656 657 658 659 660 661

	resolveLink(link: modes.ILink): TPromise<modes.ILink> {
		if (typeof this._provider.resolveDocumentLink === 'function') {
			return asWinJsPromise(token => this._provider.resolveDocumentLink(TypeConverters.DocumentLink.to(link), token)).then(value => {
				if (value) {
					return TypeConverters.DocumentLink.from(value);
				}
M
Matt Bierner 已提交
662
				return undefined;
663 664
			});
		}
M
Matt Bierner 已提交
665
		return undefined;
666
	}
J
Johannes Rieken 已提交
667 668
}

669 670
class ColorProviderAdapter {

671
	private _proxy: MainThreadLanguageFeaturesShape;
672 673
	private _documents: ExtHostDocuments;
	private _provider: vscode.DocumentColorProvider;
674
	private _formatStorageMap: Map<vscode.ColorFormat, number>;
675
	private _formatStorageIndex;
676

677 678
	constructor(proxy: MainThreadLanguageFeaturesShape, documents: ExtHostDocuments, provider: vscode.DocumentColorProvider) {
		this._proxy = proxy;
679 680
		this._documents = documents;
		this._provider = provider;
681
		this._formatStorageMap = new Map<vscode.ColorFormat, number>();
682
		this._formatStorageIndex = 0;
683 684
	}

685
	provideColors(resource: URI): TPromise<IRawColorInfo[]> {
686
		const doc = this._documents.getDocumentData(resource).document;
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
		const colorFormats: IColorFormatMap = [];
		const getCachedId = (format: vscode.ColorFormat) => {
			let cachedId = this._formatStorageMap.get(format);
			if (cachedId === undefined) {
				cachedId = this._formatStorageIndex;
				this._formatStorageMap.set(format, cachedId);
				this._formatStorageIndex += 1;

				if (typeof format === 'string') { // Append to format list for registration
					colorFormats.push([cachedId, format]);
				} else {
					colorFormats.push([cachedId, [format.opaque, format.transparent]]);
				}
			}

			return cachedId;
		};
704 705 706

		return asWinJsPromise(token => this._provider.provideDocumentColors(doc, token)).then(colors => {
			if (Array.isArray(colors)) {
707 708
				const colorInfos: IRawColorInfo[] = [];
				colors.forEach(ci => {
709
					const availableFormats = ci.availableFormats.map(f => getCachedId(f));
710 711 712

					colorInfos.push({
						color: [ci.color.red, ci.color.green, ci.color.blue, ci.color.alpha],
713
						availableFormats: availableFormats,
714 715 716 717 718 719
						range: TypeConverters.fromRange(ci.range)
					});
				});

				this._proxy.$registerColorFormats(colorFormats);
				return colorInfos;
720 721 722 723 724 725
			}
			return undefined;
		});
	}
}

726
type Adapter = OutlineAdapter | CodeLensAdapter | DefinitionAdapter | HoverAdapter
727
	| DocumentHighlightAdapter | ReferenceAdapter | QuickFixAdapter | DocumentFormattingAdapter
728
	| RangeFormattingAdapter | OnTypeFormattingAdapter | NavigateTypeAdapter | RenameAdapter
729
	| SuggestAdapter | SignatureHelpAdapter | LinkProviderAdapter | ImplementationAdapter | TypeDefinitionAdapter | ColorProviderAdapter;
J
Johannes Rieken 已提交
730

A
Alex Dima 已提交
731
export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
J
Johannes Rieken 已提交
732

733
	private static _handlePool: number = 0;
J
Johannes Rieken 已提交
734

735
	private _proxy: MainThreadLanguageFeaturesShape;
736
	private _documents: ExtHostDocuments;
737
	private _commands: ExtHostCommands;
738
	private _heapService: ExtHostHeapService;
739
	private _diagnostics: ExtHostDiagnostics;
J
Johannes Rieken 已提交
740
	private _adapter = new Map<number, Adapter>();
J
Johannes Rieken 已提交
741

742 743
	constructor(
		threadService: IThreadService,
744
		documents: ExtHostDocuments,
745
		commands: ExtHostCommands,
J
Johannes Rieken 已提交
746
		heapMonitor: ExtHostHeapService,
747 748
		diagnostics: ExtHostDiagnostics
	) {
A
Alex Dima 已提交
749
		super();
750 751 752
		this._proxy = threadService.get(MainContext.MainThreadLanguageFeatures);
		this._documents = documents;
		this._commands = commands;
753
		this._heapService = heapMonitor;
754
		this._diagnostics = diagnostics;
J
Johannes Rieken 已提交
755 756 757 758
	}

	private _createDisposable(handle: number): Disposable {
		return new Disposable(() => {
J
Johannes Rieken 已提交
759
			this._adapter.delete(handle);
J
Johannes Rieken 已提交
760 761 762 763
			this._proxy.$unregister(handle);
		});
	}

764 765 766 767
	private _nextHandle(): number {
		return ExtHostLanguageFeatures._handlePool++;
	}

768
	private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A }, callback: (adapter: A) => TPromise<R>): TPromise<R> {
J
Johannes Rieken 已提交
769
		let adapter = this._adapter.get(handle);
J
Johannes Rieken 已提交
770
		if (!(adapter instanceof ctor)) {
771
			return TPromise.wrapError<R>(new Error('no adapter found'));
J
Johannes Rieken 已提交
772
		}
J
Johannes Rieken 已提交
773
		return callback(<any>adapter);
774 775
	}

J
Johannes Rieken 已提交
776 777 778
	// --- outline

	registerDocumentSymbolProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentSymbolProvider): vscode.Disposable {
779
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
780
		this._adapter.set(handle, new OutlineAdapter(this._documents, provider));
781
		this._proxy.$registerOutlineSupport(handle, selector);
J
Johannes Rieken 已提交
782 783 784
		return this._createDisposable(handle);
	}

785 786
	$provideDocumentSymbols(handle: number, resource: URI): TPromise<modes.SymbolInformation[]> {
		return this._withAdapter(handle, OutlineAdapter, adapter => adapter.provideDocumentSymbols(resource));
J
Johannes Rieken 已提交
787
	}
788 789 790 791 792

	// --- code lens

	registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
		const handle = this._nextHandle();
793 794
		const eventHandle = typeof provider.onDidChangeCodeLenses === 'function' ? this._nextHandle() : undefined;

J
Johannes Rieken 已提交
795
		this._adapter.set(handle, new CodeLensAdapter(this._documents, this._commands.converter, this._heapService, provider));
796 797 798 799 800 801 802 803 804
		this._proxy.$registerCodeLensSupport(handle, selector, eventHandle);
		let result = this._createDisposable(handle);

		if (eventHandle !== undefined) {
			const subscription = provider.onDidChangeCodeLenses(_ => this._proxy.$emitCodeLensEvent(eventHandle));
			result = Disposable.from(result, subscription);
		}

		return result;
805 806
	}

807 808
	$provideCodeLenses(handle: number, resource: URI): TPromise<modes.ICodeLensSymbol[]> {
		return this._withAdapter(handle, CodeLensAdapter, adapter => adapter.provideCodeLenses(resource));
809 810
	}

811 812
	$resolveCodeLens(handle: number, resource: URI, symbol: modes.ICodeLensSymbol): TPromise<modes.ICodeLensSymbol> {
		return this._withAdapter(handle, CodeLensAdapter, adapter => adapter.resolveCodeLens(resource, symbol));
J
Johannes Rieken 已提交
813 814 815 816 817 818
	}

	// --- declaration

	registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
819
		this._adapter.set(handle, new DefinitionAdapter(this._documents, provider));
J
Johannes Rieken 已提交
820 821
		this._proxy.$registerDeclaractionSupport(handle, selector);
		return this._createDisposable(handle);
822 823
	}

824 825
	$provideDefinition(handle: number, resource: URI, position: IPosition): TPromise<modes.Definition> {
		return this._withAdapter(handle, DefinitionAdapter, adapter => adapter.provideDefinition(resource, position));
J
Johannes Rieken 已提交
826
	}
J
Johannes Rieken 已提交
827

M
Matt Bierner 已提交
828
	registerImplementationProvider(selector: vscode.DocumentSelector, provider: vscode.ImplementationProvider): vscode.Disposable {
829 830 831 832 833 834
		const handle = this._nextHandle();
		this._adapter.set(handle, new ImplementationAdapter(this._documents, provider));
		this._proxy.$registerImplementationSupport(handle, selector);
		return this._createDisposable(handle);
	}

M
Matt Bierner 已提交
835 836
	$provideImplementation(handle: number, resource: URI, position: IPosition): TPromise<modes.Definition> {
		return this._withAdapter(handle, ImplementationAdapter, adapter => adapter.provideImplementation(resource, position));
837 838
	}

839 840 841 842 843 844 845 846 847 848 849
	registerTypeDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.TypeDefinitionProvider): vscode.Disposable {
		const handle = this._nextHandle();
		this._adapter.set(handle, new TypeDefinitionAdapter(this._documents, provider));
		this._proxy.$registerTypeDefinitionSupport(handle, selector);
		return this._createDisposable(handle);
	}

	$provideTypeDefinition(handle: number, resource: URI, position: IPosition): TPromise<modes.Definition> {
		return this._withAdapter(handle, TypeDefinitionAdapter, adapter => adapter.provideTypeDefinition(resource, position));
	}

J
Johannes Rieken 已提交
850 851 852 853
	// --- extra info

	registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
854
		this._adapter.set(handle, new HoverAdapter(this._documents, provider));
A
Alex Dima 已提交
855
		this._proxy.$registerHoverProvider(handle, selector);
J
Johannes Rieken 已提交
856 857 858
		return this._createDisposable(handle);
	}

859
	$provideHover(handle: number, resource: URI, position: IPosition): TPromise<modes.Hover> {
860
		return this._withAdapter(handle, HoverAdapter, adpater => adpater.provideHover(resource, position));
J
Johannes Rieken 已提交
861
	}
862

J
Johannes Rieken 已提交
863
	// --- occurrences
864 865 866

	registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
867
		this._adapter.set(handle, new DocumentHighlightAdapter(this._documents, provider));
868
		this._proxy.$registerDocumentHighlightProvider(handle, selector);
869 870 871
		return this._createDisposable(handle);
	}

872 873
	$provideDocumentHighlights(handle: number, resource: URI, position: IPosition): TPromise<modes.DocumentHighlight[]> {
		return this._withAdapter(handle, DocumentHighlightAdapter, adapter => adapter.provideDocumentHighlights(resource, position));
874
	}
J
Johannes Rieken 已提交
875 876 877 878 879

	// --- references

	registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
880
		this._adapter.set(handle, new ReferenceAdapter(this._documents, provider));
J
Johannes Rieken 已提交
881 882 883 884
		this._proxy.$registerReferenceSupport(handle, selector);
		return this._createDisposable(handle);
	}

885 886
	$provideReferences(handle: number, resource: URI, position: IPosition, context: modes.ReferenceContext): TPromise<modes.Location[]> {
		return this._withAdapter(handle, ReferenceAdapter, adapter => adapter.provideReferences(resource, position, context));
J
Johannes Rieken 已提交
887 888
	}

J
Johannes Rieken 已提交
889 890 891 892
	// --- quick fix

	registerCodeActionProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
893
		this._adapter.set(handle, new QuickFixAdapter(this._documents, this._commands.converter, this._diagnostics, this._heapService, provider));
J
Johannes Rieken 已提交
894 895 896 897
		this._proxy.$registerQuickFixSupport(handle, selector);
		return this._createDisposable(handle);
	}

J
Johannes Rieken 已提交
898
	$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.Command[]> {
899
		return this._withAdapter(handle, QuickFixAdapter, adapter => adapter.provideCodeActions(resource, range));
J
Johannes Rieken 已提交
900
	}
901 902 903 904 905

	// --- formatting

	registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
906
		this._adapter.set(handle, new DocumentFormattingAdapter(this._documents, provider));
907 908 909 910
		this._proxy.$registerDocumentFormattingSupport(handle, selector);
		return this._createDisposable(handle);
	}

A
Alex Dima 已提交
911
	$provideDocumentFormattingEdits(handle: number, resource: URI, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
912
		return this._withAdapter(handle, DocumentFormattingAdapter, adapter => adapter.provideDocumentFormattingEdits(resource, options));
913 914 915 916
	}

	registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
917
		this._adapter.set(handle, new RangeFormattingAdapter(this._documents, provider));
918 919 920 921
		this._proxy.$registerRangeFormattingSupport(handle, selector);
		return this._createDisposable(handle);
	}

A
Alex Dima 已提交
922
	$provideDocumentRangeFormattingEdits(handle: number, resource: URI, range: IRange, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
923
		return this._withAdapter(handle, RangeFormattingAdapter, adapter => adapter.provideDocumentRangeFormattingEdits(resource, range, options));
924 925 926 927
	}

	registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, triggerCharacters: string[]): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
928
		this._adapter.set(handle, new OnTypeFormattingAdapter(this._documents, provider));
929 930 931 932
		this._proxy.$registerOnTypeFormattingSupport(handle, selector, triggerCharacters);
		return this._createDisposable(handle);
	}

A
Alex Dima 已提交
933
	$provideOnTypeFormattingEdits(handle: number, resource: URI, position: IPosition, ch: string, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
934
		return this._withAdapter(handle, OnTypeFormattingAdapter, adapter => adapter.provideOnTypeFormattingEdits(resource, position, ch, options));
935 936
	}

937 938 939 940
	// --- navigate types

	registerWorkspaceSymbolProvider(provider: vscode.WorkspaceSymbolProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
941
		this._adapter.set(handle, new NavigateTypeAdapter(provider, this._heapService));
942 943 944 945
		this._proxy.$registerNavigateTypeSupport(handle);
		return this._createDisposable(handle);
	}

946
	$provideWorkspaceSymbols(handle: number, search: string): TPromise<modes.SymbolInformation[]> {
947 948 949
		return this._withAdapter(handle, NavigateTypeAdapter, adapter => adapter.provideWorkspaceSymbols(search));
	}

950
	$resolveWorkspaceSymbol(handle: number, symbol: modes.SymbolInformation): TPromise<modes.SymbolInformation> {
951
		return this._withAdapter(handle, NavigateTypeAdapter, adapter => adapter.resolveWorkspaceSymbol(symbol));
952
	}
J
Johannes Rieken 已提交
953 954 955 956 957

	// --- rename

	registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
958
		this._adapter.set(handle, new RenameAdapter(this._documents, provider));
J
Johannes Rieken 已提交
959 960 961 962
		this._proxy.$registerRenameSupport(handle, selector);
		return this._createDisposable(handle);
	}

963 964
	$provideRenameEdits(handle: number, resource: URI, position: IPosition, newName: string): TPromise<modes.WorkspaceEdit> {
		return this._withAdapter(handle, RenameAdapter, adapter => adapter.provideRenameEdits(resource, position, newName));
J
Johannes Rieken 已提交
965
	}
966 967 968

	// --- suggestion

969
	registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, triggerCharacters: string[]): vscode.Disposable {
970
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
971
		this._adapter.set(handle, new SuggestAdapter(this._documents, this._commands.converter, this._heapService, provider));
972 973 974 975
		this._proxy.$registerSuggestSupport(handle, selector, triggerCharacters);
		return this._createDisposable(handle);
	}

976
	$provideCompletionItems(handle: number, resource: URI, position: IPosition): TPromise<modes.ISuggestResult> {
977
		return this._withAdapter(handle, SuggestAdapter, adapter => adapter.provideCompletionItems(resource, position));
978 979
	}

980 981
	$resolveCompletionItem(handle: number, resource: URI, position: IPosition, suggestion: modes.ISuggestion): TPromise<modes.ISuggestion> {
		return this._withAdapter(handle, SuggestAdapter, adapter => adapter.resolveCompletionItem(resource, position, suggestion));
982
	}
983 984 985 986 987

	// --- parameter hints

	registerSignatureHelpProvider(selector: vscode.DocumentSelector, provider: vscode.SignatureHelpProvider, triggerCharacters: string[]): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
988
		this._adapter.set(handle, new SignatureHelpAdapter(this._documents, provider));
A
Alex Dima 已提交
989
		this._proxy.$registerSignatureHelpProvider(handle, selector, triggerCharacters);
990 991 992
		return this._createDisposable(handle);
	}

993
	$provideSignatureHelp(handle: number, resource: URI, position: IPosition): TPromise<modes.SignatureHelp> {
A
Alex Dima 已提交
994
		return this._withAdapter(handle, SignatureHelpAdapter, adapter => adapter.provideSignatureHelp(resource, position));
995
	}
J
Johannes Rieken 已提交
996

J
Johannes Rieken 已提交
997 998 999 1000
	// --- links

	registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
		const handle = this._nextHandle();
J
Johannes Rieken 已提交
1001
		this._adapter.set(handle, new LinkProviderAdapter(this._documents, provider));
J
Johannes Rieken 已提交
1002 1003 1004 1005
		this._proxy.$registerDocumentLinkProvider(handle, selector);
		return this._createDisposable(handle);
	}

1006
	$provideDocumentLinks(handle: number, resource: URI): TPromise<modes.ILink[]> {
J
Johannes Rieken 已提交
1007 1008 1009
		return this._withAdapter(handle, LinkProviderAdapter, adapter => adapter.provideLinks(resource));
	}

1010 1011 1012 1013
	$resolveDocumentLink(handle: number, link: modes.ILink): TPromise<modes.ILink> {
		return this._withAdapter(handle, LinkProviderAdapter, adapter => adapter.resolveLink(link));
	}

1014 1015
	registerColorProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider): vscode.Disposable {
		const handle = this._nextHandle();
1016
		this._adapter.set(handle, new ColorProviderAdapter(this._proxy, this._documents, provider));
1017 1018 1019 1020
		this._proxy.$registerDocumentColorProvider(handle, selector);
		return this._createDisposable(handle);
	}

1021
	$provideDocumentColors(handle: number, resource: URI): TPromise<IRawColorInfo[]> {
1022 1023 1024
		return this._withAdapter(handle, ColorProviderAdapter, adapter => adapter.provideColors(resource));
	}

1025
	// --- configuration
J
Johannes Rieken 已提交
1026

J
Johannes Rieken 已提交
1027
	setLanguageConfiguration(languageId: string, configuration: vscode.LanguageConfiguration): vscode.Disposable {
1028
		let { wordPattern } = configuration;
J
Johannes Rieken 已提交
1029

1030 1031 1032
		// check for a valid word pattern
		if (wordPattern && regExpLeadsToEndlessLoop(wordPattern)) {
			throw new Error(`Invalid language configuration: wordPattern '${wordPattern}' is not allowed to match the empty string.`);
J
Johannes Rieken 已提交
1033
		}
J
Johannes Rieken 已提交
1034

1035 1036 1037 1038 1039 1040
		// word definition
		if (wordPattern) {
			this._documents.setWordDefinitionFor(languageId, wordPattern);
		} else {
			this._documents.setWordDefinitionFor(languageId, null);
		}
1041

1042 1043 1044
		const handle = this._nextHandle();
		this._proxy.$setLanguageConfiguration(handle, languageId, configuration);
		return this._createDisposable(handle);
1045
	}
1046
}