fix(50089): JSDoc/TSDoc @link with custom display text incorrectly shows vertical bar (#50106)

* fix(50089): omit | from jsdoc linkTag text

* change finding for the end pos of a link
This commit is contained in:
Oleksandr T
2022-12-13 01:16:29 +02:00
committed by GitHub
parent 708a522ddf
commit d54f52e0de
4 changed files with 106 additions and 19 deletions

View File

@@ -2898,7 +2898,7 @@ export function buildLinkParts(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain,
if (text) parts.push(linkTextPart(text));
}
else {
parts.push(linkTextPart(name + (suffix || text.indexOf("://") === 0 ? "" : " ") + text));
parts.push(linkTextPart(name + (suffix ? "" : " ") + text));
}
}
parts.push(linkPart("}"));
@@ -2915,15 +2915,21 @@ function skipSeparatorFromLinkText(text: string) {
}
function findLinkNameEnd(text: string) {
let pos = text.indexOf("://");
if (pos === 0) {
while (pos < text.length && text.charCodeAt(pos) !== CharacterCodes.bar) pos++;
return pos;
}
if (text.indexOf("()") === 0) return 2;
if (text[0] !== "<") return 0;
let brackets = 0;
let i = 0;
while (i < text.length) {
if (text[i] === "<") brackets++;
if (text[i] === ">") brackets--;
i++;
if (!brackets) return i;
if (text.charAt(0) === "<") {
let brackets = 0;
let i = 0;
while (i < text.length) {
if (text[i] === "<") brackets++;
if (text[i] === ">") brackets--;
i++;
if (!brackets) return i;
}
}
return 0;
}

View File

@@ -286,7 +286,7 @@
"kind": "link"
},
{
"text": "https",
"text": "https://hva",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
@@ -296,10 +296,6 @@
}
}
},
{
"text": "://hva",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
@@ -358,7 +354,7 @@
"kind": "link"
},
{
"text": "https",
"text": "https://hvaD",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
@@ -368,10 +364,6 @@
}
}
},
{
"text": "://hvaD",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"

View File

@@ -0,0 +1,81 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoLink10.ts",
"position": 57,
"name": ""
},
"quickInfo": {
"kind": "const",
"kindModifiers": "",
"textSpan": {
"start": 57,
"length": 1
},
"displayParts": [
{
"text": "const",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=>",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"documentation": [
{
"text": "start ",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "https://vscode.dev/ end",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
}
]
}
}
]

View File

@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
/////**
//// * start {@link https://vscode.dev/ | end}
//// */
////const /**/a = () => 1;
verify.baselineQuickInfo();