modes.ts 21.2 KB
Newer Older
E
Erich Gamma 已提交
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 {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {IDisposable} from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
9 10
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
11
import {IFilter} from 'vs/base/common/filters';
A
Alex Dima 已提交
12
import * as editorCommon from 'vs/editor/common/editorCommon';
A
Alex Dima 已提交
13
import {ModeTransition} from 'vs/editor/common/core/modeTransition';
14
import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry';
15
import {CancellationToken} from 'vs/base/common/cancellation';
E
Erich Gamma 已提交
16 17 18

export interface ITokenizationResult {
	type?:string;
A
Alex Dima 已提交
19
	dontMergeWithPrev?:boolean;
E
Erich Gamma 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
	nextState?:IState;
}

export interface IState {
	clone():IState;
	equals(other:IState):boolean;
	getMode():IMode;
	tokenize(stream:IStream):ITokenizationResult;
	getStateData(): IState;
	setStateData(state:IState):void;
}

/**
 * An IStream is a character & token stream abstraction over a line of text. It
 *  is never multi-line. The stream can be navigated character by character, or
 *  token by token, given some token rules.
 */
export interface IStream {

	/**
	 * Returns the current character position of the stream on the line.
	 */
	pos():number;

	/**
	 * Returns true iff the stream is at the end of the line.
	 */
	eos():boolean;

	/**
	 * Returns the next character in the stream.
	 */
	peek():string;

	/**
	 * Returns the next character in the stream, and advances it by one character.
	 */
	next(): string;
	next2(): void;

	/**
	 * Advances the stream by `n` characters.
	 */
	advance(n:number):string;

	/**
	 * Advances the stream until the end of the line.
	 */
	advanceToEOS():string;

	/**
	 * Brings the stream back `n` characters.
	 */
	goBack(n:number):void;

	/**
	 *  Advances the stream if the next characters validate a condition. A condition can be
	 *
	 *      - a regular expression (always starting with ^)
	 * 			EXAMPLES: /^\d+/, /^function|var|interface|class/
	 *
	 *  	- a string
	 * 			EXAMPLES: "1954", "albert"
	 */
	advanceIfCharCode(charCode: number): string;
	advanceIfCharCode2(charCode:number): number;

	advanceIfString(condition: string): string;
	advanceIfString2(condition: string): number;

	advanceIfStringCaseInsensitive(condition: string): string;
	advanceIfStringCaseInsensitive2(condition: string): number;

	advanceIfRegExp(condition: RegExp): string;
	advanceIfRegExp2(condition:RegExp): number;


	/**
	 * Advances the stream while the next characters validate a condition. Check #advanceIf for
	 * details on the possible types for condition.
	 */
	advanceWhile(condition:string):string;
	advanceWhile(condition:RegExp):string;

	/**
	 * Advances the stream until the some characters validate a condition. Check #advanceIf for
	 * details on the possible types for condition. The `including` boolean value indicates
	 * whether the stream will advance the characters that matched the condition as well, or not.
	 */
	advanceUntil(condition: string, including: boolean): string;
	advanceUntil(condition: RegExp, including: boolean): string;

	advanceUntilString(condition: string, including: boolean): string;
	advanceUntilString2(condition: string, including: boolean): number;

	/**
	 * The token rules define how consecutive characters should be put together as a token,
	 * or separated into two different tokens. They are given through a separator characters
	 * string and a whitespace characters string. A separator is always one token. Consecutive
	 * whitespace is always one token. Everything in between these two token types, is also a token.
	 *
	 * 	EXAMPLE: stream.setTokenRules("+-", " ");
	 * 	Setting these token rules defines the tokens for the string "123+456 -    7" as being
	 * 		["123", "+", "456", " ", "-", "    ", "7"]
	 */
	setTokenRules(separators:string, whitespace:string):void;

	/**
	 * Returns the next token, given that the stream was configured with token rules.
	 */
	peekToken():string;

	/**
	 * Returns the next token, given that the stream was configured with token rules, and advances the
	 * stream by the exact length of the found token.
	 */
	nextToken():string;

	/**
	 * Returns the next whitespace, if found. Returns an empty string otherwise.
	 */
	peekWhitespace():string;

	/**
	 * Returns the next whitespace, if found, and advances the stream by the exact length of the found
	 * whitespace. Returns an empty string otherwise.
	 */
	skipWhitespace(): string;
	skipWhitespace2(): number;
}

export interface IModeDescriptor {
	id:string;
}

export interface ILineContext {
	getLineContent(): string;

A
Alex Dima 已提交
158
	modeTransitions: ModeTransition[];
E
Erich Gamma 已提交
159 160 161 162 163 164 165 166 167

	getTokenCount(): number;
	getTokenStartIndex(tokenIndex:number): number;
	getTokenType(tokenIndex:number): string;
	getTokenText(tokenIndex:number): string;
	getTokenEndIndex(tokenIndex:number): number;
	findIndexOfOffset(offset:number): number;
}

A
Alex Dima 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
export enum MutableSupport {
	RichEditSupport = 1,
	TokenizationSupport = 2,
	SuggestSupport = 3
}
export function mutableSupportToString(registerableSupport:MutableSupport) {
	if (registerableSupport === MutableSupport.RichEditSupport) {
		return 'richEditSupport';
	}
	if (registerableSupport === MutableSupport.TokenizationSupport) {
		return 'tokenizationSupport';
	}
	if (registerableSupport === MutableSupport.SuggestSupport) {
		return 'suggestSupport';
	}
	throw new Error('Illegal argument!');
}


E
Erich Gamma 已提交
187 188 189 190
export interface IMode {

	getId(): string;

A
Alex Dima 已提交
191 192 193 194 195
	/**
	 * Return a mode "similar" to this one that strips any "smart" supports.
	 */
	toSimplifiedMode(): IMode;

A
Alex Dima 已提交
196
	addSupportChangedListener?(callback: (e: editorCommon.IModeSupportChangedEvent) => void): IDisposable;
E
Erich Gamma 已提交
197 198 199 200

	/**
	 * Register a support by name. Only optional.
	 */
A
Alex Dima 已提交
201
	registerSupport?<T>(support:MutableSupport, callback:(mode:IMode)=>T): IDisposable;
E
Erich Gamma 已提交
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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272

	/**
	 * Optional adapter to support tokenization.
	 */
	tokenizationSupport?: ITokenizationSupport;

	/**
	 * Optional adapter to support showing occurrences of words or such.
	 */
	occurrencesSupport?:IOccurrencesSupport;

	/**
	 * Optional adapter to support revealing the declaration of a symbol.
	 */
	declarationSupport?: IDeclarationSupport;

	/**
	 * Optional adapter to support finding references to a symbol.
	 */
	referenceSupport?:IReferenceSupport;

	/**
	 * Optional adapter to support intellisense.
	 */
	suggestSupport?:ISuggestSupport;

	/**
	 * Optional adapter to support showing extra info in tokens.
	 */
	extraInfoSupport?:IExtraInfoSupport;

	/**
	 * Optional adapter to support showing an outline.
	 */
	outlineSupport?:IOutlineSupport;

	/**
	 * Optional adapter to support formatting.
	 */
	formattingSupport?:IFormattingSupport;

	/**
	 * Optional adapter to support inplace-replace.
	 */
	inplaceReplaceSupport?:IInplaceReplaceSupport;

	/**
	 * Optional adapter to support output for a model (e.g. markdown -> html)
	 */
	emitOutputSupport?:IEmitOutputSupport;

	/**
	 * Optional adapter to support detecting links.
	 */
	linkSupport?:ILinkSupport;

	/**
	 * Optional adapter to support configuring this mode.
	 */
	configSupport?:IConfigurationSupport;

	/**
	 * Optional adapter to support quick fix of typing errors.
	 */
	quickFixSupport?:IQuickFixSupport;

	/**
	 * Optional adapter to support task running
	 */
	taskSupport?: ITaskSupport;

273 274 275 276
	/**
	 * Optional adapter to support rich editing.
	 */
	richEditSupport?: IRichEditSupport;
E
Erich Gamma 已提交
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
}

/**
 * Interface used for tokenization
 */
export interface IToken {
	startIndex:number;
	type:string;
}

export interface IModeTransition {
	startIndex: number;
	mode: IMode;
}

export interface ILineTokens {
	tokens: IToken[];
	actualStopOffset: number;
	endState: IState;
	modeTransitions: IModeTransition[];
	retokenize?:TPromise<void>;
}

export interface ITokenizationSupport {

	shouldGenerateEmbeddedModels: boolean;

	getInitialState():IState;

	// add offsetDelta to each of the returned indices
	// stop tokenizing at absolute value stopAtOffset (i.e. stream.pos() + offsetDelta > stopAtOffset)
	tokenize(line:string, state:IState, offsetDelta?:number, stopAtOffset?:number):ILineTokens;
}

A
Alex Dima 已提交
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
export interface IToken2 {
	startIndex: number;
	scopes: string|string[];
}
export interface ILineTokens2 {
	tokens: IToken2[];
	endState: IState2;
	retokenize?: TPromise<void>;
}
export interface IState2 {
	clone():IState2;
	equals(other:IState2):boolean;
}
export interface ITokenizationSupport2 {
	getInitialState(): IState2;
	tokenize(line:string, state:IState2): ILineTokens2;
}

E
Erich Gamma 已提交
329
/**
330 331
 * A hover represents additional information for a symbol or word. Hovers are
 * rendered in a tooltip-like widget.
E
Erich Gamma 已提交
332
 */
333 334 335 336 337 338 339 340 341 342 343
export interface Hover {
	/**
	 * The contents of this hover.
	 */
	htmlContent: IHTMLContentElement[];

	/**
	 * The range to which this hover applies. When missing, the
	 * editor will use the range at the current position or the
	 * current position itself.
	 */
A
Alex Dima 已提交
344
	range: editorCommon.IRange;
E
Erich Gamma 已提交
345
}
346

E
Erich Gamma 已提交
347
export interface IExtraInfoSupport {
348
	provideHover(model:editorCommon.IModel, position:editorCommon.IEditorPosition, cancellationToken:CancellationToken): Hover | Thenable<Hover>;
E
Erich Gamma 已提交
349 350
}

J
Johannes Rieken 已提交
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
export type SuggestionType = 'method'
	| 'function'
	| 'constructor'
	| 'field'
	| 'variable'
	| 'class'
	| 'interface'
	| 'module'
	| 'property'
	| 'unit'
	| 'value'
	| 'enum'
	| 'keyword'
	| 'snippet'
	| 'text'
	| 'color'
	| 'file'
	| 'reference'
	| 'customcolor';

E
Erich Gamma 已提交
371 372 373
export interface ISuggestion {
	label: string;
	codeSnippet: string;
J
Johannes Rieken 已提交
374
	type: SuggestionType;
E
Erich Gamma 已提交
375 376 377 378 379
	typeLabel?: string;
	documentationLabel?: string;
	filterText?: string;
	sortText?: string;
	noAutoAccept?: boolean;
380 381
	overwriteBefore?: number;
	overwriteAfter?: number;
E
Erich Gamma 已提交
382 383
}

384
export interface ISuggestResult {
E
Erich Gamma 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397
	currentWord: string;
	suggestions:ISuggestion[];
	incomplete?: boolean;
}

/**
 * Interface used to get completion suggestions at a specific location.
 */
export interface ISuggestSupport {

	/**
	 * Compute all completions for the given resource at the given position.
	 */
A
Alex Dima 已提交
398
	suggest(resource: URI, position: editorCommon.IPosition, triggerCharacter?: string): TPromise<ISuggestResult[]>;
E
Erich Gamma 已提交
399 400 401 402

	/**
	 * Compute more details for the given suggestion.
	 */
A
Alex Dima 已提交
403
	getSuggestionDetails?: (resource: URI, position: editorCommon.IPosition, suggestion: ISuggestion) => TPromise<ISuggestion>;
E
Erich Gamma 已提交
404

405
	filter?: IFilter;
406 407
	getTriggerCharacters(): string[];
	shouldAutotriggerSuggest(context: ILineContext, offset: number, triggeredByCharacter: string): boolean;
E
Erich Gamma 已提交
408 409 410 411 412 413
}

/**
 * Interface used to quick fix typing errors while accesing member fields.
 */
export interface IQuickFix {
414
	command: ICommand;
E
Erich Gamma 已提交
415 416 417 418 419 420 421 422 423
	score: number;
}

export interface IQuickFixResult {
	edits?: IResourceEdit[];
	message?: string;
}

export interface IQuickFixSupport {
424
	getQuickFixes(resource: URI, range: editorCommon.IRange): TPromise<IQuickFix[]>;
E
Erich Gamma 已提交
425 426
}

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
/**
 * Represents a parameter of a callable-signature. A parameter can
 * have a label and a doc-comment.
 */
export interface ParameterInformation {

	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
	label: string;

	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
	documentation: string;
E
Erich Gamma 已提交
444 445
}

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
/**
 * Represents the signature of something callable. A signature
 * can have a label, like a function-name, a doc-comment, and
 * a set of parameters.
 */
export interface SignatureInformation {

	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
	label: string;

	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
	documentation: string;

	/**
	 * The parameters of this signature.
	 */
	parameters: ParameterInformation[];
E
Erich Gamma 已提交
469 470
}

471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
/**
 * Signature help represents the signature of something
 * callable. There can be multiple signatures but only one
 * active and only one active parameter.
 */
export interface SignatureHelp {

	/**
	 * One or more signatures.
	 */
	signatures: SignatureInformation[];

	/**
	 * The active signature.
	 */
	activeSignature: number;

	/**
	 * The active parameter of the active signature.
	 */
	activeParameter: number;
E
Erich Gamma 已提交
492 493 494
}

/**
495 496
 * The signature help provider interface defines the contract between extensions and
 * the [parameter hints](https://code.visualstudio.com/docs/editor/editingevolved#_parameter-hints)-feature.
E
Erich Gamma 已提交
497 498
 */
export interface IParameterHintsSupport {
499 500 501 502 503 504 505 506 507 508 509 510 511

	parameterHintsTriggerCharacters: string[];

	/**
	 * Provide help for the signature at the given position and document.
	 *
	 * @param document The document in which the command was invoked.
	 * @param position The position at which the command was invoked.
	 * @param token A cancellation token.
	 * @return Signature help or a thenable that resolves to such. The lack of a result can be
	 * signaled by returning `undefined` or `null`.
	 */
	provideSignatureHelp(model: editorCommon.IModel, position: editorCommon.IEditorPosition, token: CancellationToken): SignatureHelp | Thenable<SignatureHelp>;
E
Erich Gamma 已提交
512 513 514 515
}


export interface IOccurence {
516 517
	kind?: 'write' | 'text' | string;
	range: editorCommon.IRange;
E
Erich Gamma 已提交
518 519 520 521 522 523
}

/**
 * Interface used to find occurrences of a symbol
 */
export interface IOccurrencesSupport {
A
Alex Dima 已提交
524
	findOccurrences(resource:URI, position:editorCommon.IPosition, strict?:boolean):TPromise<IOccurence[]>;
E
Erich Gamma 已提交
525 526 527 528 529 530 531 532
}


/**
 * Interface used to find declarations on a symbol
 */
export interface IReference {
	resource: URI;
A
Alex Dima 已提交
533
	range: editorCommon.IRange;
E
Erich Gamma 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
}

/**
 * Interface used to find references to a symbol
 */
export interface IReferenceSupport {

	/**
	 * @returns true if on the given line (and its tokens) at the given
	 * 	offset reference search can be invoked.
	 */
	canFindReferences(context:ILineContext, offset:number):boolean;

	/**
	 * @returns a list of reference of the symbol at the position in the
	 * 	given resource.
	 */
A
Alex Dima 已提交
551
	findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean):TPromise<IReference[]>;
E
Erich Gamma 已提交
552 553 554 555 556 557 558
}

/**
 * Interface used to find declarations on a symbol
 */
export interface IDeclarationSupport {
	canFindDeclaration(context:ILineContext, offset:number):boolean;
A
Alex Dima 已提交
559
	findDeclaration(resource:URI, position:editorCommon.IPosition):TPromise<IReference|IReference[]>;
E
Erich Gamma 已提交
560 561 562 563 564 565 566 567 568 569
}

/**
 * Interface used to compute an outline
 */
export interface IOutlineEntry {
	label: string;
	containerLabel?: string;
	type: string;
	icon?: string; // icon class or null to use the default images based on the type
A
Alex Dima 已提交
570
	range: editorCommon.IRange;
E
Erich Gamma 已提交
571 572 573 574
	children?: IOutlineEntry[];
}

export interface IOutlineSupport {
575
	getOutline(resource:URI):TPromise<IOutlineEntry[]>;
E
Erich Gamma 已提交
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
	outlineGroupLabel?: { [name: string]: string; };
}

/**
 * Interface used to format a model
 */
export interface IFormattingOptions {
	tabSize:number;
	insertSpaces:boolean;
}

/**
 * Supports to format source code. There are three levels
 * on which formatting can be offered:
 * (1) format a document
 * (2) format a selectin
 * (3) format on keystroke
 */
export interface IFormattingSupport {

A
Alex Dima 已提交
596
	formatDocument?: (resource: URI, options: IFormattingOptions) => TPromise<editorCommon.ISingleEditOperation[]>;
E
Erich Gamma 已提交
597

A
Alex Dima 已提交
598
	formatRange?: (resource: URI, range: editorCommon.IRange, options: IFormattingOptions) => TPromise<editorCommon.ISingleEditOperation[]>;
E
Erich Gamma 已提交
599 600 601

	autoFormatTriggerCharacters?: string[];

A
Alex Dima 已提交
602
	formatAfterKeystroke?: (resource: URI, position: editorCommon.IPosition, ch: string, options: IFormattingOptions) => TPromise<editorCommon.ISingleEditOperation[]>;
E
Erich Gamma 已提交
603 604 605 606
}

export interface IInplaceReplaceSupportResult {
	value: string;
A
Alex Dima 已提交
607
	range:editorCommon.IRange;
E
Erich Gamma 已提交
608 609 610 611 612 613
}

/**
 * Interface used to navigate with a value-set.
 */
export interface IInplaceReplaceSupport {
A
Alex Dima 已提交
614
	navigateValueSet(resource:URI, range:editorCommon.IRange, up:boolean):TPromise<IInplaceReplaceSupportResult>;
E
Erich Gamma 已提交
615 616 617 618 619 620
}

/**
 * Interface used to get output for a language that supports transformation (e.g. markdown -> html)
 */
export interface IEmitOutputSupport {
621
	getEmitOutput(resource:URI):TPromise<IEmitOutput>;
E
Erich Gamma 已提交
622 623 624 625 626 627 628 629 630 631 632 633
}

export interface IEmitOutput {
	filename?:string;
	content:string;
}

/**
 * Interface used to detect links.
 */
export interface ILink {

A
Alex Dima 已提交
634
	range: editorCommon.IRange;
E
Erich Gamma 已提交
635 636 637 638 639 640 641 642 643 644 645

	/**
	 * The url of the link.
	 * The url should be absolute and will not get any special treatment.
	 */
	url: string;

	extraInlineClassName?: string;
}

export interface ILinkSupport {
646
	computeLinks(resource:URI):TPromise<ILink[]>;
E
Erich Gamma 已提交
647 648 649 650 651 652
}

/**
 * Interface used to define a configurable editor mode.
 */
export interface IConfigurationSupport {
653
	configure(options:any):TPromise<void>;
E
Erich Gamma 已提交
654 655 656 657
}

export interface IResourceEdit {
	resource: URI;
A
Alex Dima 已提交
658
	range?: editorCommon.IRange;
E
Erich Gamma 已提交
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
	newText: string;
}

export interface IRenameResult {
	currentName: string;
	edits: IResourceEdit[];
	rejectReason?: string;
}

/**
 * Interface used to support renaming of symbols
 */
export interface IRenameSupport {

	filter?: string[];

A
Alex Dima 已提交
675
	rename(resource: URI, position: editorCommon.IPosition, newName: string): TPromise<IRenameResult>;
E
Erich Gamma 已提交
676 677 678 679 680 681 682 683 684
}

export interface ICommand {
	id: string;
	title: string;
	arguments?: any[];
}

export interface ICodeLensSymbol {
A
Alex Dima 已提交
685
	range: editorCommon.IRange;
E
Erich Gamma 已提交
686
	id?: string;
J
Johannes Rieken 已提交
687
	command?: ICommand;
E
Erich Gamma 已提交
688 689 690 691 692 693 694
}

/**
 * Interface used for the code lense support
 */
export interface ICodeLensSupport {
	findCodeLensSymbols(resource: URI): TPromise<ICodeLensSymbol[]>;
J
Johannes Rieken 已提交
695
	resolveCodeLensSymbol(resource: URI, symbol: ICodeLensSymbol): TPromise<ICodeLensSymbol>;
E
Erich Gamma 已提交
696 697 698 699 700 701 702 703 704 705 706 707 708 709
}

export interface ITaskSummary {
}

/**
 * Interface to support building via a langauge service
 */
export interface ITaskSupport {
	build?():TPromise<ITaskSummary>;
	rebuild?():TPromise<ITaskSummary>;
	clean?():TPromise<void>;
}

710 711
export type CharacterPair = [string, string];

E
Erich Gamma 已提交
712 713 714 715
export interface IAutoClosingPairConditional extends IAutoClosingPair {
	notIn?: string[];
}

716 717 718 719 720 721 722 723
/**
 * Interface used to support electric characters
 */
export interface IElectricAction {
	// Only one of the following properties should be defined:

	// The line will be indented at the same level of the line
	// which contains the matching given bracket type.
724
	matchOpenBracket?:string;
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755

	// The text will be appended after the electric character.
	appendText?:string;

	// The number of characters to advance the cursor, useful with appendText
	advanceCount?:number;
}

export enum IndentAction {
	None,
	Indent,
	IndentOutdent,
	Outdent
}

/**
 * An action the editor executes when 'enter' is being pressed
 */
export interface IEnterAction {
	indentAction:IndentAction;
	appendText?:string;
	removeText?:number;
}

export interface IRichEditElectricCharacter {
	getElectricCharacters():string[];
	// Should return opening bracket type to match indentation with
	onElectricCharacter(context:ILineContext, offset:number):IElectricAction;
}

export interface IRichEditOnEnter {
A
Alex Dima 已提交
756
	onEnter(model:editorCommon.ITokenizedModel, position: editorCommon.IPosition): IEnterAction;
757 758 759 760 761 762
}

/**
 * Interface used to support insertion of mode specific comments.
 */
export interface ICommentsConfiguration {
A
Alex Dima 已提交
763
	lineCommentToken?:string;
764 765 766 767 768
	blockCommentStartToken?:string;
	blockCommentEndToken?:string;
}

/**
769
 * Interface used to support insertion of matching characters like brackets and quotes.
770 771 772 773 774 775 776 777 778 779 780
 */
export interface IAutoClosingPair {
	open:string;
	close:string;
}
export interface IRichEditCharacterPair {
	getAutoClosingPairs():IAutoClosingPairConditional[];
	shouldAutoClosePair(character:string, context:ILineContext, offset:number):boolean;
	getSurroundingPairs():IAutoClosingPair[];
}

781 782 783 784
export interface IRichEditBrackets {
	maxBracketLength: number;
	forwardRegex: RegExp;
	reversedRegex: RegExp;
A
Alex Dima 已提交
785 786
	brackets: editorCommon.IRichEditBracket[];
	textIsBracket: {[text:string]:editorCommon.IRichEditBracket;};
787 788 789
	textIsOpenBracket: {[text:string]:boolean;};
}

790 791 792 793 794 795 796 797 798
export interface IRichEditSupport {
	/**
	 * Optional adapter for electric characters.
	 */
	electricCharacter?:IRichEditElectricCharacter;

	/**
	 * Optional adapter for comment insertion.
	 */
A
Alex Dima 已提交
799
	comments?:ICommentsConfiguration;
800 801 802 803 804 805 806 807 808

	/**
	 * Optional adapter for insertion of character pair.
	 */
	characterPair?:IRichEditCharacterPair;

	/**
	 * Optional adapter for classification of tokens.
	 */
809
	wordDefinition?: RegExp;
810 811 812 813 814

	/**
	 * Optional adapter for custom Enter handling.
	 */
	onEnter?: IRichEditOnEnter;
815 816 817 818 819

	/**
	 * Optional adapter for brackets.
	 */
	brackets?: IRichEditBrackets;
820
}
821 822 823 824

// --- feature registries ------

export const ReferenceSearchRegistry = new LanguageFeatureRegistry<IReferenceSupport>('referenceSupport');
825

A
Alex Dima 已提交
826
export const RenameRegistry = new LanguageFeatureRegistry<IRenameSupport>(null);
827

828 829
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>('suggestSupport');

A
Alex Dima 已提交
830
export const ParameterHintsRegistry = new LanguageFeatureRegistry<IParameterHintsSupport>(null);
831 832 833 834 835 836 837 838 839

export const ExtraInfoRegistry = new LanguageFeatureRegistry<IExtraInfoSupport>('extraInfoSupport');

export const OutlineRegistry = new LanguageFeatureRegistry<IOutlineSupport>('outlineSupport');

export const OccurrencesRegistry = new LanguageFeatureRegistry<IOccurrencesSupport>('occurrencesSupport');

export const DeclarationRegistry = new LanguageFeatureRegistry<IDeclarationSupport>('declarationSupport');

A
Alex Dima 已提交
840
export const CodeLensRegistry = new LanguageFeatureRegistry<ICodeLensSupport>(null);
841 842 843 844 845 846

export const QuickFixRegistry = new LanguageFeatureRegistry<IQuickFixSupport>('quickFixSupport');

export const FormatRegistry = new LanguageFeatureRegistry<IFormattingSupport>('formattingSupport');

export const FormatOnTypeRegistry = new LanguageFeatureRegistry<IFormattingSupport>('formattingSupport');