Skip to content

Commit 26325e8

Browse files
authored
Fix broken snooze feature (microsoft#253349)
fix broken snooze feature
1 parent 3fe16b2 commit 26325e8

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

src/vs/editor/browser/services/inlineCompletionsService.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ContextKeyExpr, IContextKeyService, RawContextKey } from '../../../plat
1313
import { InstantiationType, registerSingleton } from '../../../platform/instantiation/common/extensions.js';
1414
import { createDecorator, ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js';
1515
import { IQuickInputService, IQuickPickItem } from '../../../platform/quickinput/common/quickInput.js';
16+
import { IStorageService, StorageScope, StorageTarget } from '../../../platform/storage/common/storage.js';
1617

1718
export const IInlineCompletionsService = createDecorator<IInlineCompletionsService>('IInlineCompletionsService');
1819

@@ -83,16 +84,9 @@ export class InlineCompletionsService extends Disposable implements IInlineCompl
8384

8485
setSnoozeDuration(durationMs: number): void {
8586
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;
9588
const isSnoozing = this.isSnoozing();
89+
9690
if (wasSnoozing !== isSnoozing) {
9791
this._onDidChangeIsSnoozing.fire(isSnoozing);
9892
}
@@ -128,6 +122,7 @@ registerSingleton(IInlineCompletionsService, InlineCompletionsService, Instantia
128122

129123
const snoozeInlineSuggestId = 'editor.action.inlineSuggest.snooze';
130124
const cancelSnoozeInlineSuggestId = 'editor.action.inlineSuggest.cancelSnooze';
125+
const LAST_SNOOZE_DURATION_KEY = 'inlineCompletions.lastSnoozeDuration';
131126

132127
export class SnoozeInlineCompletion extends Action2 {
133128
public static ID = snoozeInlineSuggestId;
@@ -140,27 +135,48 @@ export class SnoozeInlineCompletion extends Action2 {
140135
});
141136
}
142137

143-
public async run(accessor: ServicesAccessor): Promise<void> {
138+
public async run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void> {
144139
const quickInputService = accessor.get(IQuickInputService);
145140
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+
}
146147

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 }
153167
];
154168

155169
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),
157172
});
158173

159174
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;
163177
}
178+
179+
return undefined;
164180
}
165181
}
166182

0 commit comments

Comments
 (0)