Skip to content

Commit

Permalink
fix: set correct cwd for WSL (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Dec 9, 2023
1 parent d3b25fd commit 240e8f9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main_controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ChildProcess, execSync, spawn } from "child_process";
import { readFile } from "fs/promises";
import path from "path";
Expand Down Expand Up @@ -63,10 +62,13 @@ export class MainController implements vscode.Disposable {
public viewportManager!: ViewportManager;

public constructor(private extContext: ExtensionContext) {
const wslpath = (path: string) =>
// execSync returns a newline character at the end
execSync(`C:\\Windows\\system32\\wsl.exe wslpath '${path}'`).toString().trim();

let extensionPath = extContext.extensionPath.replace(/\\/g, "\\\\");
if (config.useWsl) {
// execSync returns a newline character at the end
extensionPath = execSync(`C:\\Windows\\system32\\wsl.exe wslpath '${extensionPath}'`).toString().trim();
extensionPath = wslpath(extensionPath);
}

// These paths get called inside WSL, they must be POSIX paths (forward slashes)
Expand All @@ -85,9 +87,9 @@ export class MainController implements vscode.Disposable {
];

const workspaceFolder = vscode.workspace.workspaceFolders;
const cwd = workspaceFolder && workspaceFolder.length ? workspaceFolder[0].uri.fsPath : undefined;
if (cwd && !config.useWsl && !vscode.env.remoteName) {
args.push("-c", `cd ${cwd}`);
const cwd = workspaceFolder?.length ? workspaceFolder[0].uri.fsPath : undefined;
if (cwd && !vscode.env.remoteName) {
args.push("-c", `cd ${config.useWsl ? wslpath(cwd) : cwd}`);
}

if (config.useWsl) {
Expand Down

0 comments on commit 240e8f9

Please sign in to comment.