Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions internal/boxcli/integrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
type integrateCmdFlags struct {
config configFlags
debugmode bool
ideName string
}

func integrateCmd() *cobra.Command {
Expand All @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -110,21 +112,21 @@ 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"}`),
})
if err != nil {
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()))
Expand Down
5 changes: 1 addition & 4 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -21,9 +21,6 @@
"onStartupFinished"
],
"main": "./out/extension.js",
"extensionDependencies": [
"ms-vscode-remote.remote-ssh"
],
"contributes": {
"commands": [
{
Expand Down
13 changes: 11 additions & 2 deletions vscode-extension/src/devbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand All @@ -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']
});
Expand Down
Loading