@@ -25,7 +25,7 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2
2525import { Context as SuggestContext } from './suggest' ;
2626import { SuggestModel , State } from './suggestModel' ;
2727import { ICompletionItem } from './completionModel' ;
28- import { SuggestWidget } from './suggestWidget' ;
28+ import { SuggestWidget , ISelectedSuggestion } from './suggestWidget' ;
2929import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
3030import { SuggestMemories } from 'vs/editor/contrib/suggest/suggestMemory' ;
3131
@@ -34,9 +34,9 @@ class AcceptOnCharacterOracle {
3434 private _disposables : IDisposable [ ] = [ ] ;
3535
3636 private _activeAcceptCharacters = new Set < string > ( ) ;
37- private _activeItem : ICompletionItem ;
37+ private _activeItem : ISelectedSuggestion ;
3838
39- constructor ( editor : ICodeEditor , widget : SuggestWidget , accept : ( item : ICompletionItem ) => any ) {
39+ constructor ( editor : ICodeEditor , widget : SuggestWidget , accept : ( selected : ISelectedSuggestion ) => any ) {
4040
4141 this . _disposables . push ( widget . onDidShow ( ( ) => this . _onItem ( widget . getFocusedItem ( ) ) ) ) ;
4242 this . _disposables . push ( widget . onDidFocus ( this . _onItem , this ) ) ;
@@ -52,14 +52,14 @@ class AcceptOnCharacterOracle {
5252 } ) ) ;
5353 }
5454
55- private _onItem ( item : ICompletionItem ) : void {
56- if ( ! item || isFalsyOrEmpty ( item . suggestion . commitCharacters ) ) {
55+ private _onItem ( selected : ISelectedSuggestion ) : void {
56+ if ( ! selected || isFalsyOrEmpty ( selected . item . suggestion . commitCharacters ) ) {
5757 this . reset ( ) ;
5858 return ;
5959 }
60- this . _activeItem = item ;
60+ this . _activeItem = selected ;
6161 this . _activeAcceptCharacters . clear ( ) ;
62- for ( const ch of item . suggestion . commitCharacters ) {
62+ for ( const ch of selected . item . suggestion . commitCharacters ) {
6363 if ( ch . length > 0 ) {
6464 this . _activeAcceptCharacters . add ( ch [ 0 ] ) ;
6565 }
@@ -148,7 +148,7 @@ export class SuggestController implements IEditorContribution {
148148 ) ;
149149
150150 let makesTextEdit = SuggestContext . MakesTextEdit . bindTo ( this . _contextKeyService ) ;
151- this . _toDispose . push ( this . _widget . onDidFocus ( item => {
151+ this . _toDispose . push ( this . _widget . onDidFocus ( ( { item } ) => {
152152
153153 const position = this . _editor . getPosition ( ) ;
154154 const startColumn = item . position . column - item . suggestion . overwriteBefore ;
@@ -193,13 +193,13 @@ export class SuggestController implements IEditorContribution {
193193 }
194194 }
195195
196- protected _onDidSelectItem ( item : ICompletionItem ) : void {
197- if ( ! item ) {
196+ protected _onDidSelectItem ( event : ISelectedSuggestion ) : void {
197+ if ( ! event . item ) {
198198 this . _model . cancel ( ) ;
199199 return ;
200200 }
201201
202- const { suggestion, position } = item ;
202+ const { suggestion, position } = event . item ;
203203 const editorColumn = this . _editor . getPosition ( ) . column ;
204204 const columnDelta = editorColumn - position . column ;
205205
@@ -209,8 +209,12 @@ export class SuggestController implements IEditorContribution {
209209 this . _editor . pushUndoStop ( ) ;
210210 }
211211
212- // remember this word for future invocations
213- this . _memory . remember ( this . _editor . getModel ( ) . getLanguageIdentifier ( ) , item ) ;
212+ // remember this suggestion for future invocations
213+ // when it wasn't the first suggestion but from the group
214+ // of top suggestions (cons -> const, console, constructor)
215+ if ( event . model . items [ 0 ] . score === event . item . score ) {
216+ this . _memory . remember ( this . _editor . getModel ( ) . getLanguageIdentifier ( ) , event . item ) ;
217+ }
214218
215219 let { insertText } = suggestion ;
216220 if ( suggestion . snippetType !== 'textmate' ) {
@@ -237,7 +241,7 @@ export class SuggestController implements IEditorContribution {
237241 this . _model . cancel ( ) ;
238242 }
239243
240- this . _alertCompletionItem ( item ) ;
244+ this . _alertCompletionItem ( event . item ) ;
241245 }
242246
243247 private _alertCompletionItem ( { suggestion } : ICompletionItem ) : void {
0 commit comments