From df1474c11e894eb9be58492b8953f19e04c60f9d Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 1 May 2025 15:52:31 +1000 Subject: [PATCH 1/3] feat: add connection status indicator to vscode windows & windsurf --- src/remote.ts | 11 ++--------- src/util.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/remote.ts b/src/remote.ts index 3ff8f6e3..540525ed 100644 --- a/src/remote.ts +++ b/src/remote.ts @@ -19,7 +19,7 @@ import { Inbox } from "./inbox" import { SSHConfig, SSHValues, mergeSSHConfigValues } from "./sshConfig" import { computeSSHProperties, sshSupportsSetEnv } from "./sshSupport" import { Storage } from "./storage" -import { AuthorityPrefix, expandPath, parseRemoteAuthority } from "./util" +import { AuthorityPrefix, expandPath, findPort, parseRemoteAuthority } from "./util" import { WorkspaceMonitor } from "./workspaceMonitor" export interface RemoteDetails extends vscode.Disposable { @@ -793,14 +793,7 @@ export class Remote { // this to find the SSH process that is powering this connection. That SSH // process will be logging network information periodically to a file. const text = await fs.readFile(logPath, "utf8") - const matches = text.match(/-> socksPort (\d+) ->/) - if (!matches) { - return - } - if (matches.length < 2) { - return - } - const port = Number.parseInt(matches[1]) + const port = await findPort(text) if (!port) { return } diff --git a/src/util.ts b/src/util.ts index 8253f152..0d8ac675 100644 --- a/src/util.ts +++ b/src/util.ts @@ -13,6 +13,34 @@ export interface AuthorityParts { // they should be handled by this extension. export const AuthorityPrefix = "coder-vscode" +// `ms-vscode-remote.remote-ssh`: `-> socksPort ->` +// `codeium.windsurf-remote-openssh`: `=> (socks) =>` +// Windows `ms-vscode-remote.remote-ssh`: `between local port ` +export const RemoteSSHLogPortRegex = /(?:-> socksPort (\d+) ->|=> (\d+)\(socks\) =>|between local port (\d+))/; + + +/** + * Given the contents of a Remote - SSH log file, find a port number used by the + * SSH process. This is typically the socks port, but the local port works too. + * + * Returns null if no port is found. + */ +export async function findPort(text: string): Promise { + const matches = text.match(RemoteSSHLogPortRegex) + if (!matches) { + return null + } + if (matches.length < 2) { + return null + } + const portStr = matches[1] || matches[2] || matches[3]; + if (!portStr) { + return null + } + + return Number.parseInt(portStr); +} + /** * Given an authority, parse into the expected parts. * From 899d2b49808f301b0f1672e167315d51317a3463 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 1 May 2025 15:55:18 +1000 Subject: [PATCH 2/3] lint --- src/util.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/util.ts b/src/util.ts index 0d8ac675..851d8910 100644 --- a/src/util.ts +++ b/src/util.ts @@ -16,8 +16,7 @@ export const AuthorityPrefix = "coder-vscode" // `ms-vscode-remote.remote-ssh`: `-> socksPort ->` // `codeium.windsurf-remote-openssh`: `=> (socks) =>` // Windows `ms-vscode-remote.remote-ssh`: `between local port ` -export const RemoteSSHLogPortRegex = /(?:-> socksPort (\d+) ->|=> (\d+)\(socks\) =>|between local port (\d+))/; - +export const RemoteSSHLogPortRegex = /(?:-> socksPort (\d+) ->|=> (\d+)\(socks\) =>|between local port (\d+))/ /** * Given the contents of a Remote - SSH log file, find a port number used by the @@ -33,12 +32,12 @@ export async function findPort(text: string): Promise { if (matches.length < 2) { return null } - const portStr = matches[1] || matches[2] || matches[3]; + const portStr = matches[1] || matches[2] || matches[3] if (!portStr) { return null } - return Number.parseInt(portStr); + return Number.parseInt(portStr) } /** From 198cd463b3b2c674fa1f85b2d9f77dc77d459356 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 1 May 2025 21:08:49 +1000 Subject: [PATCH 3/3] update comment --- src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 851d8910..87707210 100644 --- a/src/util.ts +++ b/src/util.ts @@ -14,7 +14,7 @@ export interface AuthorityParts { export const AuthorityPrefix = "coder-vscode" // `ms-vscode-remote.remote-ssh`: `-> socksPort ->` -// `codeium.windsurf-remote-openssh`: `=> (socks) =>` +// `codeium.windsurf-remote-openssh`, `jeanp413.open-remote-ssh`: `=> (socks) =>` // Windows `ms-vscode-remote.remote-ssh`: `between local port ` export const RemoteSSHLogPortRegex = /(?:-> socksPort (\d+) ->|=> (\d+)\(socks\) =>|between local port (\d+))/