Skip to content

Commit df95260

Browse files
authored
Improve handling when speech ext not installed/enabled and start dictation is used (microsoft#269556)
fix microsoft#269054
1 parent 92669c0 commit df95260

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

src/vs/workbench/contrib/terminal/browser/terminalMenus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ export function setupTerminalMenus(): void {
761761
},
762762
group: 'navigation',
763763
order: 9,
764-
when: ContextKeyExpr.and(ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal), HasSpeechProvider, TerminalContextKeys.terminalDictationInProgress.negate()),
764+
when: ContextKeyExpr.and(ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal), TerminalContextKeys.terminalDictationInProgress.negate()),
765765
isHiddenByDefault: true
766766
});
767767
MenuRegistry.appendMenuItem(menuId, {

src/vs/workbench/contrib/terminalContrib/voice/browser/terminalVoiceActions.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { localize2 } from '../../../../../nls.js';
7-
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
6+
import { IAction } from '../../../../../base/common/actions.js';
7+
import { localize, localize2 } from '../../../../../nls.js';
8+
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
9+
import { ContextKeyExpr, IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';
10+
import { IExtensionManagementService } from '../../../../../platform/extensionManagement/common/extensionManagement.js';
811
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
12+
import { INotificationService, Severity } from '../../../../../platform/notification/common/notification.js';
13+
import { EnablementState, IWorkbenchExtensionEnablementService } from '../../../../services/extensionManagement/common/extensionManagement.js';
914
import { HasSpeechProvider, SpeechToTextInProgress } from '../../../speech/common/speechService.js';
1015
import { registerActiveInstanceAction, sharedWhenClause } from '../../../terminal/browser/terminalActions.js';
1116
import { TerminalCommandId } from '../../../terminal/common/terminal.js';
@@ -17,14 +22,57 @@ export function registerTerminalVoiceActions() {
1722
id: TerminalCommandId.StartVoice,
1823
title: localize2('workbench.action.terminal.startDictation', "Start Dictation in Terminal"),
1924
precondition: ContextKeyExpr.and(
20-
HasSpeechProvider,
2125
SpeechToTextInProgress.toNegated(),
2226
sharedWhenClause.terminalAvailable
2327
),
2428
f1: true,
25-
run: (activeInstance, c, accessor) => {
26-
const instantiationService = accessor.get(IInstantiationService);
27-
TerminalVoiceSession.getInstance(instantiationService).start();
29+
run: async (activeInstance, c, accessor) => {
30+
const contextKeyService = accessor.get(IContextKeyService);
31+
const commandService = accessor.get(ICommandService);
32+
const notificationService = accessor.get(INotificationService);
33+
const workbenchExtensionEnablementService = accessor.get(IWorkbenchExtensionEnablementService);
34+
const extensionManagementService = accessor.get(IExtensionManagementService);
35+
if (HasSpeechProvider.getValue(contextKeyService)) {
36+
const instantiationService = accessor.get(IInstantiationService);
37+
TerminalVoiceSession.getInstance(instantiationService).start();
38+
return;
39+
}
40+
const extensions = await extensionManagementService.getInstalled();
41+
const extension = extensions.find(extension => extension.identifier.id === 'ms-vscode.vscode-speech');
42+
const extensionIsDisabled = extension && !workbenchExtensionEnablementService.isEnabled(extension);
43+
const learnMoreAction = {
44+
label: localize('viewExtension', "View Extension"),
45+
run: () => commandService.executeCommand('workbench.extensions.search', '@id:ms-vscode.vscode-speech'),
46+
id: '',
47+
tooltip: '',
48+
class: undefined,
49+
enabled: true
50+
};
51+
52+
const actions: IAction[] = [];
53+
let message: string;
54+
if (extensionIsDisabled) {
55+
message = localize('terminal.voice.enableSpeechExtension', "You must enable the Speech extension to use Dictation in the Terminal.");
56+
actions.push({
57+
id: 'enableSpeechExtension',
58+
tooltip: '',
59+
class: undefined,
60+
enabled: true,
61+
label: localize('enableSpeechExtension', "Enable for Workspace"),
62+
run: () => workbenchExtensionEnablementService.setEnablement([extension], EnablementState.EnabledWorkspace),
63+
}, learnMoreAction);
64+
} else {
65+
message = localize('terminal.voice.installSpeechExtension', "You must install the Speech extension to use Dictation in the Terminal.");
66+
actions.push({
67+
id: 'installSpeechExtension',
68+
label: localize('installSpeechExtension', "Install Speech Extension"),
69+
run: () => commandService.executeCommand('workbench.extensions.installExtension', 'ms-vscode.vscode-speech'),
70+
tooltip: '',
71+
class: undefined,
72+
enabled: true
73+
}, learnMoreAction);
74+
}
75+
notificationService.notify({ severity: Severity.Info, message, actions: { primary: actions } });
2876
}
2977
});
3078

0 commit comments

Comments
 (0)