mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Remove old jsdoc link handling (#225529)
This code was used when TS Server didn't have support for `@link`. I think we can remove it now
This commit is contained in:
@@ -15,24 +15,6 @@ export interface IFilePathToResourceConverter {
|
||||
toResource(filepath: string): vscode.Uri;
|
||||
}
|
||||
|
||||
function replaceLinks(text: string): string {
|
||||
return text
|
||||
// Http(s) links
|
||||
.replace(/\{@(link|linkplain|linkcode) (https?:\/\/[^ |}]+?)(?:[| ]([^{}\n]+?))?\}/gi, (_, tag: string, link: string, text?: string) => {
|
||||
switch (tag) {
|
||||
case 'linkcode':
|
||||
return `[\`${text ? text.trim() : link}\`](${link})`;
|
||||
|
||||
default:
|
||||
return `[${text ? text.trim() : link}](${link})`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function processInlineTags(text: string): string {
|
||||
return replaceLinks(text);
|
||||
}
|
||||
|
||||
function getTagBodyText(
|
||||
tag: Proto.JSDocTagInfo,
|
||||
filePathConverter: IFilePathToResourceConverter,
|
||||
@@ -67,18 +49,19 @@ function getTagBodyText(
|
||||
case 'author': {
|
||||
// fix obsucated email address, #80898
|
||||
const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/);
|
||||
|
||||
if (emailMatch === null) {
|
||||
return text;
|
||||
} else {
|
||||
return `${emailMatch[1]} ${emailMatch[2]}`;
|
||||
}
|
||||
}
|
||||
case 'default':
|
||||
case 'default': {
|
||||
return makeCodeblock(text);
|
||||
}
|
||||
default: {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
return processInlineTags(text);
|
||||
}
|
||||
|
||||
function getTagDocumentation(
|
||||
@@ -98,11 +81,10 @@ function getTagDocumentation(
|
||||
if (!doc) {
|
||||
return label;
|
||||
}
|
||||
return label + (doc.match(/\r\n|\n/g) ? ' \n' + processInlineTags(doc) : ` \u2014 ${processInlineTags(doc)}`);
|
||||
return label + (doc.match(/\r\n|\n/g) ? ' \n' + doc : ` \u2014 ${doc}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'return':
|
||||
case 'returns': {
|
||||
// For return(s), we require a non-empty body
|
||||
@@ -147,7 +129,7 @@ export function asPlainTextWithLinks(
|
||||
parts: readonly Proto.SymbolDisplayPart[] | string,
|
||||
filePathConverter: IFilePathToResourceConverter,
|
||||
): string {
|
||||
return processInlineTags(convertLinkTags(parts, filePathConverter));
|
||||
return convertLinkTags(parts, filePathConverter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,10 +169,10 @@ function convertLinkTags(
|
||||
if (text) {
|
||||
if (/^https?:/.test(text)) {
|
||||
const parts = text.split(' ');
|
||||
if (parts.length === 1) {
|
||||
if (parts.length === 1 && !currentLink.linkcode) {
|
||||
out.push(`<${parts[0]}>`);
|
||||
} else if (parts.length > 1) {
|
||||
const linkText = parts.slice(1).join(' ');
|
||||
} else {
|
||||
const linkText = parts.length > 1 ? parts.slice(1).join(' ') : parts[0];
|
||||
out.push(`[${currentLink.linkcode ? '`' + escapeMarkdownSyntaxTokensForCode(linkText) + '`' : linkText}](${parts[0]})`);
|
||||
}
|
||||
} else {
|
||||
@@ -224,7 +206,7 @@ function convertLinkTags(
|
||||
break;
|
||||
}
|
||||
}
|
||||
return processInlineTags(out.join(''));
|
||||
return out.join('');
|
||||
}
|
||||
|
||||
function escapeMarkdownSyntaxTokensForCode(text: string): string {
|
||||
|
||||
@@ -28,17 +28,19 @@ suite('typescript.previewer', () => {
|
||||
test('Should parse url jsdoc @link', () => {
|
||||
assert.strictEqual(
|
||||
documentationToMarkdown(
|
||||
'x {@link http://www.example.com/foo} y {@link https://api.jquery.com/bind/#bind-eventType-eventData-handler} z',
|
||||
// 'x {@link http://www.example.com/foo} y {@link https://api.jquery.com/bind/#bind-eventType-eventData-handler} z',
|
||||
[{ "text": "x ", "kind": "text" }, { "text": "{@link ", "kind": "link" }, { "text": "http://www.example.com/foo", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " y ", "kind": "text" }, { "text": "{@link ", "kind": "link" }, { "text": "https://api.jquery.com/bind/#bind-eventType-eventData-handler", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " z", "kind": "text" }],
|
||||
[],
|
||||
noopToResource, undefined
|
||||
).value,
|
||||
'x [http://www.example.com/foo](http://www.example.com/foo) y [https://api.jquery.com/bind/#bind-eventType-eventData-handler](https://api.jquery.com/bind/#bind-eventType-eventData-handler) z');
|
||||
'x <http://www.example.com/foo> y <https://api.jquery.com/bind/#bind-eventType-eventData-handler> z');
|
||||
});
|
||||
|
||||
test('Should parse url jsdoc @link with text', () => {
|
||||
assert.strictEqual(
|
||||
documentationToMarkdown(
|
||||
'x {@link http://www.example.com/foo abc xyz} y {@link http://www.example.com/bar|b a z} z',
|
||||
// 'x {@link http://www.example.com/foo abc xyz} y {@link http://www.example.com/bar|b a z} z',
|
||||
[{ "text": "x ", "kind": "text" }, { "text": "{@link ", "kind": "link" }, { "text": "http://www.example.com/foo abc xyz", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " y ", "kind": "text" }, { "text": "{@link ", "kind": "link" }, { "text": "http://www.example.com/bar b a z", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " z", "kind": "text" }],
|
||||
[],
|
||||
noopToResource, undefined
|
||||
).value,
|
||||
@@ -48,11 +50,12 @@ suite('typescript.previewer', () => {
|
||||
test('Should treat @linkcode jsdocs links as monospace', () => {
|
||||
assert.strictEqual(
|
||||
documentationToMarkdown(
|
||||
'x {@linkcode http://www.example.com/foo} y {@linkplain http://www.example.com/bar} z',
|
||||
// 'x {@linkcode http://www.example.com/foo} y {@linkplain http://www.example.com/bar} z',
|
||||
[{ "text": "x ", "kind": "text" }, { "text": "{@linkcode ", "kind": "link" }, { "text": "http://www.example.com/foo", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " y ", "kind": "text" }, { "text": "{@linkplain ", "kind": "link" }, { "text": "http://www.example.com/bar", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " z", "kind": "text" }],
|
||||
[],
|
||||
noopToResource, undefined
|
||||
).value,
|
||||
'x [`http://www.example.com/foo`](http://www.example.com/foo) y [http://www.example.com/bar](http://www.example.com/bar) z');
|
||||
'x [`http://www.example.com/foo`](http://www.example.com/foo) y <http://www.example.com/bar> z');
|
||||
});
|
||||
|
||||
test('Should parse url jsdoc @link in param tag', () => {
|
||||
@@ -60,22 +63,13 @@ suite('typescript.previewer', () => {
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'param',
|
||||
text: 'a x {@link http://www.example.com/foo abc xyz} y {@link http://www.example.com/bar|b a z} z'
|
||||
// a x {@link http://www.example.com/foo abc xyz} y {@link http://www.example.com/bar|b a z} z
|
||||
text: [{ "text": "a", "kind": "parameterName" }, { "text": " ", "kind": "space" }, { "text": "x ", "kind": "text" }, { "text": "{@link ", "kind": "link" }, { "text": "http://www.example.com/foo abc xyz", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " y ", "kind": "text" }, { "text": "{@link ", "kind": "link" }, { "text": "http://www.example.com/bar b a z", "kind": "linkText" }, { "text": "}", "kind": "link" }, { "text": " z", "kind": "text" }],
|
||||
}
|
||||
], noopToResource),
|
||||
'*@param* `a` — x [abc xyz](http://www.example.com/foo) y [b a z](http://www.example.com/bar) z');
|
||||
});
|
||||
|
||||
test('Should ignore unclosed jsdocs @link', () => {
|
||||
assert.strictEqual(
|
||||
documentationToMarkdown(
|
||||
'x {@link http://www.example.com/foo y {@link http://www.example.com/bar bar} z',
|
||||
[],
|
||||
noopToResource, undefined
|
||||
).value,
|
||||
'x {@link http://www.example.com/foo y [bar](http://www.example.com/bar) z');
|
||||
});
|
||||
|
||||
test('Should support non-ascii characters in parameter name (#90108)', () => {
|
||||
assert.strictEqual(
|
||||
tagsToMarkdown([
|
||||
|
||||
Reference in New Issue
Block a user