File tree 2 files changed +30
-9
lines changed
2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import { Inbox } from "./inbox"
19
19
import { SSHConfig , SSHValues , mergeSSHConfigValues } from "./sshConfig"
20
20
import { computeSSHProperties , sshSupportsSetEnv } from "./sshSupport"
21
21
import { Storage } from "./storage"
22
- import { AuthorityPrefix , expandPath , parseRemoteAuthority } from "./util"
22
+ import { AuthorityPrefix , expandPath , findPort , parseRemoteAuthority } from "./util"
23
23
import { WorkspaceMonitor } from "./workspaceMonitor"
24
24
25
25
export interface RemoteDetails extends vscode . Disposable {
@@ -793,14 +793,7 @@ export class Remote {
793
793
// this to find the SSH process that is powering this connection. That SSH
794
794
// process will be logging network information periodically to a file.
795
795
const text = await fs . readFile ( logPath , "utf8" )
796
- const matches = text . match ( / - > s o c k s P o r t ( \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 )
804
797
if ( ! port ) {
805
798
return
806
799
}
Original file line number Diff line number Diff line change @@ -13,6 +13,34 @@ export interface AuthorityParts {
13
13
// they should be handled by this extension.
14
14
export const AuthorityPrefix = "coder-vscode"
15
15
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 = / (?: - > s o c k s P o r t ( \d + ) - > | = > ( \d + ) \( s o c k s \) = > | b e t w e e n l o c a l p o r t ( \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
+
16
44
/**
17
45
* Given an authority, parse into the expected parts.
18
46
*
You can’t perform that action at this time.
0 commit comments