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' ;
811import { 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' ;
914import { HasSpeechProvider , SpeechToTextInProgress } from '../../../speech/common/speechService.js' ;
1015import { registerActiveInstanceAction , sharedWhenClause } from '../../../terminal/browser/terminalActions.js' ;
1116import { 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