mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-19 16:18:58 +01:00
Fix notebook links to other docs in edited markdown cells (#153052)
Fixes #148199 This makes us resolve links in notebooks relative to the notebook document instead of relaitve to the cell
This commit is contained in:
@@ -38,7 +38,7 @@ export interface ReferenceHref {
|
||||
export type LinkHref = ExternalHref | InternalHref | ReferenceHref;
|
||||
|
||||
|
||||
function parseLink(
|
||||
function resolveLink(
|
||||
document: ITextDocument,
|
||||
link: string,
|
||||
): ExternalHref | InternalHref | undefined {
|
||||
@@ -85,6 +85,16 @@ function parseLink(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// If we are in a notebook cell, resolve relative to notebook instead
|
||||
if (resourceUri.scheme === Schemes.notebookCell) {
|
||||
const notebook = vscode.workspace.notebookDocuments
|
||||
.find(notebook => notebook.getCells().some(cell => cell.document === document));
|
||||
|
||||
if (notebook) {
|
||||
resourceUri = resourceUri.with({ scheme: notebook.uri.scheme });
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'internal',
|
||||
path: resourceUri.with({ fragment: '' }),
|
||||
@@ -144,7 +154,7 @@ function extractDocumentLink(
|
||||
const linkStart = document.positionAt(offset);
|
||||
const linkEnd = document.positionAt(offset + link.length);
|
||||
try {
|
||||
const linkTarget = parseLink(document, link);
|
||||
const linkTarget = resolveLink(document, link);
|
||||
if (!linkTarget) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -323,7 +333,7 @@ export class MdLinkComputer {
|
||||
|
||||
for (const match of text.matchAll(autoLinkPattern)) {
|
||||
const link = match[1];
|
||||
const linkTarget = parseLink(document, link);
|
||||
const linkTarget = resolveLink(document, link);
|
||||
if (linkTarget) {
|
||||
const offset = (match.index ?? 0) + 1;
|
||||
const linkStart = document.positionAt(offset);
|
||||
@@ -426,7 +436,7 @@ export class MdLinkComputer {
|
||||
if (noLinkRanges.contains(hrefRange.start)) {
|
||||
continue;
|
||||
}
|
||||
const target = parseLink(document, text);
|
||||
const target = resolveLink(document, text);
|
||||
if (target) {
|
||||
yield {
|
||||
kind: 'definition',
|
||||
|
||||
Reference in New Issue
Block a user