microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.6k stars 273 forks source link

Allow to open vscode:// urls in remote #4779

Open jaredp opened 3 years ago

jaredp commented 3 years ago

Steps to Reproduce:

  1. Open a project in VSCode remote that has a file at absolute path /my/file/path.js
  2. Click on a link (in Chrome, on Mac machine running vscode) with url "vscode://file/my/file/path.js"
  3. Get error modal in open VSCode window with title "Path does not exist", body: "The path '/my/file/path.js' does not seem to exist anymore on disk."

Does this issue occur when you try this locally?: No Does this issue occur when you try this locally and all extensions are disabled?: No

This is following the vscode:// schema feature described in https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls

chrmarti commented 3 years ago

You'd need a vscode-remote://.../my/file/path.js URL. The difficulty is the authority part (...), that is internal to the Remote-SSH extension.

jaredp commented 3 years ago

I can figure out the ... part, but Chrome is giving me Failed to launch 'vscode-remote://ssh+devserver/my/file/path' because the scheme does not have a registered handler.

When I try vscode://vscode-remote/ssh-remote+devserver/my/file/path, I think I run into https://github.com/microsoft/vscode/issues/108257.

However, vscode://file/my/file/path.js does route to the right vscode remote window, whose workspace root is /my/file on the remote host. By comparison vscode://file/other/file/path.js (outside the vscode remote window's workspace root) tries to open the file from the local disk in a new window.

So it looks like vscode's already routing the open-file request to the right window/workspace. Current behavior is broken because vscode's confused as to whether it's trying to open remote or local, and will thus always error.

Timmmm commented 2 years ago

This appears to be solved now, however the URL schema is still completely undocumented and as far as I can tell there's no way to discover it from existing open files.

I eventually gave up trying to figure it out and just looked at what other people have done.

It seems to be:

Note the row and column numbers are required for files, otherwise it assumes it is a directory and creates a new instance of VSCode. If you just add :1:1 unconditionally then it won't open folders successfully so unfortunately you do need to know in advance if the target is a file or a folder. Also if you do open a folder it replaces an existing instance of VSCode rather than opening a new one.

So yeah it basically doesn't work very well for folders but it works for files!

alejoar commented 1 year ago

This appears to be solved now, however the URL schema is still completely undocumented and as far as I can tell there's no way to discover it from existing open files.

I eventually gave up trying to figure it out and just looked at what other people have done.

It seems to be:

  • vscode://vscode-remote/wsl+CONTAINER_NAME/path/to/file
  • vscode://vscode-remote/ssh-remote+[USER@]HOST[:PORT]/path/to/file:ROW:COL

Note the row and column numbers are required for files, otherwise it assumes it is a directory and creates a new instance of VSCode. If you just add :1:1 unconditionally then it won't open folders successfully so unfortunately you do need to know in advance if the target is a file or a folder. Also if you do open a folder it replaces an existing instance of VSCode rather than opening a new one.

So yeah it basically doesn't work very well for folders but it works for files!

This worked for me when using locatorJS

pjeby commented 1 year ago

Additional bit of info: you can get the remote to open in a new window by adding ?windowId=_blank to the end of the URL.

markNZed commented 8 months ago

I would like to open links on a remote dev container (docker container) No doubt, if this is possible, it requires something magical in the URL as there is an SSH to the remote machine and then a connection to the remote container. Any help with this is much appreciated - ideally I want a link in a MD file to open another MD file in a new tab (I do not want to launch a new VSCode instance). Thanks

rmGFW commented 1 month ago

You'd need a vscode-remote://.../my/file/path.js URL. The difficulty is the authority part (...), that is internal to the Remote-SSH extension.

can we get authority use extension api