Working on initial support for renaming refs in md

For #146291
This commit is contained in:
Matt Bierner
2022-03-31 18:27:42 -07:00
parent 0d1530cf2f
commit c39d09a4c0
5 changed files with 151 additions and 42 deletions

View File

@@ -319,10 +319,10 @@ suite('markdown: find all references', () => {
});
suite('Reference links', () => {
test('Should find reference links within file', async () => {
test('Should find reference links within file from link', async () => {
const docUri = workspacePath('doc.md');
const doc = new InMemoryDocument(docUri, joinLines(
`[link 1][abc]`,
`[link 1][abc]`, // trigger here
``,
`[abc]: https://example.com`,
));
@@ -334,6 +334,21 @@ suite('markdown: find all references', () => {
);
});
test('Should find reference links within file from definition', async () => {
const docUri = workspacePath('doc.md');
const doc = new InMemoryDocument(docUri, joinLines(
`[link 1][abc]`,
``,
`[abc]: https://example.com`, // trigger here
));
const refs = await getReferences(doc, new vscode.Position(2, 3), new InMemoryWorkspaceMarkdownDocuments([doc]));
assertReferencesEqual(refs!,
{ uri: docUri, line: 0 },
{ uri: docUri, line: 2 },
);
});
test('Should not find reference links across files', async () => {
const docUri = workspacePath('doc.md');
const doc = new InMemoryDocument(docUri, joinLines(

View File

@@ -207,4 +207,42 @@ suite('markdown: rename', () => {
]
});
});
test('Rename on ref should rename refs and def', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text][ref]`, // rename here
`[other][ref]`,
``,
`[ref]: https://example.com`,
));
const edit = await getRenameEdits(doc, new vscode.Position(0, 8), "new ref", new InMemoryWorkspaceMarkdownDocuments([doc]));
assertEditsEqual(edit!, {
uri, edits: [
new vscode.TextEdit(new vscode.Range(0, 7, 0, 10), 'new ref'),
new vscode.TextEdit(new vscode.Range(1, 8, 1, 11), 'new ref'),
new vscode.TextEdit(new vscode.Range(3, 1, 3, 4), 'new ref'),
]
});
});
test('Rename on def should rename refs and def', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text][ref]`,
`[other][ref]`,
``,
`[ref]: https://example.com`, // rename here
));
const edit = await getRenameEdits(doc, new vscode.Position(3, 3), "new ref", new InMemoryWorkspaceMarkdownDocuments([doc]));
assertEditsEqual(edit!, {
uri, edits: [
new vscode.TextEdit(new vscode.Range(0, 7, 0, 10), 'new ref'),
new vscode.TextEdit(new vscode.Range(1, 8, 1, 11), 'new ref'),
new vscode.TextEdit(new vscode.Range(3, 1, 3, 4), 'new ref'),
]
});
});
});