jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
7.94k stars 191 forks source link

[Bug]: Reopen in Devbox shell doesn't work #1619

Open mikenikles opened 8 months ago

mikenikles commented 8 months ago

Current Behavior (bug) I use Cursor (cursor.sh) as my editor (update: I have the same issue with VS Code), with the Devbox extension installed. When I use the "Devbox: Reopen in Devbox shell environment" command, Cursor closes, but doesn't reopen again.

Expected Behavior (fix) Cursor closes and reopens.

Additional context

devbox version -v

devbox version -v
Version:     0.8.1
Platform:    darwin_arm64
Commit:      a0bdff918b3dde5ebcfc488f72df5efdf3426253
Commit Time: 2023-11-07T21:43:27Z
Go Version:  go1.21.3
Launcher:    0.2.0

devbox.json

{
  "packages": [
    "rustup@latest",
    "libiconv@latest"
  ],
  "env": {
    "PROJECT_DIR": "$PWD"
  },
  "shell": {
    "init_hook": [
      "rustup default stable"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}
mikenikles commented 8 months ago

I tried that command in VS Code Insider and VS Code, but it didn't work there either. Both editors are on their latest versions.

Lagoja commented 8 months ago

@mikenikles Can you share what OS you are encountering this issue on? We've seen some issues with macOS Sonoma, but haven't found a reliable repro

mikenikles commented 8 months ago

I recently upgraded to Sonoma 14.1.1, but I also saw it on whichever the previous OS version was. Now that I'm on Sonoma though and given it's a known issue, I'll accept that it doesn't work :)

aacebedo commented 5 months ago

I have the same problem on NixOS 23.11

mohsenari commented 5 months ago

@mikenikles @aacebedo We just released version 0.1.4 of the extension. It adds a setting called "Debug Mode" that if you enable, it will keep a log of events for "Reopen in Devbox Shell" feature. The log file is in ./devbox/extension.log. If your problem is still persisting, update the extension and enable debug mode and send me the content of this log file. This will help troubleshooting the issue significantly.

mohsenari commented 5 months ago

for reference:

Screenshot 2024-01-29 at 5 04 38β€―PM

aacebedo commented 5 months ago

@mikenikles @aacebedo We just released version 0.1.4 of the extension. It adds a setting called "Debug Mode" that if you enable, it will keep a log of events for "Reopen in Devbox Shell" feature. The log file is in ./devbox/extension.log. If your problem is still persisting, update the extension and enable debug mode and send me the content of this log file. This will help troubleshooting the issue significantly.

Go this on code-insiders 1.86 and devbox 0.8.2 on NixOS, not sure it is very useful:

[Tue, 30 Jan 2024 13:58:14 GMT] Installing devbox packages
[Tue, 30 Jan 2024 13:58:14 GMT] Updating VSCode configurations
[Tue, 30 Jan 2024 13:58:14 GMT] Calling "devbox integrate" to setup environment
[Tue, 30 Jan 2024 13:58:14 GMT] child process closed with exit code: 1
[Tue, 30 Jan 2024 14:44:11 GMT] Installing devbox packages
[Tue, 30 Jan 2024 14:44:11 GMT] Updating VSCode configurations
[Tue, 30 Jan 2024 14:44:11 GMT] Calling "devbox integrate" to setup environment
[Tue, 30 Jan 2024 14:44:11 GMT] child process closed with exit code: 1
[Tue, 30 Jan 2024 16:19:59 GMT] Installing devbox packages
[Tue, 30 Jan 2024 16:19:59 GMT] Updating VSCode configurations
[Tue, 30 Jan 2024 16:19:59 GMT] Calling "devbox integrate" to setup environment
[Tue, 30 Jan 2024 16:19:59 GMT] child process closed with exit code: 1
mikenikles commented 5 months ago

I see the same output.

I also see the following when I select the Output tab, then "Extension Host":

2024-01-30 14:28:51.824 [info] ExtensionService#_doActivateExtension ms-vscode-remote.remote-ssh, startup: false, activationEvent: 'onStartupFinished', root cause: jetpack-io.devbox
2024-01-30 14:28:51.867 [info] ExtensionService#_doActivateExtension jetpack-io.devbox, startup: false, activationEvent: 'onStartupFinished'
2024-01-30 14:28:51.878 [info] ExtensionService#_doActivateExtension ms-vscode.remote-explorer, startup: false, activationEvent: 'onCommand:remote-internal.setActiveFolders'
2024-01-30 14:29:16.560 [info] ExtensionService#_doActivateExtension vscode.json-language-features, startup: false, activationEvent: 'onLanguage:jsonc'
2024-01-30 14:29:56.720 [error] undefined devbox.reopen {"value":"jetpack-io.devbox","_lower":"jetpack-io.devbox"}
aacebedo commented 5 months ago

I see the same output.

I also see the following when I select the Output tab, then "Extension Host":

2024-01-30 14:28:51.824 [info] ExtensionService#_doActivateExtension ms-vscode-remote.remote-ssh, startup: false, activationEvent: 'onStartupFinished', root cause: jetpack-io.devbox
2024-01-30 14:28:51.867 [info] ExtensionService#_doActivateExtension jetpack-io.devbox, startup: false, activationEvent: 'onStartupFinished'
2024-01-30 14:28:51.878 [info] ExtensionService#_doActivateExtension ms-vscode.remote-explorer, startup: false, activationEvent: 'onCommand:remote-internal.setActiveFolders'
2024-01-30 14:29:16.560 [info] ExtensionService#_doActivateExtension vscode.json-language-features, startup: false, activationEvent: 'onLanguage:jsonc'
2024-01-30 14:29:56.720 [error] undefined devbox.reopen {"value":"jetpack-io.devbox","_lower":"jetpack-io.devbox"}

@mikenikles On nixos ?

@mohsenari dld you check the extension on insiders build ?

mikenikles commented 5 months ago

I use Mac OS Sonoma

mohsenari commented 5 months ago

@aacebedo @mikenikles the changes I made to enable debug logs relied on a feature in devbox cli that wasn't released yet (my apologies). We now have released devbox version 0.9.0. Would you please update your devbox to newest version and retry this?

mikenikles commented 5 months ago

With devbox 0.9.0:

[Thu, 01 Feb 2024 17:20:16 GMT] Installing devbox packages
[Thu, 01 Feb 2024 17:20:16 GMT] Updating VSCode configurations
[Thu, 01 Feb 2024 17:20:16 GMT] Calling "devbox integrate" to setup environment
[Thu, 01 Feb 2024 17:20:16 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Thu, 01 Feb 2024 17:20:16 UTC] Computing devbox environment
[Thu, 01 Feb 2024 17:20:16 UTC] Signaling VSCode to close
[Thu, 01 Feb 2024 17:20:16 UTC] Re-opening VSCode in computed devbox environment
[Thu, 01 Feb 2024 17:20:16 UTC] stdout:  
 stderr: 
[Thu, 01 Feb 2024 17:20:16 UTC] exec: "code": executable file not found in $PATH
[Thu, 01 Feb 2024 17:20:16 GMT] child process closed with exit code: 1

That makes sense since Cursor doesn't have a code binary. I tried with alias code=/Applications/Cursor.app/Contents/MacOS/Cursor in my bash profile, but that didn't work.

I'll have to look into it in more detail later, but posting this for now in case anyone has ideas.

mikenikles commented 5 months ago

Fixed it with sudo ln -s /Applications/Cursor.app/Contents/MacOS/Cursor /usr/local/bin/code.

However, it gets weirder now πŸ˜•:

[Thu, 01 Feb 2024 17:37:18 GMT] Installing devbox packages
[Thu, 01 Feb 2024 17:37:18 GMT] Updating VSCode configurations
[Thu, 01 Feb 2024 17:37:18 GMT] Calling "devbox integrate" to setup environment
[Thu, 01 Feb 2024 17:37:18 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Thu, 01 Feb 2024 17:37:18 UTC] Computing devbox environment
[Thu, 01 Feb 2024 17:37:19 UTC] Signaling VSCode to close
[Thu, 01 Feb 2024 17:37:19 UTC] Re-opening VSCode in computed devbox environment
[Thu, 01 Feb 2024 17:37:19 UTC] stdout:  
 stderr: node:internal/modules/cjs/loader:1085
  throw err;
  ^

Error: Cannot find module '/Users/m/projects/x/y/z'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1082:15)
    at Module._load (node:internal/modules/cjs/loader:927:27)
    at f._load (node:electron/js2c/asar_bundle:2:13377)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:96:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.15.0

[Thu, 01 Feb 2024 17:37:19 UTC] exit status 1

Possibly no longer Devbox related πŸ€”?!

mikenikles commented 5 months ago

If I add an empty index.js to the repo root and a "main": "index.js", entry to the package.json file, I end up with this:

[Thu, 01 Feb 2024 17:42:51 GMT] Installing devbox packages
[Thu, 01 Feb 2024 17:42:51 GMT] Updating VSCode configurations
[Thu, 01 Feb 2024 17:42:51 GMT] Calling "devbox integrate" to setup environment
[Thu, 01 Feb 2024 17:42:51 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Thu, 01 Feb 2024 17:42:51 UTC] Computing devbox environment
[Thu, 01 Feb 2024 17:42:51 UTC] Signaling VSCode to close
[Thu, 01 Feb 2024 17:42:51 UTC] Re-opening VSCode in computed devbox environment

Cursor closes the current window and stays like that – no open window.

mohsenari commented 5 months ago

@mikenikles I just installed cursor. And during first setup it asks you if you want to setup cursor to open with command line "code" or "cursor" I ignore that prompt on purpose. Then once cursor is opened, I did cmd + shift + p and ran "Shell Command: Install 'Code' command" . After that I tried reopen in devbox and it worked correctly. Can you try that instead of sudo ln -s /Applications/Cursor.app/Contents/MacOS/Cursor /usr/local/bin/code?

When you see this line in the log: Re-opening VSCode in computed devbox environment, it basically means devbox cli is running the command code <path to workspace when IDE was closed>. So if cursor doesn't open, it's equivalent to running devbox shell in a terminal then inside devbox shell running code . not working properly.

mikenikles commented 5 months ago

Excellent!! That does the trick, I'm all set. Thank you πŸ™!

Funny enough, running that "Shell Command: Install 'Code' command" does the following:

ll `which code`
lrwxr-xr-x 1 root wheel 56 Feb  1 14:29 /usr/local/bin/code -> /Applications/Cursor.app/Contents/Resources/app/bin/code

Looks like my symlink pointed to the wrong file :)

Leaving this open until @aacebedo confirmed it works for him too.

aacebedo commented 5 months ago

I saw the same issue because the binary for the insiders build is code-insiders and not code. I think devbox shall add the support of code-insiders or refactor the way the IDE are handled (like providers for instance).

mohsenari commented 5 months ago

@aacebedo that's a good suggestion. I can add in settings the path to binary that opens vscode so that it can be configurable. For the time being making a symlink seems to be the workaround.

tmeckel commented 4 months ago

@mohsenari I'm experiencing a similar (or identical?) error. Host is Windows target is an Ubuntu 20.04 VM connected via SSH remote. When executing "Devbox: Reopen in Devbox shell environment", the following error is displayed.

image

The contents of the .devbox/extension.log file isn't helpful

[Wed, 28 Feb 2024 15:40:04 GMT] Installing devbox packages
[Wed, 28 Feb 2024 15:40:04 GMT] Updating VSCode configurations
[Wed, 28 Feb 2024 15:40:04 GMT] Calling "devbox integrate" to setup environment
[Wed, 28 Feb 2024 15:40:04 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Wed, 28 Feb 2024 15:40:04 UTC] Computing devbox environment
[Wed, 28 Feb 2024 15:40:04 GMT] child process closed with exit code: 0
[Wed, 28 Feb 2024 15:43:10 GMT] Installing devbox packages
[Wed, 28 Feb 2024 15:43:10 GMT] Updating VSCode configurations
[Wed, 28 Feb 2024 15:43:10 GMT] Calling "devbox integrate" to setup environment
[Wed, 28 Feb 2024 15:43:10 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Wed, 28 Feb 2024 15:43:10 UTC] Computing devbox environment
[Wed, 28 Feb 2024 15:43:10 GMT] child process closed with exit code: 0
[Wed, 28 Feb 2024 15:45:52 GMT] Installing devbox packages
[Wed, 28 Feb 2024 15:45:52 GMT] Updating VSCode configurations
[Wed, 28 Feb 2024 15:45:52 GMT] Calling "devbox integrate" to setup environment
[Wed, 28 Feb 2024 15:45:52 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Wed, 28 Feb 2024 15:45:52 UTC] Computing devbox environment
[Wed, 28 Feb 2024 15:45:52 GMT] child process closed with exit code: 0
[Wed, 28 Feb 2024 16:20:45 GMT] Installing devbox packages
[Wed, 28 Feb 2024 16:20:45 GMT] Updating VSCode configurations
[Wed, 28 Feb 2024 16:20:45 GMT] Calling "devbox integrate" to setup environment
[Wed, 28 Feb 2024 16:20:45 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Wed, 28 Feb 2024 16:20:45 UTC] Computing devbox environment
[Wed, 28 Feb 2024 16:20:45 GMT] child process closed with exit code: 0
[Wed, 28 Feb 2024 16:22:38 GMT] Installing devbox packages
[Wed, 28 Feb 2024 16:22:38 GMT] Updating VSCode configurations
[Wed, 28 Feb 2024 16:22:38 GMT] Calling "devbox integrate" to setup environment
[Wed, 28 Feb 2024 16:22:38 UTC] Devbox process initiated. Setting up communication channel with VSCode process
[Wed, 28 Feb 2024 16:22:38 UTC] Computing devbox environment
[Wed, 28 Feb 2024 16:22:38 GMT] child process closed with exit code: 0

What error log (as mentioned in the error dialog) is relevant here to pin the error?

Digged a bit into the source code. I suspect the error occurs at line 98 in integrate.go. But hard to tell which called function creates that error. Perhaps a call to nix?

image

mohsenari commented 3 months ago

@tmeckel the functionality of Reopen in devbox shell environment doesn't work when you're connected to a remote env and also when called from Windows connected to WSL as a remote env. I explained the reason for it, with a bit more details here: https://github.com/jetpack-io/devbox/issues/1781#issuecomment-2038136742

tmeckel commented 3 months ago

@mohsenari sadly to say, then devbox is not an option for me. Stick to DevContainers then.

tmeckel commented 2 months ago

@mohsenari does this might change anything? https://github.com/microsoft/vscode-docs/blob/main/remote-release-notes/v1_89.md#wsl

I know they're talking about connecting to a WSL instance when you're connected to a Windows machine via SSH. But I think they might have changed the inner workings of WSL remote support for that.

mohsenari commented 4 weeks ago

@tmeckel I need to do some testing to see if there is a way to connect to WSL from VSCode's extension. Then spawn a subprocess, compute devbox env and lastly, reopen vscode from within WSL instance.
I'll play around on my windows machine and let you know if it's possible. It would be nice to have reopen in devbox shell work in Windows.

tmeckel commented 4 weeks ago

Can't wait about your results πŸ‘πŸΌπŸ‘πŸΌ would be awesome to be able to use devbox in WSL

andr-ec commented 1 week ago

It would be amazing if at the same time it could be resolved on remove servers as well. as mentioned here: https://github.com/jetify-com/devbox/issues/1781#issuecomment-2038136742