@@ -5,23 +5,29 @@ import * as cp from "child_process";
55import * as fse from "fs-extra" ;
66import * as path from "path" ;
77import * as requireFromString from "require-from-string" ;
8- import * as vscode from "vscode" ;
8+ import { ConfigurationChangeEvent , Disposable , MessageItem , window , workspace , WorkspaceConfiguration } from "vscode" ;
99import { Endpoint , IProblem , supportedPlugins } from "./shared" ;
1010import { executeCommand , executeCommandWithProgress } from "./utils/cpUtils" ;
1111import { genFileName } from "./utils/problemUtils" ;
1212import { DialogOptions , openUrl } from "./utils/uiUtils" ;
1313import * as wsl from "./utils/wslUtils" ;
1414import { toWslPath , useWsl } from "./utils/wslUtils" ;
1515
16- class LeetCodeExecutor {
16+ class LeetCodeExecutor implements Disposable {
1717 private leetCodeRootPath : string ;
1818 private leetCodeRootPathInWsl : string ;
1919 private nodeExecutable : string ;
20+ private configurationChangeListener : Disposable ;
2021
2122 constructor ( ) {
2223 this . leetCodeRootPath = path . join ( __dirname , ".." , ".." , "node_modules" , "vsc-leetcode-cli" ) ;
2324 this . leetCodeRootPathInWsl = "" ;
2425 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 ) ;
2531 }
2632
2733 public async getLeetCodeRootPath ( ) : Promise < string > { // not wrapped by ""
@@ -50,7 +56,7 @@ class LeetCodeExecutor {
5056 try {
5157 await this . executeCommandEx ( this . nodeExecutable , [ "-v" ] ) ;
5258 } catch ( error ) {
53- const choice : vscode . MessageItem | undefined = await vscode . window . showErrorMessage (
59+ const choice : MessageItem | undefined = await window . showErrorMessage (
5460 "LeetCode extension needs Node.js installed in environment path" ,
5561 DialogOptions . open ,
5662 ) ;
@@ -164,8 +170,12 @@ class LeetCodeExecutor {
164170 return this . nodeExecutable ;
165171 }
166172
173+ public dispose ( ) : void {
174+ this . configurationChangeListener . dispose ( ) ;
175+ }
176+
167177 private getNodePath ( ) : string {
168- const extensionConfig : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "leetcode" , null ) ;
178+ const extensionConfig : WorkspaceConfiguration = workspace . getConfiguration ( "leetcode" , null ) ;
169179 return extensionConfig . get < string > ( "nodePath" , "node" /* default value */ ) ;
170180 }
171181
0 commit comments