MCPcopy Index your code
hub / github.com/jetify-com/devbox / runIntegrateVSCodeCmd

Function runIntegrateVSCodeCmd

internal/boxcli/integrate.go:65–141  ·  view source on GitHub ↗
(cmd *cobra.Command, flags integrateCmdFlags)

Source from the content-addressed store, hash-verified

63}
64
65func 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 {

Callers 1

integrateVSCodeCmdFunction · 0.85

Calls 9

logToFileMethod · 0.95
OpenFunction · 0.92
resolveEditorBinaryFunction · 0.85
EnvVarsMethod · 0.80
WriteMethod · 0.80
CommandMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected