|
1 | 1 | import type { ConfigurationChangeEvent } from 'vscode'; |
2 | 2 | import { Disposable } from 'vscode'; |
3 | | -import type { AutolinkReference, AutolinkType } from '../config'; |
4 | | -import { GlyphChars } from '../constants'; |
5 | | -import type { IntegrationId } from '../constants.integrations'; |
6 | | -import { IssueIntegrationId } from '../constants.integrations'; |
7 | | -import type { Container } from '../container'; |
8 | | -import type { IssueOrPullRequest } from '../git/models/issue'; |
9 | | -import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/models/issue'; |
10 | | -import type { GitRemote } from '../git/models/remote'; |
11 | | -import type { ProviderReference } from '../git/models/remoteProvider'; |
12 | | -import type { ResourceDescriptor } from '../plus/integrations/integration'; |
13 | | -import { fromNow } from '../system/date'; |
14 | | -import { debug } from '../system/decorators/log'; |
15 | | -import { encodeUrl } from '../system/encoding'; |
16 | | -import { join, map } from '../system/iterable'; |
17 | | -import { Logger } from '../system/logger'; |
18 | | -import { escapeMarkdown } from '../system/markdown'; |
19 | | -import type { MaybePausedResult } from '../system/promise'; |
20 | | -import { capitalize, encodeHtmlWeak, escapeRegex, getSuperscript } from '../system/string'; |
21 | | -import { configuration } from '../system/vscode/configuration'; |
| 3 | +import { GlyphChars } from './constants'; |
| 4 | +import type { IntegrationId } from './constants.integrations'; |
| 5 | +import { IssueIntegrationId } from './constants.integrations'; |
| 6 | +import type { Container } from './container'; |
| 7 | +import type { IssueOrPullRequest } from './git/models/issue'; |
| 8 | +import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from './git/models/issue'; |
| 9 | +import type { GitRemote } from './git/models/remote'; |
| 10 | +import type { ProviderReference } from './git/models/remoteProvider'; |
| 11 | +import type { ResourceDescriptor } from './plus/integrations/integration'; |
| 12 | +import { fromNow } from './system/date'; |
| 13 | +import { debug } from './system/decorators/log'; |
| 14 | +import { encodeUrl } from './system/encoding'; |
| 15 | +import { join, map } from './system/iterable'; |
| 16 | +import { Logger } from './system/logger'; |
| 17 | +import { escapeMarkdown } from './system/markdown'; |
| 18 | +import type { MaybePausedResult } from './system/promise'; |
| 19 | +import { capitalize, encodeHtmlWeak, escapeRegex, getSuperscript } from './system/string'; |
| 20 | +import { configuration } from './system/vscode/configuration'; |
22 | 21 |
|
23 | 22 | const emptyAutolinkMap = Object.freeze(new Map<string, Autolink>()); |
24 | 23 |
|
25 | 24 | const numRegex = /<num>/g; |
26 | 25 |
|
27 | | -export interface Autolink { |
| 26 | +export type AutolinkType = 'issue' | 'pullrequest'; |
| 27 | + |
| 28 | +export interface AutolinkReference { |
| 29 | + /** Short prefix to match to generate autolinks for the external resource */ |
| 30 | + readonly prefix: string; |
| 31 | + /** URL of the external resource to link to */ |
| 32 | + readonly url: string; |
| 33 | + /** Whether alphanumeric characters should be allowed in `<num>` */ |
| 34 | + readonly alphanumeric: boolean; |
| 35 | + /** Whether case should be ignored when matching the prefix */ |
| 36 | + readonly ignoreCase: boolean; |
| 37 | + readonly title: string | undefined; |
| 38 | + |
| 39 | + readonly type?: AutolinkType; |
| 40 | + readonly description?: string; |
| 41 | + readonly descriptor?: ResourceDescriptor; |
| 42 | +} |
| 43 | + |
| 44 | +export interface Autolink extends AutolinkReference { |
28 | 45 | provider?: ProviderReference; |
29 | 46 | id: string; |
30 | | - prefix: string; |
31 | | - title?: string; |
32 | | - url: string; |
33 | | - alphanumeric?: boolean |
34 | | - type?: AutolinkType; |
35 | | - description?: string; |
36 | | - |
37 | | - descriptor?: ResourceDescriptor; |
| 47 | + |
38 | 48 | tokenize?: |
39 | 49 | | (( |
40 | 50 | text: string, |
@@ -69,8 +79,10 @@ export function serializeAutolink(value: Autolink): Autolink { |
69 | 79 | : undefined, |
70 | 80 | id: value.id, |
71 | 81 | prefix: value.prefix, |
72 | | - title: value.title, |
73 | 82 | url: value.url, |
| 83 | + alphanumeric: value.alphanumeric, |
| 84 | + ignoreCase: value.ignoreCase, |
| 85 | + title: value.title, |
74 | 86 | type: value.type, |
75 | 87 | description: value.description, |
76 | 88 | descriptor: value.descriptor, |
@@ -140,18 +152,12 @@ export class Autolinks implements Disposable { |
140 | 152 | this._references = |
141 | 153 | autolinks |
142 | 154 | ?.filter(a => a.prefix && a.url) |
143 | | - /** |
144 | | - * Only allow properties defined by {@link AutolinkReference} |
145 | | - */ |
146 | 155 | ?.map(a => ({ |
147 | 156 | prefix: a.prefix, |
148 | 157 | url: a.url, |
149 | | - title: a.title, |
150 | | - alphanumeric: a.alphanumeric, |
151 | | - ignoreCase: a.ignoreCase, |
152 | | - type: a.type, |
153 | | - description: a.description, |
154 | | - descriptor: a.descriptor, |
| 158 | + alphanumeric: a.alphanumeric ?? false, |
| 159 | + ignoreCase: a.ignoreCase ?? false, |
| 160 | + title: a.title ?? undefined, |
155 | 161 | })) ?? []; |
156 | 162 | } |
157 | 163 | } |
@@ -237,8 +243,9 @@ export class Autolinks implements Disposable { |
237 | 243 | id: num, |
238 | 244 | prefix: ref.prefix, |
239 | 245 | url: ref.url?.replace(numRegex, num), |
240 | | - title: ref.title?.replace(numRegex, num), |
241 | 246 | alphanumeric: ref.alphanumeric, |
| 247 | + ignoreCase: ref.ignoreCase, |
| 248 | + title: ref.title?.replace(numRegex, num), |
242 | 249 | type: ref.type, |
243 | 250 | description: ref.description?.replace(numRegex, num), |
244 | 251 | descriptor: ref.descriptor, |
|
0 commit comments