Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo committed Mar 31, 2019
1 parent d61996b commit f067925
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
leetCodePreviewProvider,
leetCodeResultProvider,
leetCodeSolutionProvider,
leetCodeExecutor,
vscode.window.createTreeView("leetCodeExplorer", { treeDataProvider: leetCodeTreeDataProvider, showCollapseAll: true }),
vscode.languages.registerCodeLensProvider({ scheme: "file" }, codeLensProvider),
vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()),
Expand Down
18 changes: 14 additions & 4 deletions src/leetCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ import * as cp from "child_process";
import * as fse from "fs-extra";
import * as path from "path";
import * as requireFromString from "require-from-string";
import * as vscode from "vscode";
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace, WorkspaceConfiguration } from "vscode";
import { Endpoint, IProblem, supportedPlugins } from "./shared";
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
import { genFileName } from "./utils/problemUtils";
import { DialogOptions, openUrl } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
import { toWslPath, useWsl } from "./utils/wslUtils";

class LeetCodeExecutor {
class LeetCodeExecutor implements Disposable {
private leetCodeRootPath: string;
private leetCodeRootPathInWsl: string;
private nodeExecutable: string;
private configurationChangeListener: Disposable;

constructor() {
this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli");
this.leetCodeRootPathInWsl = "";
this.nodeExecutable = this.getNodePath();
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration("leetcode.nodePath")) {
this.nodeExecutable = this.getNodePath();
}
}, this);
}

public async getLeetCodeRootPath(): Promise<string> { // not wrapped by ""
Expand Down Expand Up @@ -50,7 +56,7 @@ class LeetCodeExecutor {
try {
await this.executeCommandEx(this.nodeExecutable, ["-v"]);
} catch (error) {
const choice: vscode.MessageItem | undefined = await vscode.window.showErrorMessage(
const choice: MessageItem | undefined = await window.showErrorMessage(
"LeetCode extension needs Node.js installed in environment path",
DialogOptions.open,
);
Expand Down Expand Up @@ -164,8 +170,12 @@ class LeetCodeExecutor {
return this.nodeExecutable;
}

public dispose(): void {
this.configurationChangeListener.dispose();
}

private getNodePath(): string {
const extensionConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode", null);
const extensionConfig: WorkspaceConfiguration = workspace.getConfiguration("leetcode", null);
return extensionConfig.get<string>("nodePath", "node" /* default value */);
}

Expand Down

0 comments on commit f067925

Please sign in to comment.