diff options
author | Matt Bierner <matb@microsoft.com> | 2022-07-13 01:55:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-13 01:55:21 +0300 |
commit | 75e231ad82a3ee0de5a439d4c479e18de859e21b (patch) | |
tree | 905e6ce89126b36f11f28e25a7b326dd2f4498db /extensions | |
parent | 66d8947f84b6dba315d577983ea1968c70718c74 (diff) |
Clean up document link resolve (#154959)
- Move vscode scheme normalization to the DocumentLinkProvider
- Remove extra function since we already recognize uri-like links
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/markdown-language-features/src/languageFeatures/documentLinks.ts | 15 | ||||
-rw-r--r-- | extensions/markdown-language-features/src/util/schemes.ts | 18 |
2 files changed, 6 insertions, 27 deletions
diff --git a/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts b/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts index 396b7ebbc83..6ef76cdb227 100644 --- a/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts +++ b/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts @@ -13,7 +13,7 @@ import { getLine, ITextDocument } from '../types/textDocument'; import { coalesce } from '../util/arrays'; import { noopToken } from '../util/cancellation'; import { Disposable } from '../util/dispose'; -import { getUriForLinkWithKnownExternalScheme, isOfScheme, Schemes } from '../util/schemes'; +import { Schemes } from '../util/schemes'; import { MdDocumentInfoCache } from '../util/workspaceCache'; import { IMdWorkspace } from '../workspace'; @@ -43,14 +43,6 @@ function resolveLink( link: string, ): ExternalHref | InternalHref | undefined { const cleanLink = stripAngleBrackets(link); - const externalSchemeUri = getUriForLinkWithKnownExternalScheme(cleanLink); - if (externalSchemeUri) { - // Normalize VS Code links to target currently running version - if (isOfScheme(Schemes.vscode, link) || isOfScheme(Schemes['vscode-insiders'], link)) { - return { kind: 'external', uri: vscode.Uri.parse(link).with({ scheme: vscode.env.uriScheme }) }; - } - return { kind: 'external', uri: externalSchemeUri }; - } if (/^[a-z\-][a-z\-]+:/i.test(cleanLink)) { // Looks like a uri @@ -573,6 +565,11 @@ export class MdVsCodeLinkProvider implements vscode.DocumentLinkProvider { private toValidDocumentLink(link: MdLink, definitionSet: LinkDefinitionSet): vscode.DocumentLink | undefined { switch (link.href.kind) { case 'external': { + let target = link.href.uri; + // Normalize VS Code links to target currently running version + if (link.href.uri.scheme === Schemes.vscode || link.href.uri.scheme === Schemes['vscode-insiders']) { + target = target.with({ scheme: vscode.env.uriScheme }); + } return new vscode.DocumentLink(link.source.hrefRange, link.href.uri); } case 'internal': { diff --git a/extensions/markdown-language-features/src/util/schemes.ts b/extensions/markdown-language-features/src/util/schemes.ts index e18f60ed81d..3eae0754ad2 100644 --- a/extensions/markdown-language-features/src/util/schemes.ts +++ b/extensions/markdown-language-features/src/util/schemes.ts @@ -3,33 +3,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as vscode from 'vscode'; - export const Schemes = Object.freeze({ - http: 'http', - https: 'https', file: 'file', untitled: 'untitled', mailto: 'mailto', - data: 'data', vscode: 'vscode', 'vscode-insiders': 'vscode-insiders', notebookCell: 'vscode-notebook-cell', }); -const knownSchemes = [ - ...Object.values(Schemes), - `${vscode.env.uriScheme}` -]; - -export function getUriForLinkWithKnownExternalScheme(link: string): vscode.Uri | undefined { - if (knownSchemes.some(knownScheme => isOfScheme(knownScheme, link))) { - return vscode.Uri.parse(link); - } - - return undefined; -} - export function isOfScheme(scheme: string, link: string): boolean { return link.toLowerCase().startsWith(scheme + ':'); } |