@@ -15,9 +15,13 @@ export function activate(context: vscode.ExtensionContext) {
1515 const workspaceFolders = vscode . workspace . workspaceFolders ;
1616 const defaultUri = workspaceFolders && workspaceFolders . length > 0 ? workspaceFolders [ 0 ] . uri : undefined ;
1717 vscode . window . showOpenDialog ( { defaultUri, canSelectFolders : true , canSelectMany : false , openLabel : 'Select Magento Root Folder' } ) . then ( folderUri => {
18- if ( folderUri && folderUri [ 0 ] ) {
18+ if ( folderUri ?. [ 0 ] ) {
1919 config . update ( 'magentoLogViewer.magentoRoot' , folderUri [ 0 ] . fsPath , vscode . ConfigurationTarget . Workspace ) . then ( ( ) => {
20- vscode . window . showInformationMessage ( 'Magento root folder successfully saved!' ) ;
20+ try {
21+ vscode . window . showInformationMessage ( 'Magento root folder successfully saved!' ) ;
22+ } catch ( error ) {
23+ console . error ( 'Failed to show information message:' , error instanceof Error ? error . message : String ( error ) ) ;
24+ }
2125 config . update ( 'magentoLogViewer.isMagentoProject' , 'Yes' , vscode . ConfigurationTarget . Workspace ) ;
2226 activateExtension ( context , folderUri [ 0 ] . fsPath ) ;
2327 } ) ;
@@ -32,7 +36,11 @@ export function activate(context: vscode.ExtensionContext) {
3236 } else if ( isMagentoProject === 'Yes' ) {
3337 const magentoRoot = config . get < string > ( 'magentoLogViewer.magentoRoot' , '' ) ;
3438 if ( ! magentoRoot || ! isValidPath ( magentoRoot ) ) {
35- vscode . window . showErrorMessage ( 'Magento root path is not set or is not a directory.' ) ;
39+ try {
40+ vscode . window . showErrorMessage ( 'Magento root path is not set or is not a directory.' ) ;
41+ } catch ( error ) {
42+ console . error ( 'Failed to show error message:' , error instanceof Error ? error . message : String ( error ) ) ;
43+ }
3644 return ;
3745 }
3846 activateExtension ( context , magentoRoot ) ;
@@ -44,17 +52,20 @@ function activateExtension(context: vscode.ExtensionContext, magentoRoot: string
4452 const treeView = vscode . window . createTreeView ( 'logFiles' , { treeDataProvider : logViewerProvider } ) ;
4553
4654 vscode . commands . registerCommand ( 'magento-log-viewer.refreshLogFiles' , ( ) => logViewerProvider . refresh ( ) ) ;
47- vscode . commands . registerCommand ( 'magento-log-viewer.openFile' , ( filePath , lineNumber ) => {
48- if ( lineNumber !== undefined ) {
49- const options : vscode . TextDocumentShowOptions = {
50- selection : new vscode . Range ( new vscode . Position ( lineNumber , 0 ) , new vscode . Position ( lineNumber , 0 ) )
51- } ;
52- vscode . window . showTextDocument ( vscode . Uri . file ( filePath ) , options ) ;
53- } else {
54- vscode . window . showTextDocument ( vscode . Uri . file ( filePath ) ) ;
55+ vscode . commands . registerCommand ( 'magento-log-viewer.openFile' , ( filePath : string , lineNumber ?: number ) => {
56+
57+ if ( typeof filePath === 'string' ) {
58+ if ( lineNumber !== undefined && typeof lineNumber === 'number' && typeof vscode !== 'undefined' && typeof vscode . window !== 'undefined' ) {
59+ const options : vscode . TextDocumentShowOptions = {
60+ selection : new vscode . Range ( new vscode . Position ( lineNumber , 0 ) , new vscode . Position ( lineNumber , 0 ) )
61+ } ;
62+ vscode . window . showTextDocument ( vscode . Uri . file ( filePath ) , options ) ;
63+ } else {
64+ vscode . window . showTextDocument ( vscode . Uri . file ( filePath ) ) ;
65+ }
5566 }
5667 } ) ;
57- vscode . commands . registerCommand ( 'magento-log-viewer.openFileAtLine' , ( filePath , lineNumber ) => {
68+ vscode . commands . registerCommand ( 'magento-log-viewer.openFileAtLine' , ( filePath : string , lineNumber : number ) => {
5869 const options : vscode . TextDocumentShowOptions = {
5970 selection : new vscode . Range ( new vscode . Position ( lineNumber , 0 ) , new vscode . Position ( lineNumber , 0 ) )
6071 } ;
@@ -67,9 +78,17 @@ function activateExtension(context: vscode.ExtensionContext, magentoRoot: string
6778 const files = fs . readdirSync ( logPath ) ;
6879 files . forEach ( file => fs . unlinkSync ( path . join ( logPath , file ) ) ) ;
6980 logViewerProvider . refresh ( ) ;
70- vscode . window . showInformationMessage ( 'All log files have been cleared.' ) ;
81+ try {
82+ vscode . window . showInformationMessage ( 'All log files have been cleared.' ) ;
83+ } catch ( error ) {
84+ console . error ( 'Failed to show information message:' , error instanceof Error ? error . message : String ( error ) ) ;
85+ }
7186 } else {
72- vscode . window . showInformationMessage ( 'No log files found to clear.' ) ;
87+ try {
88+ vscode . window . showInformationMessage ( 'No log files found to clear.' ) ;
89+ } catch ( error ) {
90+ console . error ( 'Failed to show information message:' , error instanceof Error ? error . message : String ( error ) ) ;
91+ }
7392 }
7493 } ) ;
7594
0 commit comments