6
  • Version of VS Code: Visual Studio Code 1.48.2
  • What type of remote connection: SSH
  • operating system: Ubuntu 16.04.7 LTS (Xenial Xerus)
  • remote operating system: Ubuntu 16.04.7 LTS (Xenial Xerus)

I have a remote SSH connection set up between two machines, and it appears great. I can navigate the directory structure through the integrated terminal, open a remote workspace, and open files using CTRL+P to search for files in the work space. However, if I try to open a file from the remote system via the integrated terminal to my local instance of VSCode, nothing happens. code file.txt is a no-op, when instead I'd like to open the file in my current local window.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Any more info in `Remote-SSH: Show Log` ? – Luuk Sep 06 '20 at 09:25
  • Thanks for the reply. Unfortunately no. It just says ```"Resolved "ssh-remote+" to "IPaddress" [Forwarding server ] Got connection 1 [Forwarding server ] Got connection 2 [Forwarding server ] Got connection 3``` It's as if it thinks it is successfully opening it in a different window. – Duncan Miller Sep 08 '20 at 04:01

2 Answers2

1

There are many potential reasons which could prevent VSCode remote ssh integrated terminal from being able to open files via "code" command.

Quick Fix:

To get vs-code to open remotely then try add this line in your .bashrc

alias code="${HOME}/.vscode-server/bin/$(ls -t1 ${HOME}/.vscode-server/bin | head -n 1)/bin/remote-cli/code"

Now you can open a file using code -r filename.txt to open a file in the integrated terminal.
The -r parameter re-uses the current window.

More verbose Explanation:

From an integrated VS-Code terminal on the remote host:


# run this and verify the current user, show the .sock file and permissions are ok. 
echo $VSCODE_IPC_HOOK_CLI

# also check path and make sure you've got some entry to ~/.vscode-server should appear:
echo $PATH

I'm not perfectly sure the best/proper way for the .vscode-server path to get set by the integrated terminal.

I think it's related to the terminal.defaultProfile setting but I'm not 100% and may just be broken in my insider preview.

However I'm 100% sure if the ~/.vscode-server/bin/*/bin/remote-cli doesn't appear in the path it won't work, you can try to add it:

export PATH=$PATH:"~/.vscode-server/bin/**/bin/remote-cli"

then the command code -r filename.txt will open the file in the integrated editor, however I think the alias solution in Quick Fix is easier/better.

Brian Horakh
  • 329
  • 4
  • 12
-1

when I run code -r filename, I get error message

Unable to connect to VS Code server.
Error in request

it turns out I shouldn't use tmux, after I exit tmux, it works fine.

but I haven't figure out how to make this work in tmux

Jackiexiao
  • 832
  • 9
  • 15