@@ -24,6 +24,8 @@ import GenerateRoutesXmlFileCommand from 'command/GenerateRoutesXmlFileCommand';
2424import GenerateAclXmlFileCommand from 'command/GenerateAclXmlFileCommand' ;
2525import GenerateDiXmlFileCommand from 'command/GenerateDiXmlFileCommand' ;
2626import GeneratePreferenceCommand from 'command/GeneratePreferenceCommand' ;
27+ import Magento from 'util/Magento' ;
28+ import { WorkspaceFolder } from 'vscode' ;
2729
2830// This method is called when your extension is activated
2931// Your extension is activated the very first time the command is executed
@@ -46,15 +48,32 @@ export async function activate(context: vscode.ExtensionContext) {
4648 GeneratePreferenceCommand ,
4749 ] ;
4850
49- ExtensionState . init ( context ) ;
51+ const magentoWorkspaces : WorkspaceFolder [ ] = [ ] ;
52+
53+ if ( vscode . workspace . workspaceFolders ) {
54+ for ( const folder of vscode . workspace . workspaceFolders ) {
55+ if ( await Magento . isMagentoWorkspace ( folder ) ) {
56+ magentoWorkspaces . push ( folder ) ;
57+ }
58+ }
59+ }
60+
61+ ExtensionState . init ( context , magentoWorkspaces ) ;
5062
5163 commands . forEach ( command => {
5264 const instance = new command ( ) ;
5365
5466 Common . log ( 'Registering command' , instance . getCommand ( ) ) ;
5567
56- const disposable = vscode . commands . registerCommand ( instance . getCommand ( ) , ( ...args ) => {
57- instance . execute ( ...args ) ;
68+ const disposable = vscode . commands . registerCommand ( instance . getCommand ( ) , async ( ...args ) => {
69+ try {
70+ await instance . execute ( ...args ) ;
71+ } catch ( error ) {
72+ console . error ( error ) ;
73+ vscode . window . showErrorMessage (
74+ 'An error occurred while executing the command: ' + instance . getCommand ( )
75+ ) ;
76+ }
5877 } ) ;
5978
6079 context . subscriptions . push ( disposable ) ;
0 commit comments