@@ -7,6 +7,7 @@ import type { Container } from '../container';
77import type { GitRemote } from '../git/models/remote' ;
88import type { RemoteProviderId } from '../git/remotes/remoteProvider' ;
99import { getIssueOrPullRequestHtmlIcon , getIssueOrPullRequestMarkdownIcon } from '../git/utils/-webview/icons' ;
10+ import type { ConfiguredIntegrationsChangeEvent } from '../plus/integrations/authentication/configuredIntegrationService' ;
1011import type { HostingIntegration , Integration , IssueIntegration } from '../plus/integrations/integration' ;
1112import { IntegrationBase } from '../plus/integrations/integration' ;
1213import { remoteProviderIdToIntegrationId } from '../plus/integrations/integrationService' ;
@@ -18,6 +19,7 @@ import { join, map } from '../system/iterable';
1819import { Logger } from '../system/logger' ;
1920import { escapeMarkdown } from '../system/markdown' ;
2021import { getSettledValue , isPromise } from '../system/promise' ;
22+ import { PromiseCache } from '../system/promiseCache' ;
2123import { capitalize , encodeHtmlWeak , getSuperscript } from '../system/string' ;
2224import type {
2325 Autolink ,
@@ -26,24 +28,28 @@ import type {
2628 EnrichedAutolink ,
2729 MaybeEnrichedAutolink ,
2830 RefSet ,
29- } from './autolinks.utils ' ;
31+ } from './models/ autolinks' ;
3032import {
3133 ensureCachedRegex ,
3234 getAutolinks ,
3335 getBranchAutolinks ,
3436 isDynamic ,
3537 numRegex ,
3638 supportedAutolinkIntegrations ,
37- } from './autolinks.utils' ;
39+ } from './utils/-webview/ autolinks.utils' ;
3840
3941const emptyAutolinkMap = Object . freeze ( new Map < string , Autolink > ( ) ) ;
4042
41- export class Autolinks implements Disposable {
42- protected _disposable : Disposable | undefined ;
43+ export class AutolinksProvider implements Disposable {
44+ private _disposable : Disposable | undefined ;
4345 private _references : CacheableAutolinkReference [ ] = [ ] ;
46+ private _refsetCache = new PromiseCache < string | undefined , RefSet [ ] > ( { accessTTL : 1000 * 60 * 60 } ) ;
4447
4548 constructor ( private readonly container : Container ) {
46- this . _disposable = Disposable . from ( configuration . onDidChange ( this . onConfigurationChanged , this ) ) ;
49+ this . _disposable = Disposable . from (
50+ configuration . onDidChange ( this . onConfigurationChanged , this ) ,
51+ container . integrations . onDidChangeConfiguredIntegrations ( this . onConfiguredIntegrationsChanged , this ) ,
52+ ) ;
4753
4854 this . setAutolinksFromConfig ( ) ;
4955 }
@@ -55,9 +61,14 @@ export class Autolinks implements Disposable {
5561 private onConfigurationChanged ( e ?: ConfigurationChangeEvent ) {
5662 if ( configuration . changed ( e , 'autolinks' ) ) {
5763 this . setAutolinksFromConfig ( ) ;
64+ this . _refsetCache . clear ( ) ;
5865 }
5966 }
6067
68+ private onConfiguredIntegrationsChanged ( _e : ConfiguredIntegrationsChangeEvent ) {
69+ this . _refsetCache . clear ( ) ;
70+ }
71+
6172 private setAutolinksFromConfig ( ) {
6273 const autolinks = configuration . get ( 'autolinks' ) ;
6374 // Since VS Code's configuration objects are live we need to copy them to avoid writing back to the configuration
@@ -118,57 +129,40 @@ export class Autolinks implements Disposable {
118129 }
119130
120131 /** Collects custom-configured autolink references into @param refsets */
121- private collectCustomAutolinks (
122- remote : GitRemote | undefined ,
123- refsets : RefSet [ ] ,
124- options ?: { excludeCustom ?: boolean } ,
125- ) : void {
126- if ( this . _references . length && ( remote ?. provider == null || ! options ?. excludeCustom ) ) {
132+ private collectCustomAutolinks ( refsets : RefSet [ ] ) : void {
133+ if ( this . _references . length ) {
127134 refsets . push ( [ undefined , this . _references ] ) ;
128135 }
129136 }
130137
131- private async getRefSets ( remote ?: GitRemote , options ?: { excludeCustom ?: boolean } ) {
132- const refsets : RefSet [ ] = [ ] ;
138+ private async getRefSets ( remote ?: GitRemote ) {
139+ return this . _refsetCache . get ( remote ?. remoteKey , async ( ) => {
140+ const refsets : RefSet [ ] = [ ] ;
133141
134- await this . collectIntegrationAutolinks ( remote , refsets ) ;
135- this . collectRemoteAutolinks ( remote , refsets ) ;
136- this . collectCustomAutolinks ( remote , refsets , options ) ;
142+ await this . collectIntegrationAutolinks ( remote , refsets ) ;
143+ this . collectRemoteAutolinks ( remote , refsets ) ;
144+ this . collectCustomAutolinks ( refsets ) ;
137145
138- return refsets ;
146+ return refsets ;
147+ } ) ;
139148 }
140149
141150 /** @returns A sorted list of autolinks. the first match is the most relevant */
142- async getBranchAutolinks (
143- branchName : string ,
144- remote ?: GitRemote ,
145- options ?: { excludeCustom ?: boolean } ,
146- ) : Promise < Map < string , Autolink > > {
147- const refsets = await this . getRefSets ( remote , options ) ;
151+ async getBranchAutolinks ( branchName : string , remote ?: GitRemote ) : Promise < Map < string , Autolink > > {
152+ const refsets = await this . getRefSets ( remote ) ;
148153 if ( refsets . length === 0 ) return emptyAutolinkMap ;
149154
150155 return getBranchAutolinks ( branchName , refsets ) ;
151156 }
152157
153- async getAutolinks ( message : string , remote ?: GitRemote ) : Promise < Map < string , Autolink > > ;
154- async getAutolinks (
155- message : string ,
156- remote : GitRemote ,
157- // eslint-disable-next-line @typescript-eslint/unified-signatures
158- options ?: { excludeCustom ?: boolean } ,
159- ) : Promise < Map < string , Autolink > > ;
160- @debug < Autolinks [ 'getAutolinks' ] > ( {
158+ @debug < AutolinksProvider [ 'getAutolinks' ] > ( {
161159 args : {
162160 0 : '<message>' ,
163161 1 : false ,
164162 } ,
165163 } )
166- async getAutolinks (
167- message : string ,
168- remote ?: GitRemote ,
169- options ?: { excludeCustom ?: boolean } ,
170- ) : Promise < Map < string , Autolink > > {
171- const refsets = await this . getRefSets ( remote , options ) ;
164+ async getAutolinks ( message : string , remote ?: GitRemote ) : Promise < Map < string , Autolink > > {
165+ const refsets = await this . getRefSets ( remote ) ;
172166 if ( refsets . length === 0 ) return emptyAutolinkMap ;
173167
174168 return getAutolinks ( message , refsets ) ;
@@ -191,7 +185,7 @@ export class Autolinks implements Disposable {
191185 autolinks : Map < string , Autolink > ,
192186 remote : GitRemote | undefined ,
193187 ) : Promise < Map < string , EnrichedAutolink > | undefined > ;
194- @debug < Autolinks [ 'getEnrichedAutolinks' ] > ( {
188+ @debug < AutolinksProvider [ 'getEnrichedAutolinks' ] > ( {
195189 args : {
196190 0 : messageOrAutolinks =>
197191 typeof messageOrAutolinks === 'string' ? '<message>' : `autolinks=${ messageOrAutolinks . size } ` ,
@@ -264,7 +258,7 @@ export class Autolinks implements Disposable {
264258 return enrichedAutolinks ;
265259 }
266260
267- @debug < Autolinks [ 'linkify' ] > ( {
261+ @debug < AutolinksProvider [ 'linkify' ] > ( {
268262 args : {
269263 0 : '<text>' ,
270264 2 : remotes => remotes ?. length ,
0 commit comments