mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Fix refs to own file being included in md ref results from other file
For #146277
This commit is contained in:
parent
982a353285
commit
6c7ba2de69
|
@ -135,7 +135,11 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
|
||||||
references.push(new vscode.Location(link.target.fromResource, link.sourceRange));
|
references.push(new vscode.Location(link.target.fromResource, link.sourceRange));
|
||||||
}
|
}
|
||||||
} else { // Triggered on a link without a fragment so we only require matching the file and ignore fragments
|
} else { // Triggered on a link without a fragment so we only require matching the file and ignore fragments
|
||||||
references.push(new vscode.Location(link.target.fromResource, link.sourceRange));
|
|
||||||
|
// But exclude cases where the file is referencing itself
|
||||||
|
if (link.target.fromResource.fsPath !== targetDoc.uri.fsPath) {
|
||||||
|
references.push(new vscode.Location(link.target.fromResource, link.sourceRange));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,12 +244,33 @@ suite('markdown: find all references', () => {
|
||||||
]));
|
]));
|
||||||
|
|
||||||
assertReferencesEqual(refs!,
|
assertReferencesEqual(refs!,
|
||||||
{ uri: docUri, line: 0 }, // Header definition
|
{ uri: docUri, line: 0 },
|
||||||
{ uri: docUri, line: 1 },
|
{ uri: docUri, line: 1 },
|
||||||
{ uri: docUri, line: 2 },
|
{ uri: docUri, line: 2 },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should not include refs from other file to own header', async () => {
|
||||||
|
const docUri = workspacePath('doc.md');
|
||||||
|
const otherUri = workspacePath('sub', 'other.md');
|
||||||
|
|
||||||
|
const doc = new InMemoryDocument(docUri, joinLines(
|
||||||
|
`[other](./sub/other)`,
|
||||||
|
));
|
||||||
|
|
||||||
|
const refs = await getReferences(doc, new vscode.Position(0, 15), new InMemoryWorkspaceMarkdownDocuments([
|
||||||
|
doc,
|
||||||
|
new InMemoryDocument(otherUri, joinLines(
|
||||||
|
`# header`, // Definition should not be included since we triggered on a file link
|
||||||
|
`[text](#header)`, // Definition should not be included since we triggered on a file link
|
||||||
|
)),
|
||||||
|
]));
|
||||||
|
|
||||||
|
assertReferencesEqual(refs!,
|
||||||
|
{ uri: docUri, line: 0 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
suite('Reference links', () => {
|
suite('Reference links', () => {
|
||||||
test('Should find reference links within file', async () => {
|
test('Should find reference links within file', async () => {
|
||||||
const docUri = workspacePath('doc.md');
|
const docUri = workspacePath('doc.md');
|
||||||
|
|
Loading…
Reference in a new issue