@@ -41,6 +41,9 @@ const TRAILING_PATH_PUNCTUATION_PATTERN = /[.,;:!?]+$/;
4141// A question mark is legal in filenames; only exclude query-bearing request targets.
4242const REQUEST_ROUTE_PATTERN =
4343 / (?: ^ | [ \s " ' ` ] ) (?: G E T | H E A D | P O S T | P U T | P A T C H | D E L E T E | O P T I O N S | C O N N E C T | T R A C E | p r o x y i n g ) \s + [ " ' ` ] ? (?: \/ | [ A - Z a - z 0 - 9 _ - ] + \/ ) [ ^ \s ? ] * \? \S * / g;
44+ // The tail of `redis://host/0` or `file:///a.mjs` is not a path. One-letter schemes stay drives,
45+ // a diff's `+` or `-` may lead, and the lookbehind keeps runs from being rescanned at every suffix.
46+ const SCHEME_URL_PATTERN = / (?< ! [ A - Z a - z \d + . - ] ) [ + - ] ? [ A - Z a - z ] [ A - Z a - z \d + . - ] + : \/ \/ [ ^ \s " ' ` < > ] + / gu;
4447
4548function trimClosingDelimiters ( value : string , kind : TerminalLinkKind ) : string {
4649 let output = value . replace (
@@ -110,10 +113,10 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
110113 const promptMatches : TerminalLinkMatch [ ] = promptPath
111114 ? [ { kind : "path" , text : promptPath , start : 3 , end : 3 + promptPath . length } ]
112115 : [ ] ;
113- const requestRoutes = Array . from ( line . matchAll ( REQUEST_ROUTE_PATTERN ) , ( match ) => ( {
114- start : match . index ,
115- end : match . index + match [ 0 ] . length ,
116- } ) ) ;
116+ const nonPathRanges = Array . from (
117+ [ ... line . matchAll ( REQUEST_ROUTE_PATTERN ) , ... line . matchAll ( SCHEME_URL_PATTERN ) ] ,
118+ ( match ) => ( { start : match . index , end : match . index + match [ 0 ] . length } ) ,
119+ ) ;
117120 const urlMatches = collectMatches ( line , "url" , URL_PATTERN , promptMatches ) ;
118121 const quotedMatches = collectMatches ( line , "path" , QUOTED_FILE_PATH_PATTERN , [
119122 ...promptMatches ,
@@ -126,7 +129,7 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
126129 ] ) ;
127130 return [ ...promptMatches , ...urlMatches , ...quotedMatches , ...pathMatches ]
128131 . filter (
129- ( match ) => match . kind === "url" || ! requestRoutes . some ( ( route ) => overlaps ( match , route ) ) ,
132+ ( match ) => match . kind === "url" || ! nonPathRanges . some ( ( range ) => overlaps ( match , range ) ) ,
130133 )
131134 . toSorted ( ( a , b ) => a . start - b . start ) ;
132135}
0 commit comments