Skip to content

fix: add connection status indicator to vscode windows, windsurf, open-remote-ssh #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ export interface AuthorityParts {
// they should be handled by this extension.
export const AuthorityPrefix = "coder-vscode"

// `ms-vscode-remote.remote-ssh`: `-> socksPort <port> ->`
// `codeium.windsurf-remote-openssh`, `jeanp413.open-remote-ssh`: `=> <port>(socks) =>`
// Windows `ms-vscode-remote.remote-ssh`: `between local port <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<number | null> {
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.
*
Expand Down