From d05ca61e59e8170f97e5bb6dd00b666bb7eb447e Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 3 Apr 2024 15:19:45 -0700 Subject: [PATCH] get it to work --- .../browser/inlineCompletionsController.ts | 21 ++++++++----------- .../browser/inlineCompletionsModel.ts | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController.ts b/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController.ts index 9c5fad4ba93..e7bbd1cbef9 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController.ts @@ -5,7 +5,6 @@ import { createStyleSheet2 } from 'vs/base/browser/dom'; import { alert } from 'vs/base/browser/ui/aria/aria'; -import { Event } from 'vs/base/common/event'; import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle'; import { IObservable, ITransaction, autorun, autorunHandleChanges, constObservable, derived, disposableObservableValue, observableFromEvent, observableSignal, observableValue, transaction } from 'vs/base/common/observable'; import { CoreEditingCommands } from 'vs/editor/browser/coreCommands'; @@ -34,7 +33,6 @@ import { mapObservableArrayCached } from 'vs/base/common/observableInternal/util import { ISettableObservable, observableValueOpts } from 'vs/base/common/observableInternal/base'; import { itemsEquals, itemEquals } from 'vs/base/common/equals'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; -import { ISpeechService } from 'vs/workbench/contrib/speech/common/speechService'; export class InlineCompletionsController extends Disposable { static ID = 'editor.contrib.inlineCompletionsController'; @@ -60,11 +58,10 @@ export class InlineCompletionsController extends Disposable { )); private readonly _enabled = observableFromEvent(this.editor.onDidChangeConfiguration, () => this.editor.getOption(EditorOption.inlineSuggest).enabled); private readonly _isScreenReaderEnabled = observableFromEvent(this._accessibilityService.onDidChangeScreenReaderOptimized, () => this._accessibilityService.isScreenReaderOptimized()); - private readonly _onDidChangeSpeechToTextSession = Event.any(this._speechService.onDidStartSpeechToTextSession, this._speechService.onDidEndSpeechToTextSession); - private readonly _voiceChatInProgress = observableFromEvent(this._onDidChangeSpeechToTextSession, () => this._speechService.hasActiveSpeechToTextSession); + private readonly _editorDictationInProgress = observableFromEvent(this._contextKeyService.onDidChangeContext, () => this._contextKeyService.getContext(this.editor.getDomNode()).getValue('editorDictation.inProgress') === true); private get _isEnabled(): boolean { - return this._enabled.get() && (!this._isScreenReaderEnabled.get() || !this._voiceChatInProgress.get()); + return this._enabled.get() && (!this._isScreenReaderEnabled.get() || !this._editorDictationInProgress.get()); } private readonly _fontFamily = observableFromEvent(this.editor.onDidChangeConfiguration, () => this.editor.getOption(EditorOption.inlineSuggest).fontFamily); @@ -107,7 +104,6 @@ export class InlineCompletionsController extends Disposable { @IAccessibilitySignalService private readonly _accessibilitySignalService: IAccessibilitySignalService, @IKeybindingService private readonly _keybindingService: IKeybindingService, @IAccessibilityService private readonly _accessibilityService: IAccessibilityService, - @ISpeechService private readonly _speechService: ISpeechService, ) { super(); @@ -134,7 +130,7 @@ export class InlineCompletionsController extends Disposable { observableFromEvent(editor.onDidChangeConfiguration, () => editor.getOption(EditorOption.inlineSuggest).mode), this._enabled, this._isScreenReaderEnabled, - this._voiceChatInProgress + this._editorDictationInProgress ); this.model.set(model, tx); } @@ -163,10 +159,12 @@ export class InlineCompletionsController extends Disposable { this.updateObservables(tx, getReason(e)) ))); - this._register(this._onDidChangeSpeechToTextSession(() => transaction(tx => { - /** @description speechService.onDidChangeSpeechToTextSession */ - this.updateObservables(tx, VersionIdChangeReason.Other); - this.model.get()?.stop(tx); + this._register(this._contextKeyService.onDidChangeContext((e) => transaction(tx => { + if (e.affectsSome(new Set('editorDictation.inProgress'))) { + /** @description speechService.onDidChangeSpeechToTextSession */ + this.updateObservables(tx, VersionIdChangeReason.Other); + this.model.get()?.stop(tx); + } }))); this._register(editor.onDidChangeCursorPosition(e => transaction(tx => { @@ -180,7 +178,6 @@ export class InlineCompletionsController extends Disposable { this._register(editor.onDidType(() => transaction(tx => { /** @description InlineCompletionsController.onDidType */ this.updateObservables(tx, VersionIdChangeReason.Other); - console.log('enabled', this._isEnabled); if (this._isEnabled) { this.model.get()?.trigger(tx); } diff --git a/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts b/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts index e18a044ea19..01b07c9de59 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts @@ -61,7 +61,7 @@ export class InlineCompletionsModel extends Disposable { private readonly _inlineSuggestMode: IObservable<'prefix' | 'subword' | 'subwordSmart'>, private readonly _enabled: IObservable, private readonly _isScreenReaderEnabled: IObservable, - private readonly _voiceChatInProgress: IObservable, + private readonly _editorDictationInProgress: IObservable, @IInstantiationService private readonly _instantiationService: IInstantiationService, @ICommandService private readonly _commandService: ICommandService, @ILanguageConfigurationService private readonly _languageConfigurationService: ILanguageConfigurationService, @@ -109,7 +109,7 @@ export class InlineCompletionsModel extends Disposable { }, }, (reader, changeSummary) => { this._forceUpdateExplicitlySignal.read(reader); - const shouldUpdate = (this._enabled.read(reader) && (!this._isScreenReaderEnabled.read(reader) || !this._voiceChatInProgress.read(reader)) && this.selectedSuggestItem.read(reader)) || this._isActive.read(reader); + const shouldUpdate = (this._enabled.read(reader) && (!this._isScreenReaderEnabled.read(reader) || !this._editorDictationInProgress.read(reader)) && this.selectedSuggestItem.read(reader)) || this._isActive.read(reader); if (!shouldUpdate) { this._source.cancelUpdate(); return undefined;