Skip to content

Commit e682d97

Browse files
committed
feat: add connection status indicator to vscode windows & windsurf
1 parent b2898cd commit e682d97

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/remote.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Inbox } from "./inbox"
1919
import { SSHConfig, SSHValues, mergeSSHConfigValues } from "./sshConfig"
2020
import { computeSSHProperties, sshSupportsSetEnv } from "./sshSupport"
2121
import { Storage } from "./storage"
22-
import { AuthorityPrefix, expandPath, parseRemoteAuthority } from "./util"
22+
import { AuthorityPrefix, expandPath, findPort, parseRemoteAuthority } from "./util"
2323
import { WorkspaceMonitor } from "./workspaceMonitor"
2424

2525
export interface RemoteDetails extends vscode.Disposable {
@@ -793,14 +793,7 @@ export class Remote {
793793
// this to find the SSH process that is powering this connection. That SSH
794794
// process will be logging network information periodically to a file.
795795
const text = await fs.readFile(logPath, "utf8")
796-
const matches = text.match(/-> socksPort (\d+) ->/)
797-
if (!matches) {
798-
return
799-
}
800-
if (matches.length < 2) {
801-
return
802-
}
803-
const port = Number.parseInt(matches[1])
796+
const port = await findPort(text)
804797
if (!port) {
805798
return
806799
}

src/util.ts

+28
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ export interface AuthorityParts {
1313
// they should be handled by this extension.
1414
export const AuthorityPrefix = "coder-vscode"
1515

16+
// `ms-vscode-remote.remote-ssh`: `-> socksPort <port> ->`
17+
// `codeium.windsurf-remote-openssh`: `=> <port>(socks) =>`
18+
// Windows `ms-vscode-remote.remote-ssh`: `between local port <port>`
19+
export const RemoteSSHLogPortRegex = /(?:-> socksPort (\d+) ->|=> (\d+)\(socks\) =>|between local port (\d+))/;
20+
21+
22+
/**
23+
* Given the contents of a Remote - SSH log file, find a port number used by the
24+
* SSH process. This is typically the socks port, but the local port works too.
25+
*
26+
* Returns null if no port is found.
27+
*/
28+
export async function findPort(text: string): Promise<number | null> {
29+
const matches = text.match(RemoteSSHLogPortRegex)
30+
if (!matches) {
31+
return null
32+
}
33+
if (matches.length < 2) {
34+
return null
35+
}
36+
const portStr = matches[1] || matches[2] || matches[3];
37+
if (!portStr) {
38+
return null
39+
}
40+
41+
return Number.parseInt(portStr);
42+
}
43+
1644
/**
1745
* Given an authority, parse into the expected parts.
1846
*

0 commit comments

Comments
 (0)