Skip to content

Commit 2544163

Browse files
authored
[vscode-extension] Added support for reopen in devbox for cursor and vscodium (#2309)
## Summary Title plus, removed remote-ssh dependency to allow publishing the extension in open-vsx marketplace. Addresses #1619 I've been wanting to get this fixed for a while but with recent traction on vscode alternatives it makes sense to finally get this fix in. ## How was it tested? steps: 1. compile devbox binary (devbox run build) 2. update line 56 in `vscode-extension/src/devbox.ts` to the absolute path to compiled devbox binary 3. have all 3 of cursor, vscodium and vscode installed 4. have `vsce` installed globally (npm install -g vsce) 5. in devbox/vscode-extension folder run: `vsce package && code --install-extension devbox-0.1.6.vsix && cursor --install-extension devbox-0.1.6.vsix && codium --install-extension devbox-0.1.6.vsix` 6. quit any already open code editor, open it to refresh the editor with new installed extension 7. cmd + shift + p and type `devbox: reopen in devbox` and hit enter in vscode, cursor, and vscodium
1 parent 3da723b commit 2544163

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

internal/boxcli/integrate.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
type integrateCmdFlags struct {
2424
config configFlags
2525
debugmode bool
26+
ideName string
2627
}
2728

2829
func integrateCmd() *cobra.Command {
@@ -45,12 +46,13 @@ func integrateVSCodeCmd() *cobra.Command {
4546
command := &cobra.Command{
4647
Use: "vscode",
4748
Hidden: true,
48-
Short: "Integrate devbox environment with VSCode.",
49+
Short: "Integrate devbox environment with VSCode or other VSCode-based editors.",
4950
RunE: func(cmd *cobra.Command, args []string) error {
5051
return runIntegrateVSCodeCmd(cmd, flags)
5152
},
5253
}
5354
command.Flags().BoolVar(&flags.debugmode, "debugmode", false, "enable debug outputs to a file.")
55+
command.Flags().StringVar(&flags.ideName, "ide", "code", "name of the currently open editor to reopen after it's closed.")
5456
flags.config.register(command)
5557

5658
return command
@@ -65,7 +67,7 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error {
6567
enabled: flags.debugmode,
6668
}
6769
// Setup process communication with node as parent
68-
dbug.logToFile("Devbox process initiated. Setting up communication channel with VSCode process")
70+
dbug.logToFile("Devbox process initiated. Setting up communication channel with the code editor process")
6971
channel, err := go2node.RunAsNodeChild()
7072
if err != nil {
7173
dbug.logToFile(err.Error())
@@ -110,21 +112,21 @@ func runIntegrateVSCodeCmd(cmd *cobra.Command, flags integrateCmdFlags) error {
110112
})
111113

112114
// Send message to parent process to terminate
113-
dbug.logToFile("Signaling VSCode to close")
115+
dbug.logToFile("Signaling code editor to close")
114116
err = channel.Write(&go2node.NodeMessage{
115117
Message: []byte(`{"status": "finished"}`),
116118
})
117119
if err != nil {
118120
dbug.logToFile(err.Error())
119121
return err
120122
}
121-
// Open vscode with devbox shell environment
122-
cmnd := exec.Command("code", message.ConfigDir)
123+
// Open editor with devbox shell environment
124+
cmnd := exec.Command(flags.ideName, message.ConfigDir)
123125
cmnd.Env = append(cmnd.Env, envVars...)
124126
var outb, errb bytes.Buffer
125127
cmnd.Stdout = &outb
126128
cmnd.Stderr = &errb
127-
dbug.logToFile("Re-opening VSCode in computed devbox environment")
129+
dbug.logToFile("Re-opening code editor in computed devbox environment")
128130
err = cmnd.Run()
129131
if err != nil {
130132
dbug.logToFile(fmt.Sprintf("stdout: %s \n stderr: %s", outb.String(), errb.String()))

vscode-extension/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "devbox",
33
"displayName": "devbox by Jetify",
44
"description": "devbox integration for VSCode",
5-
"version": "0.1.5",
5+
"version": "0.1.6",
66
"icon": "assets/icon.png",
77
"repository": {
88
"type": "git",
@@ -21,9 +21,6 @@
2121
"onStartupFinished"
2222
],
2323
"main": "./out/extension.js",
24-
"extensionDependencies": [
25-
"ms-vscode-remote.remote-ssh"
26-
],
2724
"contributes": {
2825
"commands": [
2926
{

vscode-extension/src/devbox.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ interface Message {
77
status: string
88
}
99

10+
const appNameBinaryMap: {[key: string]: string} = {
11+
"vscodium": "codium",
12+
// eslint-disable-next-line @typescript-eslint/naming-convention
13+
"visual studio code": "code",
14+
"cursor": "cursor",
15+
};
16+
1017
export async function devboxReopen() {
1118
if (process.platform === 'win32') {
1219
const seeDocs = 'See Devbox docs';
@@ -38,7 +45,7 @@ export async function devboxReopen() {
3845
await setupDotDevbox(workingDir, dotdevbox);
3946

4047
// setup required vscode settings
41-
await logToFile(dotdevbox, 'Updating VSCode configurations');
48+
await logToFile(dotdevbox, 'Updating editor configurations');
4249
progress.report({ message: 'Updating configurations...', increment: 50 });
4350
updateVSCodeConf();
4451

@@ -49,7 +56,9 @@ export async function devboxReopen() {
4956
const devbox = 'devbox';
5057
// run devbox integrate and then close this window
5158
const debugModeFlag = workspace.getConfiguration("devbox").get("enableDebugMode");
52-
let child = spawn(devbox, ['integrate', 'vscode', '--debugmode='+debugModeFlag], {
59+
// name of the currently open editor
60+
const ideName = appNameBinaryMap[env.appName.toLocaleLowerCase()] || 'code';
61+
let child = spawn(devbox, ['integrate', 'vscode', '--debugmode='+debugModeFlag, '--ide='+ideName], {
5362
cwd: workingDir.path,
5463
stdio: [0, 1, 2, 'ipc']
5564
});

0 commit comments

Comments
 (0)