typescriptMode.ts 21.5 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*---------------------------------------------------------------------------------------------
 *  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 nls from 'vs/nls';
import WinJS = require('vs/base/common/winjs.base');
import URI from 'vs/base/common/uri';
import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import lifecycle = require('vs/base/common/lifecycle');
import async = require('vs/base/common/async');
import supports = require('vs/editor/common/modes/supports');
import tokenization = require('vs/languages/typescript/common/features/tokenization');
import quickFixMainActions = require('vs/languages/typescript/common/features/quickFixMainActions');
import typescriptWorker = require('vs/languages/typescript/common/typescriptWorker2');
import typescript = require('vs/languages/typescript/common/typescript');
import ts = require('vs/languages/typescript/common/lib/typescriptServices');
import {AbstractMode, createWordRegExp} from 'vs/editor/common/modes/abstractMode';
import {IModelService} from 'vs/editor/common/services/modelService';
import {OneWorkerAttr, AllWorkersAttr} from 'vs/platform/thread/common/threadService';
import {AsyncDescriptor, AsyncDescriptor2, createAsyncDescriptor2} from 'vs/platform/instantiation/common/descriptors';
import {IMarker} from 'vs/platform/markers/common/markers';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IThreadService, ThreadAffinity} from 'vs/platform/thread/common/thread';
import {OnEnterSupport} from 'vs/editor/common/modes/supports/onEnter';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';

class SemanticValidator {

	private _modelService: IModelService;
	private _mode: TypeScriptMode<any>;
	private _validation: async.RunOnceScheduler;
	private _lastChangedResource: URI;
	private _listener: { [r: string]: Function } = Object.create(null);

38 39
	constructor(mode: TypeScriptMode<any>, @IModelService modelService: IModelService) {
		this._modelService = modelService;
E
Erich Gamma 已提交
40 41 42
		this._mode = mode;
		this._validation = new async.RunOnceScheduler(this._doValidate.bind(this), 750);
		if (this._modelService) {
43 44 45
			this._modelService.onModelAdded(this._onModelAdded, this);
			this._modelService.onModelRemoved(this._onModelRemoved, this);
			this._modelService.onModelModeChanged(event => {
E
Erich Gamma 已提交
46
				// Handle a model mode changed as a remove + add
47 48
				this._onModelRemoved(event.model);
				this._onModelAdded(event.model);
E
Erich Gamma 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
			}, this);
			this._modelService.getModels().forEach(this._onModelAdded, this);
		// } else {
		// 	console.warn('NO model service for validation');
		}
	}

	public dispose(): void {
		this._validation.dispose();
	}

	private _lastValidationReq: number = 0;

	public validateOpen(): void {
		this._scheduleValidation();
	}

	private _scheduleValidation(resource?: URI): void {
		this._lastValidationReq += 1;
		this._lastChangedResource = resource;
		this._validation.schedule();
	}

	private _doValidate(): void {

		var resources: URI[] = [];
		if (this._lastChangedResource) {
			resources.push(this._lastChangedResource);
		}
		for (var k in this._listener) {
			if (!this._lastChangedResource || k !== this._lastChangedResource.toString()) {
				resources.push(URI.parse(k));
			}
		}

		var thisValidationReq = this._lastValidationReq;
		var validate = async.sequence(resources.map(r => {
			return () => {

				if (!this._modelService.getModel(r)) {
					return WinJS.Promise.as(undefined);
				}

				if (thisValidationReq === this._lastValidationReq) {
					return this._mode.performSemanticValidation(r);
				}
			}
		}));

		validate.done(undefined, err => console.warn(err));
	}

	private _onModelAdded(model: EditorCommon.IModel): void {

		if (!this._mode._shouldBeValidated(model)) {
			return;
		}

		var validate: Function,
			unbind: Function;

		validate = () => {
			this._scheduleValidation(model.getAssociatedResource());
		};

		unbind = model.addListener(EditorCommon.EventType.ModelContentChanged2, _ => validate());
		this._listener[model.getAssociatedResource().toString()] = unbind;
		validate();
	}

	private _onModelRemoved(model: EditorCommon.IModel): void {
		var unbind = this._listener[model.getAssociatedResource().toString()];
		if (unbind) {
			unbind();
			delete this._listener[model.getAssociatedResource().toString()];
		}
	}
}

export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extends AbstractMode<W> implements lifecycle.IDisposable {

	public tokenizationSupport: Modes.ITokenizationSupport;
	public electricCharacterSupport: Modes.IElectricCharacterSupport;
	public characterPairSupport: Modes.ICharacterPairSupport;
	public referenceSupport: Modes.IReferenceSupport;
	public extraInfoSupport:Modes.IExtraInfoSupport;
135
	public occurrencesSupport:Modes.IOccurrencesSupport;
E
Erich Gamma 已提交
136 137 138 139 140 141 142 143 144 145 146 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188
	public quickFixSupport:Modes.IQuickFixSupport;
	public logicalSelectionSupport:Modes.ILogicalSelectionSupport;
	public parameterHintsSupport:Modes.IParameterHintsSupport;
	public outlineSupport:Modes.IOutlineSupport;
	public declarationSupport: Modes.IDeclarationSupport;
	public formattingSupport: Modes.IFormattingSupport;
	public emitOutputSupport:Modes.IEmitOutputSupport;
	public renameSupport: Modes.IRenameSupport;
	public suggestSupport: Modes.ISuggestSupport;

	public onEnterSupport: Modes.IOnEnterSupport;

	private _telemetryService: ITelemetryService;
	private _disposables: lifecycle.IDisposable[] = [];
	private _projectResolver: WinJS.TPromise<typescript.IProjectResolver2>;
	private _semanticValidator: SemanticValidator;

	constructor(
		descriptor:Modes.IModeDescriptor,
		@IInstantiationService instantiationService: IInstantiationService,
		@IThreadService threadService: IThreadService,
		@ITelemetryService telemetryService: ITelemetryService
	) {
		super(descriptor, instantiationService, threadService);
		this._telemetryService = telemetryService;

		if (this._threadService && this._threadService.isInMainThread) {

			// semantic validation from the client side
			this._semanticValidator = instantiationService.createInstance(SemanticValidator, this);
			this._disposables.push(this._semanticValidator);

			// create project resolver
			var desc = this._getProjectResolver();
			if(!desc) {
				throw new Error('missing project resolver!');
			}
			if (desc instanceof AsyncDescriptor) {
				this._projectResolver = instantiationService.createInstance(desc, this).then(undefined, err => {
					console.error(err);
					return typescript.Defaults.ProjectResolver;
				});
			} else {
				this._projectResolver = WinJS.TPromise.as(desc);
			}

			this._projectResolver = this._projectResolver.then(instance => {
				instance.setConsumer(this);
				return instance;
			});
		}

		this.extraInfoSupport = this;
189
		this.occurrencesSupport = this;
E
Erich Gamma 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
		this.formattingSupport = this;
		this.quickFixSupport = this;
		this.logicalSelectionSupport = this;
		this.outlineSupport = this;
		this.emitOutputSupport = this;
		this.renameSupport = this;
		this.tokenizationSupport = tokenization.createTokenizationSupport(this, tokenization.Language.TypeScript);

		this.electricCharacterSupport = new supports.BracketElectricCharacterSupport(this, {
			brackets: [
				{ tokenType:'delimiter.bracket.ts', open: '{', close: '}', isElectric: true },
				{ tokenType:'delimiter.array.ts', open: '[', close: ']', isElectric: true },
				{ tokenType:'delimiter.parenthesis.ts', open: '(', close: ')', isElectric: true }
			],
			docComment: {scope:'comment.doc', open:'/**', lineStart:' * ', close:' */'} });

		this.referenceSupport = new supports.ReferenceSupport(this, {
			tokens: ['identifier.ts'],
			findReferences: (resource, position, includeDeclaration) => this.findReferences(resource, position, includeDeclaration)});

		this.declarationSupport = new supports.DeclarationSupport(this, {
			tokens: ['identifier.ts', 'string.ts', 'attribute.value.vs'],
			findDeclaration: (resource, position) => this.findDeclaration(resource, position)});

		this.parameterHintsSupport = new supports.ParameterHintsSupport(this, {
			triggerCharacters: ['(', ','],
			excludeTokens: ['string.ts'],
			getParameterHints: (resource, position) => this.getParameterHints(resource, position)});

		this.characterPairSupport = new supports.CharacterPairSupport(this, {
			autoClosingPairs:
				[	{ open: '{', close: '}' },
					{ open: '[', close: ']' },
					{ open: '(', close: ')' },
					{ open: '"', close: '"', notIn: ['string'] },
					{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
					{ open: '`', close: '`' }
				]});

		this.suggestSupport = new supports.SuggestSupport(this, {
			triggerCharacters: ['.'],
			excludeTokens: ['string', 'comment', 'number'],
			sortBy: [{type:'reference', partSeparator: '/'}],
			suggest: (resource, position) => this.suggest(resource, position),
			getSuggestionDetails: (resource, position, suggestion) => this.getSuggestionDetails(resource, position, suggestion)});

		this.onEnterSupport = new OnEnterSupport(this.getId(), {
			brackets: [
				{ open: '{', close: '}' },
				{ open: '[', close: ']' },
				{ open: '(', close: ')' },
			],
			regExpRules: [
				{
					// e.g. /** | */
					beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
					afterText: /^\s*\*\/$/,
					action: { indentAction: Modes.IndentAction.IndentOutdent, appendText: ' * ' }
				},
				{
					// e.g. /** ...|
					beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
					action: { indentAction: Modes.IndentAction.None, appendText: ' * ' }
				},
				{
					// e.g.  * ...|
256
					beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
E
Erich Gamma 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
					action: { indentAction: Modes.IndentAction.None, appendText: '* ' }
				},
				{
					// e.g.  */|
					beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
					action: { indentAction: Modes.IndentAction.None, removeText: 1 }
				}
			]
		});
	}

	public dispose(): void {
		this._disposables = lifecycle.disposeAll(this._disposables);
	}

	_shouldBeValidated(model: EditorCommon.IModel): boolean {
		return model.getMode() === this || /\.ts$/.test(model.getAssociatedResource().fsPath);
	}

	// ---- project sync

	protected _getProjectResolver(): AsyncDescriptor<typescript.IProjectResolver2>|typescript.IProjectResolver2 {
		return typescript.Extensions.getProjectResolver() || typescript.Defaults.ProjectResolver;
	}

	acceptProjectChanges(changes: { kind: typescript.ChangeKind; resource: URI; files: URI[]; options: ts.CompilerOptions }[]): WinJS.TPromise<{[dirname:string]:URI}> {
		this._semanticValidator.validateOpen();
		return this._doAcceptProjectChanges(changes);
	}

	static $_doAcceptProjectChanges = AllWorkersAttr(TypeScriptMode, TypeScriptMode.prototype._doAcceptProjectChanges);
	private _doAcceptProjectChanges(changes: { kind: typescript.ChangeKind; resource: URI; files: URI[]; options: ts.CompilerOptions }[]): WinJS.TPromise<{[dirname:string]:URI}> {
		return this._worker(worker => worker.acceptProjectChanges(changes));
	}

	acceptFileChanges(changes: { kind: typescript.ChangeKind; resource: URI; content: string }[]): WinJS.TPromise<boolean> {

		let newLengthTotal = 0;
		for(let change of changes) {
			if(change.content) {
				newLengthTotal += change.content.length;
			}
		}

		return this._canAcceptFileChanges(newLengthTotal).then(canAccept => {
			if (canAccept === false) { // explict compare with false because the tests return null here
				return WinJS.TPromise.wrapError(nls.localize('err.tooMuchData',
					"Sorry, but there are too many JavaScript source files for VS Code. Consider using the exclude-property in jsconfig.json."))
			}
			return this._doAcceptFileChanges(changes).then(accepted => {
				this._semanticValidator.validateOpen();
				return accepted;
			});
		});
	}

	static $_canAcceptFileChanges = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype._canAcceptFileChanges);
	private _canAcceptFileChanges(length: number): WinJS.TPromise<boolean> {
		return this._worker(worker => worker.canAcceptFileChanges(length));
	}

	static $_doAcceptFileChanges = AllWorkersAttr(TypeScriptMode, TypeScriptMode.prototype._doAcceptFileChanges);
	private _doAcceptFileChanges(changes: { kind: typescript.ChangeKind; resource: URI; content: string }[]): WinJS.TPromise<boolean> {
		return this._worker(worker => worker.acceptFileChanges(changes));
	}

	private _defaultLibPromise: WinJS.TPromise<any>;

	private _defaultLib(): WinJS.TPromise<any> {
		if (!this._defaultLibPromise) {

			var fileChanges: typescript.IFileChange[] = [];
			var p1 = new WinJS.TPromise<string>((c, e) => require([typescript.defaultLib.path.substr(1)], c, e)).then(content => {
				fileChanges.push({
					kind: typescript.ChangeKind.Added,
					resource: typescript.defaultLib,
					content
				});
			});
			var p2 = new WinJS.TPromise<string>((c, e) => require([typescript.defaultLibES6.path.substr(1)], c, e)).then(content => {
				fileChanges.push({
					kind: typescript.ChangeKind.Added,
					resource: typescript.defaultLibES6,
					content
				});
			});

			this._defaultLibPromise = WinJS.TPromise.join([p1, p2]).then(values => this.acceptFileChanges(fileChanges));
		}
		return new async.ShallowCancelThenPromise(this._defaultLibPromise);
	}

	private _syncProjects(): WinJS.TPromise<any> {
		if (this._projectResolver) {
			return this._defaultLib()
				.then(_ => this._projectResolver)
				.then(r => r.resolveProjects());
		}
	}

	public configure(options: any): WinJS.TPromise<boolean> {
		var ret = super.configure(options);
		if (this._semanticValidator) {
			ret.then(validate => validate && this._semanticValidator.validateOpen());
		}
		return ret;
	}

	// ---- worker talk

	protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], typescriptWorker.TypeScriptWorker2> {
		return createAsyncDescriptor2('vs/languages/typescript/common/typescriptWorker2', 'TypeScriptWorker2');
	}

	public getCommentsConfiguration():Modes.ICommentsConfiguration {
		return { lineCommentTokens: ['//'], blockCommentStartToken: '/*', blockCommentEndToken: '*/' };
	}

	static $_pickAWorkerToValidate = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype._pickAWorkerToValidate, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group3);
	public _pickAWorkerToValidate(): WinJS.Promise {
		return this._worker((w) => w.enableValidator());
	}

	public performSemanticValidation(resource: URI): WinJS.TPromise<void> {
		return this.doValidateSemantics(resource).then(missesFiles => {
			if (!missesFiles) {
				return;
			}
			return this.getMissingFiles().then(missing => {
				if (missing) {
					// console.log(`${resource.fsPath} misses ~${missing.length} resources`);
					return this._projectResolver.then(resolver => {
						return resolver.resolveFiles(missing);
					});
				}
			});
		});
	}

	static $doValidateSemantics = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.doValidateSemantics, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group3);
	public doValidateSemantics(resource: URI): WinJS.TPromise<boolean> {
		return this._worker(w => w.doValidateSemantics(resource));
	}

	static $getMissingFiles = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getMissingFiles, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group3);
	public getMissingFiles(): WinJS.TPromise<URI[]> {
		return this._worker(w => w.getMissingFiles());
	}

	static $getOutline = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getOutline, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group1);
407
	public getOutline(resource:URI):WinJS.TPromise<Modes.IOutlineEntry[]> {
E
Erich Gamma 已提交
408 409 410 411
		return this._worker((w) => w.getOutline(resource));
	}

	static $findOccurrences = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.findOccurrences, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
412
	public findOccurrences(resource:URI, position:EditorCommon.IPosition, strict:boolean = false): WinJS.TPromise<Modes.IOccurence[]> {
E
Erich Gamma 已提交
413 414 415 416
		return this._worker((w) => w.findOccurrences(resource, position, strict));
	}

	static $suggest = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.suggest, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
417
	public suggest(resource:URI, position:EditorCommon.IPosition):WinJS.TPromise<Modes.ISuggestResult[]> {
E
Erich Gamma 已提交
418 419 420 421
		return this._worker((w) => w.suggest(resource, position));
	}

	static $getSuggestionDetails = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getSuggestionDetails, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
422
	public getSuggestionDetails(resource:URI, position:EditorCommon.IPosition, suggestion:Modes.ISuggestion):WinJS.TPromise<Modes.ISuggestion> {
E
Erich Gamma 已提交
423 424 425 426
		return this._worker((w) => w.getSuggestionDetails(resource, position, suggestion));
	}

	static $getParameterHints = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getParameterHints, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
427
	public getParameterHints(resource:URI, position:EditorCommon.IPosition):WinJS.TPromise<Modes.IParameterHints> {
E
Erich Gamma 已提交
428 429 430 431
		return this._worker((w) => w.getParameterHints(resource, position));
	}

	static $getEmitOutput = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getEmitOutput, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group3);
432
	public getEmitOutput(resource:URI, type:string = undefined):WinJS.Promise {
E
Erich Gamma 已提交
433 434 435 436 437 438 439 440 441
		return this._worker((w) => w.getEmitOutput(resource, type));
	}

	private static WORD_DEFINITION = createWordRegExp('$');
	public getWordDefinition():RegExp {
		return TypeScriptMode.WORD_DEFINITION;
	}

	static $findReferences = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.findReferences, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group3);
442
	public findReferences(resource:URI, position:EditorCommon.IPosition, includeDeclaration:boolean):WinJS.TPromise<Modes.IReference[]> {
E
Erich Gamma 已提交
443 444 445 446 447 448 449 450 451 452 453 454
		return this._worker((w) => w.findReferences(resource, position, includeDeclaration));
	}

	public get filter() {
		return ['identifier.ts', 'string.ts'];
	}

	static $rename = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.rename, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
	public rename(resource: URI, position: EditorCommon.IPosition, newName: string): WinJS.TPromise<Modes.IRenameResult> {
		return this._worker(w => w.rename(resource, position, newName));
	}

455
	public runQuickFixAction(resource:  URI, range: EditorCommon.IRange, id: any): WinJS.TPromise<Modes.IQuickFixResult> {
E
Erich Gamma 已提交
456 457 458 459 460 461 462 463 464 465
		var quickFixMainSupport = this._instantiationService.createInstance(quickFixMainActions.QuickFixMainActions);
		return quickFixMainSupport.evaluate(resource, range, id).then((action) => {
			if (action) {
				return action;
			}
			return this.runQuickFixActionInWorker(resource, range, id);
		});
	}

	static $runQuickFixActionInWorker = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.runQuickFixActionInWorker, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
466
	public runQuickFixActionInWorker(resource:  URI, range: EditorCommon.IRange, id: any): WinJS.TPromise<Modes.IQuickFixResult> {
E
Erich Gamma 已提交
467 468 469 470
		return this._worker((w) => w.runQuickFixAction(resource, range, id));
	}

	static $getQuickFixes = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getQuickFixes, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
471
	public getQuickFixes(resource: URI, range: IMarker | EditorCommon.IRange):WinJS.TPromise<Modes.IQuickFix[]> {
E
Erich Gamma 已提交
472 473 474 475
		return this._worker((w) => w.getQuickFixes(resource, range));
	}

	static $getRangesToPosition = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.getRangesToPosition, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group1);
476
	public getRangesToPosition(resource: URI, position:EditorCommon.IPosition):WinJS.TPromise<Modes.ILogicalSelectionEntry[]> {
E
Erich Gamma 已提交
477 478 479 480
		return this._worker((w) => w.getRangesToPosition(resource, position));
	}

	static $findDeclaration = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.findDeclaration, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
481
	public findDeclaration(resource: URI, position:any):WinJS.TPromise<Modes.IReference> {
E
Erich Gamma 已提交
482 483 484 485
		return this._worker((w) => w.findDeclaration(resource, position));
	}

	static $computeInfo = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.computeInfo, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group2);
486
	public computeInfo(resource: URI, position:EditorCommon.IPosition): WinJS.TPromise<Modes.IComputeExtraInfoResult> {
E
Erich Gamma 已提交
487 488 489 490 491 492 493 494
		return this._worker((w) => w.computeInfo(resource, position));
	}

	public get autoFormatTriggerCharacters():string[] {
		return [';', '}', '\n'];
	}

	static $formatDocument = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.formatDocument, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group1);
495
	public formatDocument(resource: URI, options:Modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
E
Erich Gamma 已提交
496 497 498 499
		return this._worker((w) => w.formatDocument(resource, options));
	}

	static $formatRange = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.formatRange, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group1);
500
	public formatRange(resource: URI, range:EditorCommon.IRange, options:Modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
E
Erich Gamma 已提交
501 502 503 504
		return this._worker((w) => w.formatRange(resource, range, options));
	}

	static $formatAfterKeystroke = OneWorkerAttr(TypeScriptMode, TypeScriptMode.prototype.formatAfterKeystroke, TypeScriptMode.prototype._syncProjects, ThreadAffinity.Group1);
505
	public formatAfterKeystroke(resource: URI, position:EditorCommon.IPosition, ch: string, options:Modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
E
Erich Gamma 已提交
506 507 508
		return this._worker((w) => w.formatAfterKeystroke(resource, position, ch, options));
	}
}