Skip to content

Commit

Permalink
Fixes custom autolinks not being detected (closes #3899)
Browse files Browse the repository at this point in the history
- Ensures that custom autolinks are loaded in the constructor
- Fixes bug with config check when collecting refsets
  • Loading branch information
axosoft-ramint committed Dec 20, 2024
1 parent 03229d2 commit 3802fb5
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/autolinks/autolinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Autolinks implements Disposable {
constructor(private readonly container: Container) {
this._disposable = Disposable.from(configuration.onDidChange(this.onConfigurationChanged, this));

this.onConfigurationChanged();
this.setAutolinksFromConfig();
}

dispose() {
Expand All @@ -51,21 +51,25 @@ export class Autolinks implements Disposable {

private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (configuration.changed(e, 'autolinks')) {
const autolinks = configuration.get('autolinks');
// Since VS Code's configuration objects are live we need to copy them to avoid writing back to the configuration
this._references =
autolinks
?.filter(a => a.prefix && a.url)
?.map(a => ({
prefix: a.prefix,
url: a.url,
alphanumeric: a.alphanumeric ?? false,
ignoreCase: a.ignoreCase ?? false,
title: a.title ?? undefined,
})) ?? [];
this.setAutolinksFromConfig();
}
}

private setAutolinksFromConfig() {
const autolinks = configuration.get('autolinks');
// Since VS Code's configuration objects are live we need to copy them to avoid writing back to the configuration
this._references =
autolinks
?.filter(a => a.prefix && a.url)
?.map(a => ({
prefix: a.prefix,
url: a.url,
alphanumeric: a.alphanumeric ?? false,
ignoreCase: a.ignoreCase ?? false,
title: a.title ?? undefined,
})) ?? [];
}

/** Collects connected integration autolink references into @param refsets */
private async collectIntegrationAutolinks(remote: GitRemote | undefined, refsets: RefSet[]): Promise<void> {
const integrationPromises: Promise<HostingIntegration | IssueIntegration | undefined>[] =
Expand Down Expand Up @@ -111,8 +115,12 @@ export class Autolinks implements Disposable {
}

/** Collects custom-configured autolink references into @param refsets */
private collectCustomAutolinks(remote: GitRemote | undefined, refsets: RefSet[]): void {
if (this._references.length && remote?.provider == null) {
private collectCustomAutolinks(
remote: GitRemote | undefined,
refsets: RefSet[],
options?: { excludeCustom?: boolean },
): void {
if (this._references.length && (remote?.provider == null || !options?.excludeCustom)) {
refsets.push([undefined, this._references]);
}
}
Expand All @@ -122,9 +130,7 @@ export class Autolinks implements Disposable {

await this.collectIntegrationAutolinks(remote, refsets);
this.collectRemoteAutolinks(remote, refsets);
if (!options?.excludeCustom) {
this.collectCustomAutolinks(remote, refsets);
}
this.collectCustomAutolinks(remote, refsets, options);

return refsets;
}
Expand Down

0 comments on commit 3802fb5

Please sign in to comment.