From 428255d41fd1446c0c6dbf040d223f42d2040cc1 Mon Sep 17 00:00:00 2001 From: LinkeyLeo Date: Thu, 13 Feb 2020 19:05:09 +0800 Subject: [PATCH 1/6] fixed use wsl feature convert path wsl after full path constructed leetCodeRootPathInWsl no longer used getLeetCodeRootPath function removed since it has only one reference after the bug fixed --- src/leetCodeExecutor.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index ce4a84e8..2fe9b652 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,13 @@ class LeetCodeExecutor implements Disposable { }, this); } - public async getLeetCodeRootPath(): Promise { // not wrapped by "" - if (wsl.useWsl()) { - if (!this.leetCodeRootPathInWsl) { - this.leetCodeRootPathInWsl = `${await wsl.toWslPath(this.leetCodeRootPath)}`; + getLeetCodeBinaryPath() { + return __awaiter(this, void 0, void 0, function* () { + if (wsl.useWsl()) { + return `${yield wsl.toWslPath(`"${path.join(yield `"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`)}`; } - return `${this.leetCodeRootPathInWsl}`; - } - return `${this.leetCodeRootPath}`; - } - - public async getLeetCodeBinaryPath(): Promise { // wrapped by "" - return `"${path.join(await this.getLeetCodeRootPath(), "bin", "leetcode")}"`; + return `"${path.join(yield `"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`; + }); } public async meetRequirements(): Promise { @@ -168,7 +161,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(await this.leetCodeRootPath, "lib", "plugins", "company.js"); const companiesTagsSrc: string = (await fse.readFile(companiesTagsPath, "utf8")).replace( "module.exports = plugin", "module.exports = { COMPONIES, TAGS }", From 103400141a2be000781debca19c5b13c6986610f Mon Sep 17 00:00:00 2001 From: LinkeyLeo Date: Thu, 13 Feb 2020 19:27:55 +0800 Subject: [PATCH 2/6] Update leetCodeExecutor.ts add missing signature --- src/leetCodeExecutor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index 2fe9b652..e5b24c1c 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -27,7 +27,7 @@ class LeetCodeExecutor implements Disposable { }, this); } - getLeetCodeBinaryPath() { + public async getLeetCodeBinaryPath() { return __awaiter(this, void 0, void 0, function* () { if (wsl.useWsl()) { return `${yield wsl.toWslPath(`"${path.join(yield `"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`)}`; From f0d01f7845393d8d86961db7e498b739518470a0 Mon Sep 17 00:00:00 2001 From: LinkeyLeo Date: Thu, 13 Feb 2020 19:32:28 +0800 Subject: [PATCH 3/6] Update leetCodeExecutor.ts --- src/leetCodeExecutor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index e5b24c1c..ccf772cd 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -27,7 +27,7 @@ class LeetCodeExecutor implements Disposable { }, this); } - public async getLeetCodeBinaryPath() { + public async getLeetCodeBinaryPath(): Promise { return __awaiter(this, void 0, void 0, function* () { if (wsl.useWsl()) { return `${yield wsl.toWslPath(`"${path.join(yield `"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`)}`; From f3ad33ff9deaad3aa93250b239142f81118b1208 Mon Sep 17 00:00:00 2001 From: LinkeyLeo Date: Thu, 13 Feb 2020 19:34:07 +0800 Subject: [PATCH 4/6] Update leetCodeExecutor.ts --- src/leetCodeExecutor.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index ccf772cd..9e668ce2 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -28,12 +28,10 @@ class LeetCodeExecutor implements Disposable { } public async getLeetCodeBinaryPath(): Promise { - return __awaiter(this, void 0, void 0, function* () { - if (wsl.useWsl()) { - return `${yield wsl.toWslPath(`"${path.join(yield `"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`)}`; - } - return `"${path.join(yield `"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`; - }); + if (wsl.useWsl()) { + return `${yield wsl.toWslPath(`"${path.join(yield`"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`)}`; + } + return `"${path.join(yield`"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`; } public async meetRequirements(): Promise { From 4066e02aea06cb59bd52d24f3099d2e569d53da2 Mon Sep 17 00:00:00 2001 From: LinkeyLeo Date: Thu, 13 Feb 2020 19:47:04 +0800 Subject: [PATCH 5/6] Update leetCodeExecutor.ts --- src/leetCodeExecutor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index 9e668ce2..271ca9a4 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -29,9 +29,9 @@ class LeetCodeExecutor implements Disposable { public async getLeetCodeBinaryPath(): Promise { if (wsl.useWsl()) { - return `${yield wsl.toWslPath(`"${path.join(yield`"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`)}`; + return `${await wsl.toWslPath(`"${path.join(this.leetCodeRootPath, "bin", "leetcode")}"`)}`; } - return `"${path.join(yield`"${this.leetCodeRootPath}"`, "bin", "leetcode")}"`; + return `"${path.join(this.leetCodeRootPath, "bin", "leetcode")}"`; } public async meetRequirements(): Promise { @@ -159,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 this.leetCodeRootPath, "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 }", From 96a5821aadb742f4ec54c063d64931d2c5a38a12 Mon Sep 17 00:00:00 2001 From: LinkeyLeo Date: Thu, 13 Feb 2020 21:36:14 +0800 Subject: [PATCH 6/6] Update wslUtils.ts patch to solve wslpath fail when path not exists --- src/utils/wslUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; }