devbox icon indicating copy to clipboard operation
devbox copied to clipboard

[Bug]: VS Code extension: "Reopen in Devbox shell environment" command does not work in WSL

Open apgrucza opened this issue 2 years ago • 2 comments

Current Behavior (bug) The "Reopen in Devbox shell environment" command does not work in a VS Code WSL window. The VS Code window closes without a new one being opened. There is no error message stating that WSL is not supported. (The error message added in #1277 only appears when in a normal VS Code window, not a WSL one).

Expected Behavior (fix) After the VS Code window closes, a new VS Code window should open that is set up with the project's Devbox environment.

Additional context Output of devbox version -v:

Version:     0.5.7
Platform:    linux_amd64
Commit:      95ee45715bd2d5a7e60cd58093f2a87a88a4564d
Commit Time: 2023-07-12T22:28:00Z
Go Version:  go1.20.5
Launcher:    0.2.0

apgrucza avatar Jul 27 '23 01:07 apgrucza

(comment copied from #1029)

I had a poke around myself in internal/boxcli/integrate.go and made these observations:

  • The IPC is working ok (it's able to get the config dir and terminate the parent VS Code process).
  • The code command actually runs a shell script from VS Code Server rather than the Windows VS Code executable. This is because VS Code has modified PATH to include an entry like /home/XXXX/.vscode-server/bin/XXXX/bin/remote-cli.
  • The code shell script runs JavaScript code which fails to start a new VS Code process because the parent VS Code process has been terminated.
  • If the parent VS Code process is kept alive, a new VS Code process is successfully created but the JavaScript code does not forward environment variables to it.

If HOME is set, the Windows executable can be run instead, and environment variables do get passed through. So I'm not sure if this is the best way, but the below changes to integrate.go do work as a proof-of-concept under WSL:

	cmnd := exec.Command(os.Getenv("VSCODE_CWD")+"/bin/code", message.ConfigDir)
	cmnd.Env = append(cmnd.Env, envVars...)
	cmnd.Env = append(cmnd.Env, "HOME="+os.Getenv("HOME")) // Prevent error: mkdir: cannot create directory ‘/.vscode-server’: Permission denied
	cmnd.Env = append(cmnd.Env, "ELECTRON_RUN_AS_NODE=")   // Prevent error: Remote Extension host terminated unexpectedly 3 times within the last 5 minutes.

apgrucza avatar Jul 27 '23 01:07 apgrucza

any updates on this? or a workaround

Abdullah-AlAttar avatar Oct 17 '24 17:10 Abdullah-AlAttar

I've created a PR #2729 that fixes this.

Note that #2703 still limits the usefulness of "Reopen in Devbox shell environment", but at least this fix allows other VS Code extensions to run tools from your Devbox environment.

apgrucza avatar Oct 20 '25 06:10 apgrucza