@@ -46,6 +46,9 @@ const REQUEST_ROUTE_PATTERN =
4646// The tail of `redis://host/0` or `file:///a.mjs` is not a path. One-letter schemes stay drives,
4747// a diff's `+` or `-` may lead, and the lookbehind keeps runs from being rescanned at every suffix.
4848const SCHEME_URL_PATTERN = / (?< ! [ A - Z a - z \d + . - ] ) [ + - ] ? [ A - Z a - z ] [ A - Z a - z \d + . - ] + : \/ \/ [ ^ \s " ' ` < > ] + / gu;
49+ // Nor is the tail of an SCP-style Git remote such as `[email protected] :acme/widgets.git`. Only a 50+ // path wholly inside the tail is dropped, so `src/[email protected] :12:3` keeps its link. 51+ const SCP_REMOTE_PATTERN = / (?< ! [ \w . @ - ] ) [ \w . - ] + @ [ \w . - ] + : [ ^ \s " ' ` < > ] + / gu;
4952
5053function trimClosingDelimiters ( value : string , kind : TerminalLinkKind ) : string {
5154 let output = value . replace (
@@ -119,6 +122,10 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
119122 [ ...line . matchAll ( REQUEST_ROUTE_PATTERN ) , ...line . matchAll ( SCHEME_URL_PATTERN ) ] ,
120123 ( match ) => ( { start : match . index , end : match . index + match [ 0 ] . length } ) ,
121124 ) ;
125+ const remoteTails = Array . from ( line . matchAll ( SCP_REMOTE_PATTERN ) , ( match ) => ( {
126+ start : match . index + match [ 0 ] . indexOf ( ":" ) + 1 ,
127+ end : match . index + match [ 0 ] . length ,
128+ } ) ) ;
122129 const urlMatches = collectMatches ( line , "url" , URL_PATTERN , promptMatches ) ;
123130 const quotedMatches = collectMatches ( line , "path" , QUOTED_FILE_PATH_PATTERN , [
124131 ...promptMatches ,
@@ -131,7 +138,10 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
131138 ] ) ;
132139 return [ ...promptMatches , ...urlMatches , ...quotedMatches , ...pathMatches ]
133140 . filter (
134- ( match ) => match . kind === "url" || ! nonPathRanges . some ( ( range ) => overlaps ( match , range ) ) ,
141+ ( match ) =>
142+ match . kind === "url" ||
143+ ( ! nonPathRanges . some ( ( range ) => overlaps ( match , range ) ) &&
144+ ! remoteTails . some ( ( tail ) => match . start >= tail . start && match . end <= tail . end ) ) ,
135145 )
136146 . toSorted ( ( a , b ) => a . start - b . start ) ;
137147}
0 commit comments