@@ -5,23 +5,29 @@ import * as cp from "child_process";
5
5
import * as fse from "fs-extra" ;
6
6
import * as path from "path" ;
7
7
import * as requireFromString from "require-from-string" ;
8
- import * as vscode from "vscode" ;
8
+ import { ConfigurationChangeEvent , Disposable , MessageItem , window , workspace , WorkspaceConfiguration } from "vscode" ;
9
9
import { Endpoint , IProblem , supportedPlugins } from "./shared" ;
10
10
import { executeCommand , executeCommandWithProgress } from "./utils/cpUtils" ;
11
11
import { genFileName } from "./utils/problemUtils" ;
12
12
import { DialogOptions , openUrl } from "./utils/uiUtils" ;
13
13
import * as wsl from "./utils/wslUtils" ;
14
14
import { toWslPath , useWsl } from "./utils/wslUtils" ;
15
15
16
- class LeetCodeExecutor {
16
+ class LeetCodeExecutor implements Disposable {
17
17
private leetCodeRootPath : string ;
18
18
private leetCodeRootPathInWsl : string ;
19
19
private nodeExecutable : string ;
20
+ private configurationChangeListener : Disposable ;
20
21
21
22
constructor ( ) {
22
23
this . leetCodeRootPath = path . join ( __dirname , ".." , ".." , "node_modules" , "vsc-leetcode-cli" ) ;
23
24
this . leetCodeRootPathInWsl = "" ;
24
25
this . nodeExecutable = this . getNodePath ( ) ;
26
+ this . configurationChangeListener = workspace . onDidChangeConfiguration ( ( event : ConfigurationChangeEvent ) => {
27
+ if ( event . affectsConfiguration ( "leetcode.nodePath" ) ) {
28
+ this . nodeExecutable = this . getNodePath ( ) ;
29
+ }
30
+ } , this ) ;
25
31
}
26
32
27
33
public async getLeetCodeRootPath ( ) : Promise < string > { // not wrapped by ""
@@ -50,7 +56,7 @@ class LeetCodeExecutor {
50
56
try {
51
57
await this . executeCommandEx ( this . nodeExecutable , [ "-v" ] ) ;
52
58
} catch ( error ) {
53
- const choice : vscode . MessageItem | undefined = await vscode . window . showErrorMessage (
59
+ const choice : MessageItem | undefined = await window . showErrorMessage (
54
60
"LeetCode extension needs Node.js installed in environment path" ,
55
61
DialogOptions . open ,
56
62
) ;
@@ -164,8 +170,12 @@ class LeetCodeExecutor {
164
170
return this . nodeExecutable ;
165
171
}
166
172
173
+ public dispose ( ) : void {
174
+ this . configurationChangeListener . dispose ( ) ;
175
+ }
176
+
167
177
private getNodePath ( ) : string {
168
- const extensionConfig : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "leetcode" , null ) ;
178
+ const extensionConfig : WorkspaceConfiguration = workspace . getConfiguration ( "leetcode" , null ) ;
169
179
return extensionConfig . get < string > ( "nodePath" , "node" /* default value */ ) ;
170
180
}
171
181
0 commit comments