Skip to content

Fix @link https:// formatting #47705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,16 @@ namespace ts {
/** Gets the text of a jsdoc comment, flattening links to their text. */
export function getTextOfJSDocComment(comment?: string | NodeArray<JSDocComment>) {
return typeof comment === "string" ? comment
: comment?.map(c =>
// TODO: Other kinds here
c.kind === SyntaxKind.JSDocText ? c.text : `{@link ${c.name ? entityNameToString(c.name) + " " : ""}${c.text}}`).join("");
: comment?.map(c => c.kind === SyntaxKind.JSDocText ? c.text : formatJSDocLink(c)).join("");
}

function formatJSDocLink(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain) {
const kind = link.kind === SyntaxKind.JSDocLink ? "link"
: link.kind === SyntaxKind.JSDocLinkCode ? "linkcode"
: "linkplain";
const name = link.name ? entityNameToString(link.name) : "";
const space = link.name && link.text.startsWith("://") ? "" : " ";
return `{@${kind} ${name}${space}${link.text}}`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ namespace ts {
if (text) parts.push(linkTextPart(text));
}
else {
parts.push(linkTextPart(name + (suffix ? "" : " ") + text));
parts.push(linkTextPart(name + (suffix || text.indexOf("://") === 0 ? "" : " ") + text));
}
}
parts.push(linkPart("}"));
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/linkTagEmit1.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ declare namespace NS {
function computeCommonSourceDirectoryOfFilenames(integer) {
return integer + 1 // pls pls pls
}

/** {@link https://hvad} */
var see3 = true

/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/


//// [linkTagEmit1.js]
Expand All @@ -36,6 +41,9 @@ function computeCommonSourceDirectoryOfFilenames(integer) {
function computeCommonSourceDirectoryOfFilenames(integer) {
return integer + 1; // pls pls pls
}
/** {@link https://hvad} */
var see3 = true;
/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/


//// [linkTagEmit1.d.ts]
Expand All @@ -50,6 +58,8 @@ function computeCommonSourceDirectoryOfFilenames(integer) {
* @param {number} integer {@link Z}
*/
declare function computeCommonSourceDirectoryOfFilenames(integer: number): number;
/** {@link https://hvad} */
declare var see3: boolean;
type N = number;
type D1 = {
/**
Expand All @@ -62,3 +72,7 @@ type D1 = {
m: 1;
};
type Z = number;
/**
* {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}
*/
type Attempt = number;
6 changes: 6 additions & 0 deletions tests/baselines/reference/linkTagEmit1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ function computeCommonSourceDirectoryOfFilenames(integer) {
>integer : Symbol(integer, Decl(linkTagEmit1.js, 12, 49))
}

/** {@link https://hvad} */
var see3 = true
>see3 : Symbol(see3, Decl(linkTagEmit1.js, 17, 3))

/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/

7 changes: 7 additions & 0 deletions tests/baselines/reference/linkTagEmit1.types
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ function computeCommonSourceDirectoryOfFilenames(integer) {
>1 : 1
}

/** {@link https://hvad} */
var see3 = true
>see3 : boolean
>true : true

/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 36,
"name": "5"
},
"quickInfo": {
"kind": "var",
"kindModifiers": "",
"textSpan": {
"start": 36,
"length": 4
},
"displayParts": [
{
"text": "var",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "see2",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "boolean",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "see",
"text": [
{
"text": "",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "https://hva",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
}
]
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 81,
"name": "6"
},
"quickInfo": {
"kind": "var",
"kindModifiers": "",
"textSpan": {
"start": 81,
"length": 4
},
"displayParts": [
{
"text": "var",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "see3",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "boolean",
"kind": "keyword"
}
],
"documentation": [
{
"text": "",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "https://hvaD",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
}
]
}
}
]
5 changes: 5 additions & 0 deletions tests/cases/conformance/jsdoc/linkTagEmit1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ declare namespace NS {
function computeCommonSourceDirectoryOfFilenames(integer) {
return integer + 1 // pls pls pls
}

/** {@link https://hvad} */
var see3 = true

/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/
12 changes: 12 additions & 0 deletions tests/cases/fourslash/quickInfoForJSDocWithUnresolvedHttpLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
// @checkJs: true
// @filename: quickInfoForJSDocWithHttpLinks.js
// #46734

//// /** @see {@link https://hva} */
//// var /*5*/see2 = true
////
//// /** {@link https://hvaD} */
//// var /*6*/see3 = true

verify.baselineQuickInfo();