Skip to content

Commit 9f7ea05

Browse files
authored
Immediately snooze on pressing snooze (microsoft#253641)
immidiately snooze when pressing snooze
1 parent d63c9dd commit 9f7ea05

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,31 @@ export class InlineCompletionsService extends Disposable implements IInlineCompl
8383
}
8484

8585
setSnoozeDuration(durationMs: number): void {
86+
if (durationMs < 0) {
87+
throw new BugIndicatingError(`Invalid snooze duration: ${durationMs}. Duration must be non-negative.`);
88+
}
89+
if (durationMs === 0) {
90+
this.cancelSnooze();
91+
return;
92+
}
93+
8694
const wasSnoozing = this.isSnoozing();
8795
this._snoozeTimeEnd = Date.now() + durationMs;
88-
const isSnoozing = this.isSnoozing();
8996

90-
if (wasSnoozing !== isSnoozing) {
91-
this._onDidChangeIsSnoozing.fire(isSnoozing);
97+
if (!wasSnoozing) {
98+
this._onDidChangeIsSnoozing.fire(true);
9299
}
93100

94-
if (isSnoozing) {
95-
this._timer.cancelAndSet(
96-
() => {
97-
if (!this.isSnoozing()) {
98-
this._onDidChangeIsSnoozing.fire(false);
99-
} else {
100-
throw new BugIndicatingError('Snooze timer did not fire as expected');
101-
}
102-
},
103-
this.snoozeTimeLeft + 1,
104-
);
105-
}
101+
this._timer.cancelAndSet(
102+
() => {
103+
if (!this.isSnoozing()) {
104+
this._onDidChangeIsSnoozing.fire(false);
105+
} else {
106+
throw new BugIndicatingError('Snooze timer did not fire as expected');
107+
}
108+
},
109+
this.snoozeTimeLeft + 1,
110+
);
106111
}
107112

108113
isSnoozing(): boolean {

src/vs/editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { ObservableContextKeyService } from '../utils.js';
3737
import { InlineCompletionsView } from '../view/inlineCompletionsView.js';
3838
import { inlineSuggestCommitId } from './commandIds.js';
3939
import { InlineCompletionContextKeys } from './inlineCompletionContextKeys.js';
40-
import { IInlineCompletionsService } from '../../../../browser/services/inlineCompletionsService.js';
4140

4241
export class InlineCompletionsController extends Disposable {
4342
private static readonly _instances = new Set<InlineCompletionsController>();
@@ -96,7 +95,6 @@ export class InlineCompletionsController extends Disposable {
9695
@IAccessibilitySignalService private readonly _accessibilitySignalService: IAccessibilitySignalService,
9796
@IKeybindingService private readonly _keybindingService: IKeybindingService,
9897
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
99-
@IInlineCompletionsService private readonly _inlineCompletionsService: IInlineCompletionsService,
10098
) {
10199
super();
102100
this._editorObs = observableCodeEditor(this.editor);
@@ -112,8 +110,7 @@ export class InlineCompletionsController extends Disposable {
112110
this._contextKeyService.onDidChangeContext,
113111
() => this._contextKeyService.getContext(this.editor.getDomNode()).getValue('editorDictation.inProgress') === true
114112
);
115-
const isSnoozing = observableFromEvent(this, this._inlineCompletionsService.onDidChangeIsSnoozing, () => this._inlineCompletionsService.isSnoozing());
116-
this._enabled = derived(this, reader => this._enabledInConfig.read(reader) && !isSnoozing.read(reader) && (!this._isScreenReaderEnabled.read(reader) || !this._editorDictationInProgress.read(reader)));
113+
this._enabled = derived(this, reader => this._enabledInConfig.read(reader) && (!this._isScreenReaderEnabled.read(reader) || !this._editorDictationInProgress.read(reader)));
117114
this._debounceValue = this._debounceService.for(
118115
this._languageFeaturesService.inlineCompletionsProvider,
119116
'InlineCompletionsDebounce',

src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { SuggestItemInfo } from './suggestWidgetAdapter.js';
4646
import { TextModelEditReason, EditReasons } from '../../../../common/textModelEditReason.js';
4747
import { ICodeEditorService } from '../../../../browser/services/codeEditorService.js';
4848
import { InlineCompletionViewData, InlineCompletionViewKind } from '../view/inlineEdits/inlineEditsViewInterface.js';
49+
import { IInlineCompletionsService } from '../../../../browser/services/inlineCompletionsService.js';
4950

5051
export class InlineCompletionsModel extends Disposable {
5152
private readonly _source;
@@ -90,6 +91,7 @@ export class InlineCompletionsModel extends Disposable {
9091
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
9192
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService,
9293
@ICodeEditorService private readonly _codeEditorService: ICodeEditorService,
94+
@IInlineCompletionsService inlineCompletionsService: IInlineCompletionsService
9395
) {
9496
super();
9597
this.primaryPosition = derived(this, reader => this._positions.read(reader)[0] ?? new Position(1, 1));
@@ -111,6 +113,11 @@ export class InlineCompletionsModel extends Disposable {
111113
this._inlineEditsEnabled = this._editorObs.getOption(EditorOption.inlineSuggest).map(v => !!v.edits.enabled);
112114
this._inlineEditsShowCollapsedEnabled = this._editorObs.getOption(EditorOption.inlineSuggest).map(s => s.edits.showCollapsed);
113115
this._triggerCommandOnProviderChange = this._editorObs.getOption(EditorOption.inlineSuggest).map(s => s.experimental.triggerCommandOnProviderChange);
116+
this._register(inlineCompletionsService.onDidChangeIsSnoozing((isSnoozing) => {
117+
if (isSnoozing) {
118+
this.stop();
119+
}
120+
}));
114121

115122
this._lastShownInlineCompletionInfo = undefined;
116123
this._lastAcceptedInlineCompletionInfo = undefined;
@@ -183,7 +190,8 @@ export class InlineCompletionsModel extends Disposable {
183190
this._onlyRequestInlineEditsSignal.read(reader);
184191
this._forceUpdateExplicitlySignal.read(reader);
185192
this._fetchSpecificProviderSignal.read(reader);
186-
const shouldUpdate = (this._enabled.read(reader) && this._selectedSuggestItem.read(reader)) || this._isActive.read(reader);
193+
const shouldUpdate = ((this._enabled.read(reader) && this._selectedSuggestItem.read(reader)) || this._isActive.read(reader))
194+
&& (!inlineCompletionsService.isSnoozing() || changeSummary.inlineCompletionTriggerKind === InlineCompletionTriggerKind.Explicit);
187195
if (!shouldUpdate) {
188196
this._source.cancelUpdate();
189197
return undefined;

0 commit comments

Comments
 (0)