Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/markdown-language-features/src/languageFeatures/documentLinks.ts')
-rw-r--r--extensions/markdown-language-features/src/languageFeatures/documentLinks.ts32
1 files changed, 15 insertions, 17 deletions
diff --git a/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts b/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts
index 4fe6320c6cc..6ef76cdb227 100644
--- a/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts
+++ b/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts
@@ -9,11 +9,11 @@ import * as uri from 'vscode-uri';
import { OpenDocumentLinkCommand } from '../commands/openDocumentLink';
import { ILogger } from '../logging';
import { IMdParser } from '../markdownEngine';
-import { ITextDocument } from '../types/textDocument';
+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
@@ -400,7 +392,8 @@ export class MdLinkComputer {
private *getReferenceLinks(document: ITextDocument, noLinkRanges: NoLinkRanges): Iterable<MdLink> {
const text = document.getText();
for (const match of text.matchAll(referenceLinkPattern)) {
- const linkStart = document.positionAt(match.index ?? 0);
+ const linkStartOffset = (match.index ?? 0) + match[1].length;
+ const linkStart = document.positionAt(linkStartOffset);
if (noLinkRanges.contains(linkStart)) {
continue;
}
@@ -410,21 +403,21 @@ export class MdLinkComputer {
let reference = match[4];
if (reference === '') { // [ref][],
reference = match[3];
- const offset = ((match.index ?? 0) + match[1].length) + 1;
+ const offset = linkStartOffset + 1;
hrefStart = document.positionAt(offset);
hrefEnd = document.positionAt(offset + reference.length);
} else if (reference) { // [text][ref]
const pre = match[2];
- const offset = ((match.index ?? 0) + match[1].length) + pre.length;
+ const offset = linkStartOffset + pre.length;
hrefStart = document.positionAt(offset);
hrefEnd = document.positionAt(offset + reference.length);
} else if (match[5]) { // [ref]
reference = match[5];
- const offset = ((match.index ?? 0) + match[1].length) + 1;
+ const offset = linkStartOffset + 1;
hrefStart = document.positionAt(offset);
- const line = document.lineAt(hrefStart.line);
+ const line = getLine(document, hrefStart.line);
// See if link looks like a checkbox
- const checkboxMatch = line.text.match(/^\s*[\-\*]\s*\[x\]/i);
+ const checkboxMatch = line.match(/^\s*[\-\*]\s*\[x\]/i);
if (checkboxMatch && hrefStart.character <= checkboxMatch[0].length) {
continue;
}
@@ -433,7 +426,7 @@ export class MdLinkComputer {
continue;
}
- const linkEnd = linkStart.translate(0, match[0].length);
+ const linkEnd = linkStart.translate(0, match[0].length - match[1].length);
yield {
kind: 'link',
source: {
@@ -572,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': {