diff --git a/internal/boxcli/integrate.go b/internal/boxcli/integrate.go index a6d8191af1b..46040a0f579 100644 --- a/internal/boxcli/integrate.go +++ b/internal/boxcli/integrate.go @@ -23,6 +23,7 @@ import ( type integrateCmdFlags struct { config configFlags debugmode bool + ideName string } func integrateCmd() *cobra.Command { @@ -45,12 +46,13 @@ func integrateVSCodeCmd() *cobra.Command { command := &cobra.Command{ Use: "vscode", Hidden: true, - Short: "Integrate devbox environment with VSCode.", + Short: "Integrate devbox environment with VSCode or other VSCode-based editors.", RunE: func(cmd *cobra.Command, args []string) error { return runIntegrateVSCodeCmd(cmd, flags) }, } command.Flags().BoolVar(&flags.debugmode, "debugmode", false, "enable debug outputs to a file.") + command.Flags().StringVar(&flags.ideName, "ide", "code", "name of the currently open editor to reopen after it's closed.") flags.config.register(command) return command @@ -65,7 +67,7 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error { enabled: flags.debugmode, } // Setup process communication with node as parent - dbug.logToFile("Devbox process initiated. Setting up communication channel with VSCode process") + dbug.logToFile("Devbox process initiated. Setting up communication channel with the code editor process") channel, err := go2node.RunAsNodeChild() if err != nil { dbug.logToFile(err.Error()) @@ -110,7 +112,7 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error { }) // Send message to parent process to terminate - dbug.logToFile("Signaling VSCode to close") + dbug.logToFile("Signaling code editor to close") err = channel.Write(&go2node.NodeMessage{ Message: []byte(`{"status": "finished"}`), }) @@ -118,13 +120,13 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error { dbug.logToFile(err.Error()) return err } - // Open vscode with devbox shell environment - cmnd := exec.Command("code", message.ConfigDir) + // Open editor with devbox shell environment + cmnd := exec.Command(flags.ideName, message.ConfigDir) cmnd.Env = append(cmnd.Env, envVars...) var outb, errb bytes.Buffer cmnd.Stdout = &outb cmnd.Stderr = &errb - dbug.logToFile("Re-opening VSCode in computed devbox environment") + dbug.logToFile("Re-opening code editor in computed devbox environment") err = cmnd.Run() if err != nil { dbug.logToFile(fmt.Sprintf("stdout: %s \n stderr: %s", outb.String(), errb.String())) diff --git a/vscode-extension/package.json b/vscode-extension/package.json index 8e48d6a869a..29a1a0f0ec6 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -2,7 +2,7 @@ "name": "devbox", "displayName": "devbox by Jetify", "description": "devbox integration for VSCode", - "version": "0.1.5", + "version": "0.1.6", "icon": "assets/icon.png", "repository": { "type": "git", @@ -21,9 +21,6 @@ "onStartupFinished" ], "main": "./out/extension.js", - "extensionDependencies": [ - "ms-vscode-remote.remote-ssh" - ], "contributes": { "commands": [ { diff --git a/vscode-extension/src/devbox.ts b/vscode-extension/src/devbox.ts index fd85bd93fa9..2fb61a3784d 100644 --- a/vscode-extension/src/devbox.ts +++ b/vscode-extension/src/devbox.ts @@ -7,6 +7,13 @@ interface Message { status: string } +const appNameBinaryMap: {[key: string]: string} = { + "vscodium": "codium", + // eslint-disable-next-line @typescript-eslint/naming-convention + "visual studio code": "code", + "cursor": "cursor", +}; + export async function devboxReopen() { if (process.platform === 'win32') { const seeDocs = 'See Devbox docs'; @@ -38,7 +45,7 @@ export async function devboxReopen() { await setupDotDevbox(workingDir, dotdevbox); // setup required vscode settings - await logToFile(dotdevbox, 'Updating VSCode configurations'); + await logToFile(dotdevbox, 'Updating editor configurations'); progress.report({ message: 'Updating configurations...', increment: 50 }); updateVSCodeConf(); @@ -49,7 +56,9 @@ export async function devboxReopen() { const devbox = 'devbox'; // run devbox integrate and then close this window const debugModeFlag = workspace.getConfiguration("devbox").get("enableDebugMode"); - let child = spawn(devbox, ['integrate', 'vscode', '--debugmode='+debugModeFlag], { + // name of the currently open editor + const ideName = appNameBinaryMap[env.appName.toLocaleLowerCase()] || 'code'; + let child = spawn(devbox, ['integrate', 'vscode', '--debugmode='+debugModeFlag, '--ide='+ideName], { cwd: workingDir.path, stdio: [0, 1, 2, 'ipc'] });