microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.52k stars 28.99k forks source link

Terminal launcher: local vs remote file path confusion #148066

Open gk-devhub opened 2 years ago

gk-devhub commented 2 years ago

Does this issue occur when all extensions are disabled?: Not relevant. Obviously the SSH extension has to be active for the ssh connection.

This is an edge case bug that manifests itself when a local file (e.g. local ssh config file on Windows) is open in the VS Code editor while the user is logged into a remote Linux box using the MS ssh remote extension. If at this point the user tries to launch the terminal window with Ctrl-' and "Terminal > Integrated: Cwd" is set to ${fileDirname}, the following error message is displayed

image

because the Terminal Launcher gets confused about the local Windows directory path

C:\Users\<win_user>\.ssh\

and the remote Linux directory path

/home/\<user>/dir/

Basically the Terminal Launcher assumes that the local Windows file path of the open ssh config file

C:\Users\<win_user>\.ssh\config

is a relative file path on the remote Linux machine and hence it concatenates the local Windows directory path to the remote Linux directory path and hence it tries to launch a terminal in the directory

/home/\<user>/dir/c:/Users/\<win_user>/.ssh/

which doesn't exist on the remote Linux box and hence the error message.

The underlying problem is that the Terminal Launcher's assumption about the open file being a remote file is not true in the above special case when the local ssh config file is open in the editor.

Steps to Reproduce:

  1. Set "Terminal > Integrated: Cwd" to ${fileDirname}

image

  1. Connect to the remote Linux box using the SSH extension

  2. Open some directory on the remote Linux box in VS Code

/home/\<user>/dir/

  1. Open the local ssh config file (that is used for the remote connection)

C:\Users\<win_user>\.ssh\config

via the Remote Explorer's config widget

image

  1. While the local ssh config file is the active editor window, try to launch the Terminal window using Ctrl-'. The following error message will be displayed

image

where \<user> is the Linux user on the remote Linux box and \<win_user> is the local user on the Windows ssh client side.

Note: since this is a local vs remote file path confusion issue, hence the type of the local OS doesn't matter. So although I observed this behaviour in the case of a Windows client, but the issue should be observable from a Linux or a Mac client as well provided that the path to the local ssh config file directory doesn't exist on the remote Linux machine (meaning that it's not the default local /home/\<user>/.ssh/ directory on the Linux/Mac client).

Solution options:

  1. If VS Code can launch/handle remote and local terminals at the same time, then it should launch a local terminal (a DOS/PowerShell terminal in the above particular case) in the directory C:\Users\<win_user>\.ssh\

  2. If VS Code can't launch/handle local and remote terminals at the same time, then it should launch a remote terminal in the same directory that the last remote terminal was launched for e.g.

/home/\<user>/dir/\<last_terminal_subdir>

note that this might be a subdir in the remote workspace, and not necessarily the root dir of the workspace.

  1. However, if the last launch dir is not tracked by VS Code, then it should just launch a remote terminal in the root of the dev folder

/home/\<user>/dir/

The first solution is the preferred solution if available (for the sake of consistency), with the other 2 being fallback options.

Tyriar commented 1 year ago

Relative cwds should get resolved properly.

Tyriar commented 1 year ago

These issues are all closely related: