Adding test for renaming the definition itself

This commit is contained in:
Matt Bierner 2022-04-04 15:02:58 -07:00
parent 7831ff6a32
commit d0767451a9
No known key found for this signature in database
GPG key ID: 099C331567E11888
2 changed files with 27 additions and 6 deletions

View file

@ -93,12 +93,10 @@ export class MdRenameProvider extends Disposable implements vscode.RenameProvide
// We may be renaming either the reference or the definition itself
if (isRefRename) {
edit.replace(ref.link.source.resource, ref.link.ref.range, newName);
} else {
edit.replace(ref.link.source.resource, ref.fragmentLocation?.range ?? ref.link.source.hrefRange, ref.fragmentLocation ? slug : newName);
continue;
}
} else {
edit.replace(ref.location.uri, ref.fragmentLocation?.range ?? ref.location.range, ref.link.href.kind === 'reference' ? newName : slug);
}
edit.replace(ref.link.source.resource, ref.fragmentLocation?.range ?? ref.location.range, isRefRename && !ref.fragmentLocation ? newName : slug);
break;
}
}

View file

@ -254,7 +254,7 @@ suite('markdown: rename', () => {
}
});
test('Rename on ref should rename refs and def', async () => {
test('Rename on reference should rename references and definition', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text][ref]`, // rename here
@ -273,7 +273,7 @@ suite('markdown: rename', () => {
});
});
test('Rename on def should rename refs and def', async () => {
test('Rename on definition should rename references and definitions', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text][ref]`,
@ -292,6 +292,29 @@ suite('markdown: rename', () => {
});
});
test('Rename on definition entry should rename header and references', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`# a B c`,
`[ref text][ref]`,
`[direct](#a-b-c)`,
`[ref]: #a-b-c`, // rename here
));
const preparedInfo = await prepareRename(doc, new vscode.Position(3, 10), new InMemoryWorkspaceMarkdownDocuments([doc]));
assert.strictEqual(preparedInfo!.placeholder, 'a B c');
assertRangeEqual(preparedInfo!.range, new vscode.Range(3, 8, 3, 13));
const edit = await getRenameEdits(doc, new vscode.Position(3, 10), "x Y z", new InMemoryWorkspaceMarkdownDocuments([doc]));
assertEditsEqual(edit!, {
uri, edits: [
new vscode.TextEdit(new vscode.Range(0, 2, 0, 7), 'x Y z'),
new vscode.TextEdit(new vscode.Range(2, 10, 2, 15), 'x-y-z'),
new vscode.TextEdit(new vscode.Range(3, 8, 3, 13), 'x-y-z'),
]
});
});
test('Rename should not be supported on link text', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(