Skip to content

Commit 8f595b2

Browse files
committed
Fix VS Code integration under WSL
1 parent e8dfb82 commit 8f595b2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

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)