@@ -46,7 +46,7 @@ export interface AutolinkReference {
4646export interface Autolink extends AutolinkReference {
4747 provider ?: ProviderReference ;
4848 id : string ;
49- index : number ;
49+ index ? : number ;
5050
5151 tokenize ?:
5252 | ( (
@@ -225,8 +225,13 @@ export class Autolinks implements Disposable {
225225 if ( a . index === 0 ) {
226226 return - 1 ;
227227 }
228+
228229 // maybe it worths to use some weight function instead.
229- return b . prefix . length - a . prefix . length || b . id . length - a . id . length || - ( b . index - a . index ) ;
230+ return (
231+ b . prefix . length - a . prefix . length ||
232+ b . id . length - a . id . length ||
233+ ( b . index != null && a . index != null ? - ( b . index - a . index ) : 0 )
234+ ) ;
230235 }
231236
232237 private async getRefsets ( remote ?: GitRemote , options ?: { excludeCustom ?: boolean } ) {
@@ -260,10 +265,11 @@ export class Autolinks implements Disposable {
260265 let num ;
261266 for ( const [ provider , refs ] of refsets ) {
262267 for ( const ref of refs ) {
263- if ( ! isCacheable ( ref ) ) {
264- continue ;
265- }
266- if ( ref . type === 'pullrequest' || ( ref . referenceType && ref . referenceType !== 'branchName' ) ) {
268+ if (
269+ ! isCacheable ( ref ) ||
270+ ref . type === 'pullrequest' ||
271+ ( ref . referenceType && ref . referenceType !== 'branchName' )
272+ ) {
267273 continue ;
268274 }
269275
@@ -277,8 +283,9 @@ export class Autolinks implements Disposable {
277283 let index = match . value . index ;
278284 const linkUrl = ref . url ?. replace ( numRegex , num ) ;
279285 // strange case (I would say synthetic), but if we parse the link twice, use the most relevant of them
280- if ( autolinks . has ( linkUrl ) ) {
281- index = Math . min ( index , autolinks . get ( linkUrl ) ! . index ) ;
286+ const existingIndex = autolinks . get ( linkUrl ) ?. index ;
287+ if ( existingIndex != null ) {
288+ index = Math . min ( index , existingIndex ) ;
282289 }
283290 autolinks . set ( linkUrl , {
284291 ...ref ,
@@ -327,7 +334,7 @@ export class Autolinks implements Disposable {
327334 let num ;
328335 for ( const [ provider , refs ] of refsets ) {
329336 for ( const ref of refs ) {
330- if ( ! isCacheable ( ref ) ) {
337+ if ( ! isCacheable ( ref ) || ( ref . referenceType && ref . referenceType !== 'commitMessage' ) ) {
331338 if ( isDynamic ( ref ) ) {
332339 ref . parse ( message , autolinks ) ;
333340 }
0 commit comments