Skip to content

Commit 4ba6fce

Browse files
authored
Fix VS Code "Reopen in Devbox shell environment" in WSL (#2729)
## Summary Fixes #1319 - the "Reopen in Devbox shell environment" command does not work in a VS Code WSL window ## How was it tested? Tested on Windows (WSL), Linux and MacOS. In Windows, the WSL VS Code extension must be installed, and the test project must reside in WSL. 1. Build Devbox and place it in the `PATH` 2. Run VS Code 3. Open a project that has a `devbox.json` file at the root 4. In a Terminal window, verify that the packages in `devbox.json` are not executable (not in the `PATH`) 5. Open the command palette and select "Devbox: Reopen in Devbox shell environment" 6. Verify that the VS Code window closes, and a new VS Code window is opened for the same project. 7. In a Terminal window, exit out of any Devbox shells and verify that the packages in `devbox.json` are executable. ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request, I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).
1 parent 6c517a0 commit 4ba6fce

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/boxcli/integrate.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error {
108108
// PATH after VSCode opens and resets it to global shellenv. This causes the VSCode
109109
// terminal to not be able to find devbox packages after the reopen in devbox
110110
// environment action is called.
111-
return ok && (strings.HasPrefix(k, "DEVBOX_OG_PATH") || k == "NODE_CHANNEL_FD")
111+
//
112+
// ELECTRON_RUN_AS_NODE being set causes this error in WSL:
113+
// "Remote Extension host terminated unexpectedly 3 times within the last 5 minutes."
114+
return ok && (strings.HasPrefix(k, "DEVBOX_OG_PATH") || k == "ELECTRON_RUN_AS_NODE" || k == "NODE_CHANNEL_FD")
112115
})
113116

114117
// Send message to parent process to terminate
@@ -121,7 +124,13 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error {
121124
return err
122125
}
123126
// Open editor with devbox shell environment
124-
cmnd := exec.Command(flags.ideName, message.ConfigDir)
127+
cmndName := flags.ideName
128+
cwd, ok := os.LookupEnv("VSCODE_CWD")
129+
if ok {
130+
// Specify full path to avoid running the `code` shell script from VS Code Server, which fails under WSL
131+
cmndName = cwd + "/bin/" + cmndName
132+
}
133+
cmnd := exec.Command(cmndName, message.ConfigDir)
125134
cmnd.Env = append(cmnd.Env, envVars...)
126135
var outb, errb bytes.Buffer
127136
cmnd.Stdout = &outb

0 commit comments

Comments
 (0)