Skip to content

Commit 75e231a

Browse files
authored
Clean up document link resolve (microsoft#154959)
- Move vscode scheme normalization to the DocumentLinkProvider - Remove extra function since we already recognize uri-like links
1 parent 66d8947 commit 75e231a

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

extensions/markdown-language-features/src/languageFeatures/documentLinks.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getLine, ITextDocument } from '../types/textDocument';
1313
import { coalesce } from '../util/arrays';
1414
import { noopToken } from '../util/cancellation';
1515
import { Disposable } from '../util/dispose';
16-
import { getUriForLinkWithKnownExternalScheme, isOfScheme, Schemes } from '../util/schemes';
16+
import { Schemes } from '../util/schemes';
1717
import { MdDocumentInfoCache } from '../util/workspaceCache';
1818
import { IMdWorkspace } from '../workspace';
1919

@@ -43,14 +43,6 @@ function resolveLink(
4343
link: string,
4444
): ExternalHref | InternalHref | undefined {
4545
const cleanLink = stripAngleBrackets(link);
46-
const externalSchemeUri = getUriForLinkWithKnownExternalScheme(cleanLink);
47-
if (externalSchemeUri) {
48-
// Normalize VS Code links to target currently running version
49-
if (isOfScheme(Schemes.vscode, link) || isOfScheme(Schemes['vscode-insiders'], link)) {
50-
return { kind: 'external', uri: vscode.Uri.parse(link).with({ scheme: vscode.env.uriScheme }) };
51-
}
52-
return { kind: 'external', uri: externalSchemeUri };
53-
}
5446

5547
if (/^[a-z\-][a-z\-]+:/i.test(cleanLink)) {
5648
// Looks like a uri
@@ -573,6 +565,11 @@ export class MdVsCodeLinkProvider implements vscode.DocumentLinkProvider {
573565
private toValidDocumentLink(link: MdLink, definitionSet: LinkDefinitionSet): vscode.DocumentLink | undefined {
574566
switch (link.href.kind) {
575567
case 'external': {
568+
let target = link.href.uri;
569+
// Normalize VS Code links to target currently running version
570+
if (link.href.uri.scheme === Schemes.vscode || link.href.uri.scheme === Schemes['vscode-insiders']) {
571+
target = target.with({ scheme: vscode.env.uriScheme });
572+
}
576573
return new vscode.DocumentLink(link.source.hrefRange, link.href.uri);
577574
}
578575
case 'internal': {

extensions/markdown-language-features/src/util/schemes.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as vscode from 'vscode';
7-
86
export const Schemes = Object.freeze({
9-
http: 'http',
10-
https: 'https',
117
file: 'file',
128
untitled: 'untitled',
139
mailto: 'mailto',
14-
data: 'data',
1510
vscode: 'vscode',
1611
'vscode-insiders': 'vscode-insiders',
1712
notebookCell: 'vscode-notebook-cell',
1813
});
1914

20-
const knownSchemes = [
21-
...Object.values(Schemes),
22-
`${vscode.env.uriScheme}`
23-
];
24-
25-
export function getUriForLinkWithKnownExternalScheme(link: string): vscode.Uri | undefined {
26-
if (knownSchemes.some(knownScheme => isOfScheme(knownScheme, link))) {
27-
return vscode.Uri.parse(link);
28-
}
29-
30-
return undefined;
31-
}
32-
3315
export function isOfScheme(scheme: string, link: string): boolean {
3416
return link.toLowerCase().startsWith(scheme + ':');
3517
}

0 commit comments

Comments
 (0)