Skip to content

Commit

Permalink
Fix angle bracket path completions for link defs (#154182)
Browse files Browse the repository at this point in the history
Fixes #153866
  • Loading branch information
mjbvz authored Jul 5, 2022
1 parent fc0bd9d commit f6271dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export class MdVsCodePathCompletionProvider implements vscode.CompletionItemProv

const definitionLinkPrefixMatch = linePrefixText.match(this.definitionPattern);
if (definitionLinkPrefixMatch) {
const prefix = definitionLinkPrefixMatch[1];
const isAngleBracketLink = definitionLinkPrefixMatch[1].startsWith('<');
const prefix = definitionLinkPrefixMatch[1].slice(isAngleBracketLink ? 1 : 0);
if (this.refLooksLikeUrl(prefix)) {
return undefined;
}
Expand All @@ -205,6 +206,7 @@ export class MdVsCodePathCompletionProvider implements vscode.CompletionItemProv
linkTextStartPosition: position.translate({ characterDelta: -prefix.length }),
linkSuffix: suffix ? suffix[0] : '',
anchorInfo: this.getAnchorContext(prefix),
skipEncoding: isAngleBracketLink,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,22 @@ suite('Markdown: Path completions', () => {
{ label: 'file.md', insertText: 'file.md' },
]);
});

test('Should support definition path with angle brackets', async () => {
const workspace = new InMemoryMdWorkspace([
new InMemoryDocument(workspacePath('a.md'), ''),
new InMemoryDocument(workspacePath('b.md'), ''),
new InMemoryDocument(workspacePath('sub with space/file.md'), ''),
]);

const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines(
`[def]: <./${CURSOR}>`
), workspace);

assertCompletionsEqual(completions, [
{ label: 'a.md', insertText: 'a.md' },
{ label: 'b.md', insertText: 'b.md' },
{ label: 'sub with space/', insertText: 'sub with space/' },
]);
});
});

0 comments on commit f6271dd

Please sign in to comment.