Error on rename in bare file links in definition

This commit is contained in:
Matt Bierner 2022-04-01 00:07:22 -07:00
parent 114b340f7a
commit ca267e3f5e
No known key found for this signature in database
GPG key ID: 099C331567E11888
2 changed files with 15 additions and 2 deletions

View file

@ -53,7 +53,10 @@ export class MdRenameProvider extends Disposable implements vscode.RenameProvide
if (triggerRef.link.refRange.contains(position)) {
return triggerRef.link.refRange;
} else {
return triggerRef.link.sourceHrefRange;
if (triggerRef.fragmentLocation) {
return triggerRef.fragmentLocation.range;
}
throw new Error(localize('renameNoFiles', "Renaming files is currently not supported"));
}
} else {
if (triggerRef.fragmentLocation) {

View file

@ -302,7 +302,7 @@ suite('markdown: rename', () => {
await assert.rejects(getRenameRange(doc, new vscode.Position(1, 2), new InMemoryWorkspaceMarkdownDocuments([doc])));
});
test('Rename should not be supported on bare file references', async () => {
test('Rename should not be supported on bare file link', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text](./doc.md)`,
@ -311,4 +311,14 @@ suite('markdown: rename', () => {
await assert.rejects(getRenameRange(doc, new vscode.Position(0, 10), new InMemoryWorkspaceMarkdownDocuments([doc])));
});
test('Rename should not be supported on bare file link in definition', async () => {
const uri = workspacePath('doc.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text](./doc.md)`,
`[ref]: ./doc.md`,
));
await assert.rejects(getRenameRange(doc, new vscode.Position(1, 10), new InMemoryWorkspaceMarkdownDocuments([doc])));
});
});