Repository: vscode
Issue: Terminal launcher: local vs remote file path confusion
Labels: bug,remote,terminal-process

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Not relevant. Obviously the SSH extension has to be active for the ssh connection.

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.66.2 and 1.65.2 (so not a new issue)
- OS Version: Windows/Linux

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](https://user-images.githubusercontent.com/52323224/165132884-330f06cf-f754-48c4-8f80-33096faf80ee.png)

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](https://user-images.githubusercontent.com/52323224/165135739-434f62c7-8eb8-4ed4-89a2-dcd04f245e14.png)

2. Connect to the remote Linux box using the SSH extension
 
3. Open some directory on the remote Linux box in VS Code

**/home/\<user\>/dir/**

4. 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](https://user-images.githubusercontent.com/52323224/165136166-5ac70487-6a84-4761-b132-a2ce1afe5b03.png)

5. 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](https://user-images.githubusercontent.com/52323224/165136463-fb81808a-b31a-45ba-b081-4127c974f8ba.png)

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.

3. 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.