diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index ce4a84e8..271ca9a4 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -14,13 +14,11 @@ import { toWslPath, useWsl } from "./utils/wslUtils"; 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")) { @@ -29,18 +27,11 @@ class LeetCodeExecutor implements Disposable { }, this); } - public async getLeetCodeRootPath(): Promise { // not wrapped by "" + public async getLeetCodeBinaryPath(): Promise { if (wsl.useWsl()) { - if (!this.leetCodeRootPathInWsl) { - this.leetCodeRootPathInWsl = `${await wsl.toWslPath(this.leetCodeRootPath)}`; - } - return `${this.leetCodeRootPathInWsl}`; + return `${await wsl.toWslPath(`"${path.join(this.leetCodeRootPath, "bin", "leetcode")}"`)}`; } - return `${this.leetCodeRootPath}`; - } - - public async getLeetCodeBinaryPath(): Promise { // wrapped by "" - return `"${path.join(await this.getLeetCodeRootPath(), "bin", "leetcode")}"`; + return `"${path.join(this.leetCodeRootPath, "bin", "leetcode")}"`; } public async meetRequirements(): Promise { @@ -168,7 +159,7 @@ class LeetCodeExecutor implements Disposable { public async getCompaniesAndTags(): Promise<{ companies: { [key: string]: string[] }, tags: { [key: string]: string[] } }> { // preprocess the plugin source - const companiesTagsPath: string = path.join(await leetCodeExecutor.getLeetCodeRootPath(), "lib", "plugins", "company.js"); + const companiesTagsPath: string = path.join(this.leetCodeRootPath, "lib", "plugins", "company.js"); const companiesTagsSrc: string = (await fse.readFile(companiesTagsPath, "utf8")).replace( "module.exports = plugin", "module.exports = { COMPONIES, TAGS }", diff --git a/src/utils/wslUtils.ts b/src/utils/wslUtils.ts index d496b038..16d83cde 100644 --- a/src/utils/wslUtils.ts +++ b/src/utils/wslUtils.ts @@ -15,5 +15,8 @@ export async function toWslPath(path: string): Promise { } export async function toWinPath(path: string): Promise { - return (await executeCommand("wsl", ["wslpath", "-w", `"${path}"`])).trim(); + if (path.startsWith("\\mnt\\")) { + return (await executeCommand("wsl", ["wslpath", "-w", `"${path.replace(/\\/g, "/").substr(0, 6)}"`])).trim() + path.substr(7); + } + return (await executeCommand("wsl", ["wslpath", "-w", "/"])).trim() + path; }