@@ -2,22 +2,29 @@ import * as vscode from 'vscode';
2
2
import { promptMagentoProjectSelection , showErrorMessage , activateExtension , isValidPath , deleteReportFile } from './helpers' ;
3
3
import { LogItem , ReportViewerProvider } from './logViewer' ;
4
4
5
+ let disposables : vscode . Disposable [ ] = [ ] ;
6
+
5
7
export function activate ( context : vscode . ExtensionContext ) : void {
6
- const config = vscode . workspace . getConfiguration ( ) ;
7
- const isMagentoProject = config . get < string > ( 'magentoLogViewer.isMagentoProject' , 'Please select' ) ;
8
+ // Get workspace folders
9
+ const workspaceFolders = vscode . workspace . workspaceFolders ;
10
+ const workspaceUri = workspaceFolders ?. [ 0 ] ?. uri || null ;
11
+
12
+ // Get configuration with resource scope
13
+ const config = vscode . workspace . getConfiguration ( 'magentoLogViewer' , workspaceUri ) ;
14
+ const isMagentoProject = config . get < string > ( 'isMagentoProject' , 'Please select' ) ;
8
15
9
16
if ( isMagentoProject === 'Please select' ) {
10
17
promptMagentoProjectSelection ( config , context ) ;
11
18
} else if ( isMagentoProject === 'Yes' ) {
12
- const magentoRoot = config . get < string > ( 'magentoLogViewer. magentoRoot' , '' ) ;
19
+ const magentoRoot = config . get < string > ( 'magentoRoot' , '' ) ;
13
20
if ( ! magentoRoot || ! isValidPath ( magentoRoot ) ) {
14
21
showErrorMessage ( 'Magento root path is not set or is not a directory.' ) ;
15
22
return ;
16
23
}
17
24
const reportViewerProvider = new ReportViewerProvider ( magentoRoot ) ;
18
25
activateExtension ( context , magentoRoot , reportViewerProvider ) ;
19
26
20
- vscode . commands . registerCommand ( 'magento-log-viewer.deleteReportFile' , ( logItem : LogItem ) => {
27
+ const deleteCommand = vscode . commands . registerCommand ( 'magento-log-viewer.deleteReportFile' , ( logItem : LogItem ) => {
21
28
if ( logItem && logItem . command && logItem . command . arguments && logItem . command . arguments [ 0 ] ) {
22
29
const filePath = logItem . command . arguments [ 0 ] ;
23
30
deleteReportFile ( filePath ) ;
@@ -26,7 +33,25 @@ export function activate(context: vscode.ExtensionContext): void {
26
33
showErrorMessage ( 'Failed to delete report file: Invalid file path.' ) ;
27
34
}
28
35
} ) ;
36
+
37
+ disposables . push ( deleteCommand ) ;
38
+ context . subscriptions . push ( ...disposables ) ;
29
39
}
30
40
}
31
41
32
- export function deactivate ( ) : void { }
42
+ export function deactivate ( ) : void {
43
+ // Clear any context values we set
44
+ vscode . commands . executeCommand ( 'setContext' , 'magentoLogViewer.hasMagentoRoot' , undefined ) ;
45
+
46
+ // Dispose of all disposables
47
+ while ( disposables . length ) {
48
+ const disposable = disposables . pop ( ) ;
49
+ if ( disposable ) {
50
+ try {
51
+ disposable . dispose ( ) ;
52
+ } catch ( err ) {
53
+ console . error ( 'Error disposing:' , err ) ;
54
+ }
55
+ }
56
+ }
57
+ }
0 commit comments