@@ -7,7 +7,7 @@ import { alert } from 'vs/base/browser/ui/aria/aria';
77import { isNonEmptyArray } from 'vs/base/common/arrays' ;
88import { onUnexpectedError } from 'vs/base/common/errors' ;
99import { KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
10- import { dispose , IDisposable } from 'vs/base/common/lifecycle' ;
10+ import { dispose , IDisposable , DisposableStore , toDisposable } from 'vs/base/common/lifecycle' ;
1111import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
1212import { EditorAction , EditorCommand , registerEditorAction , registerEditorCommand , registerEditorContribution , ServicesAccessor } from 'vs/editor/browser/editorExtensions' ;
1313import { EditOperation } from 'vs/editor/common/core/editOperation' ;
@@ -45,7 +45,7 @@ export class SuggestController implements IEditorContribution {
4545 private readonly _model : SuggestModel ;
4646 private readonly _widget : IdleValue < SuggestWidget > ;
4747 private readonly _alternatives : IdleValue < SuggestAlternatives > ;
48- private _toDispose : IDisposable [ ] = [ ] ;
48+ private readonly _toDispose = new DisposableStore ( ) ;
4949
5050 private readonly _sticky = false ; // for development purposes only
5151
@@ -63,23 +63,21 @@ export class SuggestController implements IEditorContribution {
6363
6464 const widget = this . _instantiationService . createInstance ( SuggestWidget , this . _editor ) ;
6565
66- this . _toDispose . push ( widget ) ;
67- this . _toDispose . push ( widget . onDidSelect ( item => this . _insertSuggestion ( item , false , true ) , this ) ) ;
66+ this . _toDispose . add ( widget ) ;
67+ this . _toDispose . add ( widget . onDidSelect ( item => this . _insertSuggestion ( item , false , true ) , this ) ) ;
6868
6969 // Wire up logic to accept a suggestion on certain characters
7070 const commitCharacterController = new CommitCharacterController ( this . _editor , widget , item => this . _insertSuggestion ( item , false , true ) ) ;
71- this . _toDispose . push (
72- commitCharacterController ,
73- this . _model . onDidSuggest ( e => {
74- if ( e . completionModel . items . length === 0 ) {
75- commitCharacterController . reset ( ) ;
76- }
77- } )
78- ) ;
71+ this . _toDispose . add ( commitCharacterController ) ;
72+ this . _toDispose . add ( this . _model . onDidSuggest ( e => {
73+ if ( e . completionModel . items . length === 0 ) {
74+ commitCharacterController . reset ( ) ;
75+ }
76+ } ) ) ;
7977
8078 // Wire up makes text edit context key
8179 let makesTextEdit = SuggestContext . MakesTextEdit . bindTo ( this . _contextKeyService ) ;
82- this . _toDispose . push ( widget . onDidFocus ( ( { item } ) => {
80+ this . _toDispose . add ( widget . onDidFocus ( ( { item } ) => {
8381
8482 const position = this . _editor . getPosition ( ) ! ;
8583 const startColumn = item . completion . range . startColumn ;
@@ -103,36 +101,32 @@ export class SuggestController implements IEditorContribution {
103101 }
104102 makesTextEdit . set ( value ) ;
105103 } ) ) ;
106- this . _toDispose . push ( {
107- dispose ( ) { makesTextEdit . reset ( ) ; }
108- } ) ;
104+ this . _toDispose . add ( toDisposable ( ( ) => makesTextEdit . reset ( ) ) ) ;
109105
110106 return widget ;
111107 } ) ;
112108
113109 this . _alternatives = new IdleValue ( ( ) => {
114- let res = new SuggestAlternatives ( this . _editor , this . _contextKeyService ) ;
115- this . _toDispose . push ( res ) ;
116- return res ;
110+ return this . _toDispose . add ( new SuggestAlternatives ( this . _editor , this . _contextKeyService ) ) ;
117111 } ) ;
118112
119- this . _toDispose . push ( _instantiationService . createInstance ( WordContextKey , _editor ) ) ;
113+ this . _toDispose . add ( _instantiationService . createInstance ( WordContextKey , _editor ) ) ;
120114
121- this . _toDispose . push ( this . _model . onDidTrigger ( e => {
115+ this . _toDispose . add ( this . _model . onDidTrigger ( e => {
122116 this . _widget . getValue ( ) . showTriggered ( e . auto , e . shy ? 250 : 50 ) ;
123117 } ) ) ;
124- this . _toDispose . push ( this . _model . onDidSuggest ( e => {
118+ this . _toDispose . add ( this . _model . onDidSuggest ( e => {
125119 if ( ! e . shy ) {
126120 let index = this . _memoryService . select ( this . _editor . getModel ( ) ! , this . _editor . getPosition ( ) ! , e . completionModel . items ) ;
127121 this . _widget . getValue ( ) . showSuggestions ( e . completionModel , index , e . isFrozen , e . auto ) ;
128122 }
129123 } ) ) ;
130- this . _toDispose . push ( this . _model . onDidCancel ( e => {
124+ this . _toDispose . add ( this . _model . onDidCancel ( e => {
131125 if ( this . _widget && ! e . retrigger ) {
132126 this . _widget . getValue ( ) . hideWidget ( ) ;
133127 }
134128 } ) ) ;
135- this . _toDispose . push ( this . _editor . onDidBlurEditorWidget ( ( ) => {
129+ this . _toDispose . add ( this . _editor . onDidBlurEditorWidget ( ( ) => {
136130 if ( ! this . _sticky ) {
137131 this . _model . cancel ( ) ;
138132 this . _model . clear ( ) ;
@@ -145,7 +139,7 @@ export class SuggestController implements IEditorContribution {
145139 const { acceptSuggestionOnEnter } = this . _editor . getConfiguration ( ) . contribInfo ;
146140 acceptSuggestionsOnEnter . set ( acceptSuggestionOnEnter === 'on' || acceptSuggestionOnEnter === 'smart' ) ;
147141 } ;
148- this . _toDispose . push ( this . _editor . onDidChangeConfiguration ( ( e ) => updateFromConfig ( ) ) ) ;
142+ this . _toDispose . add ( this . _editor . onDidChangeConfiguration ( ( e ) => updateFromConfig ( ) ) ) ;
149143 updateFromConfig ( ) ;
150144 }
151145
@@ -155,7 +149,7 @@ export class SuggestController implements IEditorContribution {
155149 }
156150
157151 dispose ( ) : void {
158- this . _toDispose = dispose ( this . _toDispose ) ;
152+ this . _toDispose . dispose ( ) ;
159153 this . _widget . dispose ( ) ;
160154 if ( this . _model ) {
161155 this . _model . dispose ( ) ;
0 commit comments