33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { onUnexpectedError } from 'vs/base/common/errors' ;
76import { Emitter , Event } from 'vs/base/common/event' ;
87import { IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
98import * as strings from 'vs/base/common/strings' ;
@@ -17,7 +16,7 @@ import { createScopedLineTokens, ScopedLineTokens } from 'vs/editor/common/modes
1716import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair' ;
1817import { BracketElectricCharacterSupport , IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter' ;
1918import { IndentConsts , IndentRulesSupport } from 'vs/editor/common/modes/supports/indentRules' ;
20- import { IOnEnterSupportOptions , OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter' ;
19+ import { OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter' ;
2120import { RichEditBrackets } from 'vs/editor/common/modes/supports/richEditBrackets' ;
2221import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions' ;
2322
@@ -49,11 +48,11 @@ export class RichEditSupport {
4948 private readonly _languageIdentifier : LanguageIdentifier ;
5049 private _brackets : RichEditBrackets | null ;
5150 private _electricCharacter : BracketElectricCharacterSupport | null ;
51+ private readonly _onEnterSupport : OnEnterSupport | null ;
5252
5353 public readonly comments : ICommentsConfiguration | null ;
5454 public readonly characterPair : CharacterPairSupport ;
5555 public readonly wordDefinition : RegExp ;
56- public readonly onEnter : OnEnterSupport | null ;
5756 public readonly indentRulesSupport : IndentRulesSupport | null ;
5857 public readonly indentationRules : IndentationRule | undefined ;
5958 public readonly foldingRules : FoldingRules ;
@@ -71,8 +70,7 @@ export class RichEditSupport {
7170
7271 this . _conf = RichEditSupport . _mergeConf ( prev , rawConf ) ;
7372
74- this . onEnter = RichEditSupport . _handleOnEnter ( this . _conf ) ;
75-
73+ this . _onEnterSupport = ( this . _conf . brackets || this . _conf . indentationRules || this . _conf . onEnterRules ? new OnEnterSupport ( this . _conf ) : null ) ;
7674 this . comments = RichEditSupport . _handleComments ( this . _conf ) ;
7775
7876 this . characterPair = new CharacterPairSupport ( this . _conf ) ;
@@ -103,6 +101,13 @@ export class RichEditSupport {
103101 return this . _electricCharacter ;
104102 }
105103
104+ public onEnter ( autoIndent : EditorAutoIndentStrategy , oneLineAboveText : string , beforeEnterText : string , afterEnterText : string ) : EnterAction | null {
105+ if ( ! this . _onEnterSupport ) {
106+ return null ;
107+ }
108+ return this . _onEnterSupport . onEnter ( autoIndent , oneLineAboveText , beforeEnterText , afterEnterText ) ;
109+ }
110+
106111 private static _mergeConf ( prev : LanguageConfiguration | null , current : LanguageConfiguration ) : LanguageConfiguration {
107112 return {
108113 comments : ( prev ? current . comments || prev . comments : current . comments ) ,
@@ -118,29 +123,6 @@ export class RichEditSupport {
118123 } ;
119124 }
120125
121- private static _handleOnEnter ( conf : LanguageConfiguration ) : OnEnterSupport | null {
122- // on enter
123- let onEnter : IOnEnterSupportOptions = { } ;
124- let empty = true ;
125-
126- if ( conf . brackets ) {
127- empty = false ;
128- onEnter . brackets = conf . brackets ;
129- }
130- if ( conf . indentationRules ) {
131- empty = false ;
132- }
133- if ( conf . onEnterRules ) {
134- empty = false ;
135- onEnter . regExpRules = conf . onEnterRules ;
136- }
137-
138- if ( ! empty ) {
139- return new OnEnterSupport ( onEnter ) ;
140- }
141- return null ;
142- }
143-
144126 private static _handleComments ( conf : LanguageConfiguration ) : ICommentsConfiguration | null {
145127 let commentRule = conf . comments ;
146128 if ( ! commentRule ) {
@@ -481,6 +463,11 @@ export class LanguageConfigurationRegistryImpl {
481463 return null ;
482464 }
483465
466+ const richEditSupport = this . _getRichEditSupport ( languageId ) ;
467+ if ( ! richEditSupport ) {
468+ return null ;
469+ }
470+
484471 const indentRulesSupport = this . getIndentRulesSupport ( languageId ) ;
485472 if ( ! indentRulesSupport ) {
486473 return null ;
@@ -492,15 +479,7 @@ export class LanguageConfigurationRegistryImpl {
492479 if ( indent ) {
493480 const inheritLine = indent . line ;
494481 if ( inheritLine !== undefined ) {
495- const onEnterSupport = this . _getOnEnterSupport ( languageId ) ;
496- let enterResult : EnterAction | null = null ;
497- try {
498- if ( onEnterSupport ) {
499- enterResult = onEnterSupport . onEnter ( autoIndent , '' , virtualModel . getLineContent ( inheritLine ) , '' ) ;
500- }
501- } catch ( e ) {
502- onUnexpectedError ( e ) ;
503- }
482+ const enterResult = richEditSupport . onEnter ( autoIndent , '' , virtualModel . getLineContent ( inheritLine ) , '' ) ;
504483
505484 if ( enterResult ) {
506485 let indentation = strings . getLeadingWhitespace ( virtualModel . getLineContent ( inheritLine ) ) ;
@@ -689,18 +668,10 @@ export class LanguageConfigurationRegistryImpl {
689668
690669 // begin onEnter
691670
692- private _getOnEnterSupport ( languageId : LanguageId ) : OnEnterSupport | null {
693- const value = this . _getRichEditSupport ( languageId ) ;
694- if ( ! value ) {
695- return null ;
696- }
697- return value . onEnter || null ;
698- }
699-
700671 public getEnterAction ( autoIndent : EditorAutoIndentStrategy , model : ITextModel , range : Range ) : CompleteEnterAction | null {
701672 const scopedLineTokens = this . getScopedLineTokens ( model , range . startLineNumber , range . startColumn ) ;
702- const onEnterSupport = this . _getOnEnterSupport ( scopedLineTokens . languageId ) ;
703- if ( ! onEnterSupport ) {
673+ const richEditSupport = this . _getRichEditSupport ( scopedLineTokens . languageId ) ;
674+ if ( ! richEditSupport ) {
704675 return null ;
705676 }
706677
@@ -726,13 +697,7 @@ export class LanguageConfigurationRegistryImpl {
726697 }
727698 }
728699
729- let enterResult : EnterAction | null = null ;
730- try {
731- enterResult = onEnterSupport . onEnter ( autoIndent , oneLineAboveText , beforeEnterText , afterEnterText ) ;
732- } catch ( e ) {
733- onUnexpectedError ( e ) ;
734- }
735-
700+ const enterResult = richEditSupport . onEnter ( autoIndent , oneLineAboveText , beforeEnterText , afterEnterText ) ;
736701 if ( ! enterResult ) {
737702 return null ;
738703 }
0 commit comments