From 9f7ea0588dc74f3bdaea542bfdeb105aa7c4bc83 Mon Sep 17 00:00:00 2001 From: Benjamin Christopher Simmonds <44439583+benibenj@users.noreply.github.com> Date: Wed, 2 Jul 2025 14:45:45 +0200 Subject: [PATCH] Immediately snooze on pressing snooze (#253641) immidiately snooze when pressing snooze --- .../services/inlineCompletionsService.ts | 35 +++++++++++-------- .../controller/inlineCompletionsController.ts | 5 +-- .../browser/model/inlineCompletionsModel.ts | 10 +++++- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/vs/editor/browser/services/inlineCompletionsService.ts b/src/vs/editor/browser/services/inlineCompletionsService.ts index 0573984ea22..f060fbddfb2 100644 --- a/src/vs/editor/browser/services/inlineCompletionsService.ts +++ b/src/vs/editor/browser/services/inlineCompletionsService.ts @@ -83,26 +83,31 @@ export class InlineCompletionsService extends Disposable implements IInlineCompl } setSnoozeDuration(durationMs: number): void { + if (durationMs < 0) { + throw new BugIndicatingError(`Invalid snooze duration: ${durationMs}. Duration must be non-negative.`); + } + if (durationMs === 0) { + this.cancelSnooze(); + return; + } + const wasSnoozing = this.isSnoozing(); this._snoozeTimeEnd = Date.now() + durationMs; - const isSnoozing = this.isSnoozing(); - if (wasSnoozing !== isSnoozing) { - this._onDidChangeIsSnoozing.fire(isSnoozing); + if (!wasSnoozing) { + this._onDidChangeIsSnoozing.fire(true); } - if (isSnoozing) { - this._timer.cancelAndSet( - () => { - if (!this.isSnoozing()) { - this._onDidChangeIsSnoozing.fire(false); - } else { - throw new BugIndicatingError('Snooze timer did not fire as expected'); - } - }, - this.snoozeTimeLeft + 1, - ); - } + this._timer.cancelAndSet( + () => { + if (!this.isSnoozing()) { + this._onDidChangeIsSnoozing.fire(false); + } else { + throw new BugIndicatingError('Snooze timer did not fire as expected'); + } + }, + this.snoozeTimeLeft + 1, + ); } isSnoozing(): boolean { diff --git a/src/vs/editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.ts b/src/vs/editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.ts index 0ae14aef6d5..7aab79fce9c 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.ts @@ -37,7 +37,6 @@ import { ObservableContextKeyService } from '../utils.js'; import { InlineCompletionsView } from '../view/inlineCompletionsView.js'; import { inlineSuggestCommitId } from './commandIds.js'; import { InlineCompletionContextKeys } from './inlineCompletionContextKeys.js'; -import { IInlineCompletionsService } from '../../../../browser/services/inlineCompletionsService.js'; export class InlineCompletionsController extends Disposable { private static readonly _instances = new Set(); @@ -96,7 +95,6 @@ export class InlineCompletionsController extends Disposable { @IAccessibilitySignalService private readonly _accessibilitySignalService: IAccessibilitySignalService, @IKeybindingService private readonly _keybindingService: IKeybindingService, @IAccessibilityService private readonly _accessibilityService: IAccessibilityService, - @IInlineCompletionsService private readonly _inlineCompletionsService: IInlineCompletionsService, ) { super(); this._editorObs = observableCodeEditor(this.editor); @@ -112,8 +110,7 @@ export class InlineCompletionsController extends Disposable { this._contextKeyService.onDidChangeContext, () => this._contextKeyService.getContext(this.editor.getDomNode()).getValue('editorDictation.inProgress') === true ); - const isSnoozing = observableFromEvent(this, this._inlineCompletionsService.onDidChangeIsSnoozing, () => this._inlineCompletionsService.isSnoozing()); - this._enabled = derived(this, reader => this._enabledInConfig.read(reader) && !isSnoozing.read(reader) && (!this._isScreenReaderEnabled.read(reader) || !this._editorDictationInProgress.read(reader))); + this._enabled = derived(this, reader => this._enabledInConfig.read(reader) && (!this._isScreenReaderEnabled.read(reader) || !this._editorDictationInProgress.read(reader))); this._debounceValue = this._debounceService.for( this._languageFeaturesService.inlineCompletionsProvider, 'InlineCompletionsDebounce', diff --git a/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts b/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts index 964b23884c8..ad4f401d00a 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts @@ -46,6 +46,7 @@ import { SuggestItemInfo } from './suggestWidgetAdapter.js'; import { TextModelEditReason, EditReasons } from '../../../../common/textModelEditReason.js'; import { ICodeEditorService } from '../../../../browser/services/codeEditorService.js'; import { InlineCompletionViewData, InlineCompletionViewKind } from '../view/inlineEdits/inlineEditsViewInterface.js'; +import { IInlineCompletionsService } from '../../../../browser/services/inlineCompletionsService.js'; export class InlineCompletionsModel extends Disposable { private readonly _source; @@ -90,6 +91,7 @@ export class InlineCompletionsModel extends Disposable { @IAccessibilityService private readonly _accessibilityService: IAccessibilityService, @ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService, @ICodeEditorService private readonly _codeEditorService: ICodeEditorService, + @IInlineCompletionsService inlineCompletionsService: IInlineCompletionsService ) { super(); this.primaryPosition = derived(this, reader => this._positions.read(reader)[0] ?? new Position(1, 1)); @@ -111,6 +113,11 @@ export class InlineCompletionsModel extends Disposable { this._inlineEditsEnabled = this._editorObs.getOption(EditorOption.inlineSuggest).map(v => !!v.edits.enabled); this._inlineEditsShowCollapsedEnabled = this._editorObs.getOption(EditorOption.inlineSuggest).map(s => s.edits.showCollapsed); this._triggerCommandOnProviderChange = this._editorObs.getOption(EditorOption.inlineSuggest).map(s => s.experimental.triggerCommandOnProviderChange); + this._register(inlineCompletionsService.onDidChangeIsSnoozing((isSnoozing) => { + if (isSnoozing) { + this.stop(); + } + })); this._lastShownInlineCompletionInfo = undefined; this._lastAcceptedInlineCompletionInfo = undefined; @@ -183,7 +190,8 @@ export class InlineCompletionsModel extends Disposable { this._onlyRequestInlineEditsSignal.read(reader); this._forceUpdateExplicitlySignal.read(reader); this._fetchSpecificProviderSignal.read(reader); - const shouldUpdate = (this._enabled.read(reader) && this._selectedSuggestItem.read(reader)) || this._isActive.read(reader); + const shouldUpdate = ((this._enabled.read(reader) && this._selectedSuggestItem.read(reader)) || this._isActive.read(reader)) + && (!inlineCompletionsService.isSnoozing() || changeSummary.inlineCompletionTriggerKind === InlineCompletionTriggerKind.Explicit); if (!shouldUpdate) { this._source.cancelUpdate(); return undefined;