Skip to content

Commit

Permalink
Fix #61
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Mar 1, 2023
1 parent ec66e79 commit 25f501b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/authResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class RemoteSSHResolver implements vscode.RemoteAuthorityResolver, vscode

this.logger.info(`Resolving ssh remote authority '${authority}' (attemp #${context.resolveAttempt})`);

const sshDest = SSHDestination.parse(dest);
const sshDest = SSHDestination.parseEncoded(dest);

// It looks like default values are not loaded yet when resolving a remote,
// so let's hardcode the default values here
Expand Down
4 changes: 3 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
import { getRemoteAuthority } from './authResolver';
import { getSSHConfigPath } from './ssh/sshConfig';
import { exists as fileExists } from './common/files';
import SSHDestination from './ssh/sshDestination';

export async function promptOpenRemoteSSHWindow(reuseWindow: boolean) {
const host = await vscode.window.showInputBox({
Expand All @@ -13,7 +14,8 @@ export async function promptOpenRemoteSSHWindow(reuseWindow: boolean) {
return;
}

openRemoteSSHWindow(host, reuseWindow);
const sshDest = new SSHDestination(host);
openRemoteSSHWindow(sshDest.toEncodedString(), reuseWindow);
}

export function openRemoteSSHWindow(host: string, reuseWindow: boolean) {
Expand Down
4 changes: 2 additions & 2 deletions src/hostTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ export class HostTreeDataProvider extends Disposable implements vscode.TreeDataP

private async openRemoteSSHWindow(element: HostItem, reuseWindow: boolean) {
const sshDest = new SSHDestination(element.hostname);
openRemoteSSHWindow(sshDest.toString(), reuseWindow);
openRemoteSSHWindow(sshDest.toEncodedString(), reuseWindow);
}

private async openRemoteSSHLocationWindow(element: HostLocationItem, reuseWindow: boolean) {
const sshDest = new SSHDestination(element.hostname);
openRemoteSSHLocationWindow(sshDest.toString(), element.path, reuseWindow);
openRemoteSSHLocationWindow(sshDest.toEncodedString(), element.path, reuseWindow);
}
}
4 changes: 2 additions & 2 deletions src/remoteLocationHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export function getRemoteWorkspaceLocationData(): [string, string] | undefined {
let location = vscode.workspace.workspaceFile;
if (location && location.scheme === 'vscode-remote' && location.authority.startsWith(REMOTE_SSH_AUTHORITY) && location.path.endsWith('.code-workspace')) {
const [, host] = location.authority.split('+');
const sshDest = SSHDestination.parse(host);
const sshDest = SSHDestination.parseEncoded(host);
return [sshDest.hostname, location.path];
}

location = vscode.workspace.workspaceFolders?.[0].uri;
if (location && location.scheme === 'vscode-remote' && location.authority.startsWith(REMOTE_SSH_AUTHORITY)) {
const [, host] = location.authority.split('+');
const sshDest = SSHDestination.parse(host);
const sshDest = SSHDestination.parseEncoded(host);
return [sshDest.hostname, location.path];
}

Expand Down
14 changes: 14 additions & 0 deletions src/ssh/sshDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ export default class SSHDestination {
}
return result;
}

// vscode.uri implementation lowercases the authority, so when reopen or restore
// a remote session from the recently openend list the connection fails
static parseEncoded(dest: string): SSHDestination {
return SSHDestination.parse(dest.replace(/\\x([0-9a-f]{2})/g, (_, charCode) => String.fromCharCode(parseInt(charCode, 16))));
}

toEncodedString(): string {
let result = this.toString();
if (result.toLowerCase() !== result) {
return result.replace(/[A-Z]/g, (ch) => `\\x${ch.charCodeAt(0).toString(16).toLowerCase()}`);
}
return result;
}
}

0 comments on commit 25f501b

Please # to comment.