(cmd *cobra.Command, flags integrateCmdFlags)
| 63 | } |
| 64 | |
| 65 | func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error { |
| 66 | dbug := debugMode{ |
| 67 | enabled: flags.debugmode, |
| 68 | } |
| 69 | // Setup process communication with node as parent |
| 70 | dbug.logToFile("Devbox process initiated. Setting up communication channel with the code editor process") |
| 71 | channel, err := go2node.RunAsNodeChild() |
| 72 | if err != nil { |
| 73 | dbug.logToFile(err.Error()) |
| 74 | return err |
| 75 | } |
| 76 | // Get config dir as a message from parent process |
| 77 | msg, err := channel.Read() |
| 78 | if err != nil { |
| 79 | dbug.logToFile(err.Error()) |
| 80 | return err |
| 81 | } |
| 82 | // Parse node process' message |
| 83 | var message parentMessage |
| 84 | if err = json.Unmarshal(msg.Message, &message); err != nil { |
| 85 | dbug.logToFile(err.Error()) |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | // todo: add error handling - consider sending error message to parent process |
| 90 | box, err := devbox.Open(&devopt.Opts{ |
| 91 | Dir: message.ConfigDir, |
| 92 | Stderr: cmd.ErrOrStderr(), |
| 93 | }) |
| 94 | if err != nil { |
| 95 | dbug.logToFile(err.Error()) |
| 96 | return err |
| 97 | } |
| 98 | // Get env variables of a devbox shell |
| 99 | dbug.logToFile("Computing devbox environment") |
| 100 | envVars, err := box.EnvVars(cmd.Context()) |
| 101 | if err != nil { |
| 102 | dbug.logToFile(err.Error()) |
| 103 | return err |
| 104 | } |
| 105 | envVars = slices.DeleteFunc(envVars, func(s string) bool { |
| 106 | k, _, ok := strings.Cut(s, "=") |
| 107 | // DEVBOX_OG_PATH_<hash> being set causes devbox global shellenv to overwrite the |
| 108 | // PATH after VSCode opens and resets it to global shellenv. This causes the VSCode |
| 109 | // terminal to not be able to find devbox packages after the reopen in devbox |
| 110 | // environment action is called. |
| 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") |
| 115 | }) |
| 116 | |
| 117 | // Send message to parent process to terminate |
| 118 | dbug.logToFile("Signaling code editor to close") |
| 119 | err = channel.Write(&go2node.NodeMessage{ |
| 120 | Message: []byte(`{"status": "finished"}`), |
| 121 | }) |
| 122 | if err != nil { |
no test coverage detected