@@ -13,6 +13,7 @@ import { ContextKeyExpr, IContextKeyService, RawContextKey } from '../../../plat
13
13
import { InstantiationType , registerSingleton } from '../../../platform/instantiation/common/extensions.js' ;
14
14
import { createDecorator , ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js' ;
15
15
import { IQuickInputService , IQuickPickItem } from '../../../platform/quickinput/common/quickInput.js' ;
16
+ import { IStorageService , StorageScope , StorageTarget } from '../../../platform/storage/common/storage.js' ;
16
17
17
18
export const IInlineCompletionsService = createDecorator < IInlineCompletionsService > ( 'IInlineCompletionsService' ) ;
18
19
@@ -83,16 +84,9 @@ export class InlineCompletionsService extends Disposable implements IInlineCompl
83
84
84
85
setSnoozeDuration ( durationMs : number ) : void {
85
86
const wasSnoozing = this . isSnoozing ( ) ;
86
-
87
- if ( this . _snoozeTimeEnd === undefined ) {
88
- this . _snoozeTimeEnd = Date . now ( ) + durationMs ;
89
- } else if ( this . snoozeTimeLeft > 0 ) {
90
- this . _snoozeTimeEnd += durationMs ;
91
- } else {
92
- this . _snoozeTimeEnd = Date . now ( ) + durationMs ;
93
- }
94
-
87
+ this . _snoozeTimeEnd = Date . now ( ) + durationMs ;
95
88
const isSnoozing = this . isSnoozing ( ) ;
89
+
96
90
if ( wasSnoozing !== isSnoozing ) {
97
91
this . _onDidChangeIsSnoozing . fire ( isSnoozing ) ;
98
92
}
@@ -128,6 +122,7 @@ registerSingleton(IInlineCompletionsService, InlineCompletionsService, Instantia
128
122
129
123
const snoozeInlineSuggestId = 'editor.action.inlineSuggest.snooze' ;
130
124
const cancelSnoozeInlineSuggestId = 'editor.action.inlineSuggest.cancelSnooze' ;
125
+ const LAST_SNOOZE_DURATION_KEY = 'inlineCompletions.lastSnoozeDuration' ;
131
126
132
127
export class SnoozeInlineCompletion extends Action2 {
133
128
public static ID = snoozeInlineSuggestId ;
@@ -140,27 +135,48 @@ export class SnoozeInlineCompletion extends Action2 {
140
135
} ) ;
141
136
}
142
137
143
- public async run ( accessor : ServicesAccessor ) : Promise < void > {
138
+ public async run ( accessor : ServicesAccessor , ... args : unknown [ ] ) : Promise < void > {
144
139
const quickInputService = accessor . get ( IQuickInputService ) ;
145
140
const inlineCompletionsService = accessor . get ( IInlineCompletionsService ) ;
141
+ const storageService = accessor . get ( IStorageService ) ;
142
+
143
+ let durationMinutes : number | undefined ;
144
+ if ( args . length > 0 && typeof args [ 0 ] === 'number' ) {
145
+ durationMinutes = args [ 0 ] ;
146
+ }
146
147
147
- const items : IQuickPickItem [ ] = [
148
- { label : '5 minutes' , id : '5' , picked : true } ,
149
- { label : '10 minutes' , id : '10' } ,
150
- { label : '15 minutes' , id : '15' } ,
151
- { label : '30 minutes' , id : '30' } ,
152
- { label : '60 minutes' , id : '60' }
148
+ if ( ! durationMinutes ) {
149
+ durationMinutes = await this . getDurationFromUser ( quickInputService , storageService ) ;
150
+ }
151
+
152
+ if ( durationMinutes ) {
153
+ inlineCompletionsService . setSnoozeDuration ( durationMinutes ) ;
154
+ }
155
+ }
156
+
157
+ private async getDurationFromUser ( quickInputService : IQuickInputService , storageService : IStorageService ) : Promise < number | undefined > {
158
+ const lastSelectedDuration = storageService . getNumber ( LAST_SNOOZE_DURATION_KEY , StorageScope . PROFILE , 300_000 ) ;
159
+
160
+ const items : ( IQuickPickItem & { value : number } ) [ ] = [
161
+ { label : '1 minute' , id : '1' , value : 60_000 } ,
162
+ { label : '5 minutes' , id : '5' , value : 300_000 } ,
163
+ { label : '10 minutes' , id : '10' , value : 600_000 } ,
164
+ { label : '15 minutes' , id : '15' , value : 900_000 } ,
165
+ { label : '30 minutes' , id : '30' , value : 1_800_000 } ,
166
+ { label : '60 minutes' , id : '60' , value : 3_600_000 }
153
167
] ;
154
168
155
169
const picked = await quickInputService . pick ( items , {
156
- placeHolder : localize ( 'snooze.placeholder' , "Select snooze duration" )
170
+ placeHolder : localize ( 'snooze.placeholder' , "Select snooze duration for Code completions and NES" ) ,
171
+ activeItem : items . find ( item => item . value === lastSelectedDuration ) ,
157
172
} ) ;
158
173
159
174
if ( picked ) {
160
- const minutes = parseInt ( picked . id ! , 10 ) ;
161
- const durationMs = minutes * 60 * 1000 ;
162
- inlineCompletionsService . setSnoozeDuration ( durationMs ) ;
175
+ storageService . store ( LAST_SNOOZE_DURATION_KEY , picked . value , StorageScope . PROFILE , StorageTarget . USER ) ;
176
+ return picked . value ;
163
177
}
178
+
179
+ return undefined ;
164
180
}
165
181
}
166
182
0 commit comments