Skip to content

Commit fefb857

Browse files
committed
Use only immediately preceding JSDoc
Now only the immediately preceding jsdoc of a node is retrieved by getJSDoc, although it still does the correct non-local lookup for nodes like ParameterDeclaration. This doesn't change parsing or binding, which use the per-node Node.jsdoc property directly. But it does change everything that relies on getJSDoc, which includes the checker and language service. Fixes #32062, which contains the analysis that justifies the change.
1 parent 410b717 commit fefb857

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,13 +2201,13 @@ namespace ts {
22012201
let result: (JSDoc | JSDocTag)[] | undefined;
22022202
// Pull parameter comments from declaring function as well
22032203
if (isVariableLike(hostNode) && hasInitializer(hostNode) && hasJSDocNodes(hostNode.initializer!)) {
2204-
result = addRange(result, (hostNode.initializer as HasJSDoc).jsDoc!);
2204+
result = append(result, last((hostNode.initializer as HasJSDoc).jsDoc!));
22052205
}
22062206

22072207
let node: Node | undefined = hostNode;
22082208
while (node && node.parent) {
22092209
if (hasJSDocNodes(node)) {
2210-
result = addRange(result, node.jsDoc!);
2210+
result = append(result, last(node.jsDoc!));
22112211
}
22122212

22132213
if (node.kind === SyntaxKind.Parameter) {

tests/baselines/reference/syntaxErrors.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ function f(x, y, skipped) {
1717
>skipped : Symbol(skipped, Decl(badTypeArguments.js, 4, 16))
1818

1919
return x.t + y.t;
20-
>x.t : Symbol(C.t, Decl(dummyType.d.ts, 0, 20))
2120
>x : Symbol(x, Decl(badTypeArguments.js, 4, 11))
22-
>t : Symbol(C.t, Decl(dummyType.d.ts, 0, 20))
23-
>y.t : Symbol(C.t, Decl(dummyType.d.ts, 0, 20))
2421
>y : Symbol(y, Decl(badTypeArguments.js, 4, 13))
25-
>t : Symbol(C.t, Decl(dummyType.d.ts, 0, 20))
2622
}
2723
var x = f({ t: 1000 }, { t: 3000 }, { t: 5000 });
2824
>x : Symbol(x, Decl(badTypeArguments.js, 7, 3))

tests/baselines/reference/syntaxErrors.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ declare class C<T> { t: T }
99
// @ts-ignore
1010
/** @param {C.<number,>} skipped */
1111
function f(x, y, skipped) {
12-
>f : (x: C<any>, y: C<number>, skipped: C<number>) => any
13-
>x : C<any>
14-
>y : C<number>
12+
>f : (x: any, y: any, skipped: C<number>) => any
13+
>x : any
14+
>y : any
1515
>skipped : C<number>
1616

1717
return x.t + y.t;
1818
>x.t + y.t : any
1919
>x.t : any
20-
>x : C<any>
20+
>x : any
21+
>t : any
22+
>y.t : any
23+
>y : any
2124
>t : any
22-
>y.t : number
23-
>y : C<number>
24-
>t : number
2525
}
2626
var x = f({ t: 1000 }, { t: 3000 }, { t: 5000 });
2727
>x : any
2828
>f({ t: 1000 }, { t: 3000 }, { t: 5000 }) : any
29-
>f : (x: C<any>, y: C<number>, skipped: C<number>) => any
29+
>f : (x: any, y: any, skipped: C<number>) => any
3030
>{ t: 1000 } : { t: number; }
3131
>t : number
3232
>1000 : 1000

tests/cases/fourslash/commentsCommentParsing.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
////}
2727
////jsDocM/*4q*/ultiLine(/*4*/);
2828
////
29-
/////** this is multiple line jsdoc stule comment
29+
/////** multiple line jsdoc comments no longer merge
3030
////*New line1
3131
////*New Line2*/
3232
/////** Shoul mege this line as well
@@ -99,13 +99,13 @@
9999
//// return /*18*/a + b;
100100
////}
101101
/////*15*/s/*16q*/um(/*16*/10, /*17*/20);
102-
/////** This is multiplication function*/
103-
/////** @param */
104-
/////** @param a first number*/
105-
/////** @param b */
106-
/////** @param c {
107-
//// @param d @anotherTag*/
108-
/////** @param e LastParam @anotherTag*/
102+
/////** This is multiplication function
103+
//// * @param
104+
//// * @param a first number
105+
//// * @param b
106+
//// * @param c {
107+
//// @param d @anotherTag
108+
//// * @param e LastParam @anotherTag*/
109109
////function multiply(/*19aq*/a: number, /*20aq*/b: number, /*21aq*/c?: number, /*22aq*/d?, /*23aq*/e?) {
110110
////}
111111
////mult/*19q*/iply(/*19*/10,/*20*/ 20,/*21*/ 30, /*22*/40, /*23*/50);
@@ -214,26 +214,26 @@ verify.quickInfoAt("3q", "function jsDocSingleLine(): void", "this is eg of sing
214214
verify.signatureHelp({ marker: "4", docComment: "this is multiple line jsdoc stule comment\nNew line1\nNew Line2" });
215215
verify.quickInfoAt("4q", "function jsDocMultiLine(): void", "this is multiple line jsdoc stule comment\nNew line1\nNew Line2");
216216

217-
verify.signatureHelp({ marker: "5", docComment: "this is multiple line jsdoc stule comment\nNew line1\nNew Line2\nShoul mege this line as well\nand this too\nAnother this one too" });
218-
verify.quickInfoAt("5q", "function jsDocMultiLineMerge(): void", "this is multiple line jsdoc stule comment\nNew line1\nNew Line2\nShoul mege this line as well\nand this too\nAnother this one too");
217+
verify.signatureHelp({ marker: "5", docComment: "Another this one too" });
218+
verify.quickInfoAt("5q", "function jsDocMultiLineMerge(): void", "Another this one too");
219219

220220
verify.signatureHelp({ marker: "6", docComment: "jsdoc comment" });
221221
verify.quickInfoAt("6q", "function jsDocMixedComments1(): void", "jsdoc comment");
222222

223-
verify.signatureHelp({ marker: "7", docComment: "jsdoc comment\nanother jsDocComment" });
224-
verify.quickInfoAt("7q", "function jsDocMixedComments2(): void", "jsdoc comment\nanother jsDocComment");
223+
verify.signatureHelp({ marker: "7", docComment: "another jsDocComment" });
224+
verify.quickInfoAt("7q", "function jsDocMixedComments2(): void", "another jsDocComment");
225225

226-
verify.signatureHelp({ marker: "8", docComment: "jsdoc comment\n* triplestar jsDocComment" });
227-
verify.quickInfoAt("8q", "function jsDocMixedComments3(): void", "jsdoc comment\n* triplestar jsDocComment");
226+
verify.signatureHelp({ marker: "8", docComment: "* triplestar jsDocComment" });
227+
verify.quickInfoAt("8q", "function jsDocMixedComments3(): void", "* triplestar jsDocComment");
228228

229-
verify.signatureHelp({ marker: "9", docComment: "jsdoc comment\nanother jsDocComment" });
230-
verify.quickInfoAt("9q", "function jsDocMixedComments4(): void", "jsdoc comment\nanother jsDocComment");
229+
verify.signatureHelp({ marker: "9", docComment: "another jsDocComment" });
230+
verify.quickInfoAt("9q", "function jsDocMixedComments4(): void", "another jsDocComment");
231231

232-
verify.signatureHelp({ marker: "10", docComment: "jsdoc comment\nanother jsDocComment" });
233-
verify.quickInfoAt("10q", "function jsDocMixedComments5(): void", "jsdoc comment\nanother jsDocComment");
232+
verify.signatureHelp({ marker: "10", docComment: "another jsDocComment" });
233+
verify.quickInfoAt("10q", "function jsDocMixedComments5(): void", "another jsDocComment");
234234

235-
verify.signatureHelp({ marker: "11", docComment: "another jsDocComment\njsdoc comment" });
236-
verify.quickInfoAt("11q", "function jsDocMixedComments6(): void", "another jsDocComment\njsdoc comment");
235+
verify.signatureHelp({ marker: "11", docComment: "jsdoc comment" });
236+
verify.quickInfoAt("11q", "function jsDocMixedComments6(): void", "jsdoc comment");
237237

238238
verify.signatureHelp({ marker: "12", docComment: "" });
239239
verify.quickInfoAt("12q", "function noHelpComment1(): void");

tests/cases/fourslash/server/jsdocCallbackTag.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,15 @@ verify.signatureHelp({
3737
marker: '4',
3838
text: "t(eventName: string, eventName2: string | number, eventName3: any): number",
3939
parameterDocComment: "- So many words",
40-
tags: [{ name: "callback", text: "FooHandler - A kind of magic" },
41-
{ name: "type", text: "{FooHandler} callback" }]
40+
tags: [{ name: "type", text: "{FooHandler} callback" }]
4241
});
4342
verify.signatureHelp({
4443
marker: '5',
4544
parameterDocComment: "- Silence is golden",
46-
tags: [{ name: "callback", text: "FooHandler - A kind of magic" },
47-
{ name: "type", text: "{FooHandler} callback" }]
45+
tags: [{ name: "type", text: "{FooHandler} callback" }]
4846
});
4947
verify.signatureHelp({
5048
marker: '6',
5149
parameterDocComment: "- Osterreich mos def",
52-
tags: [{ name: "callback", text: "FooHandler - A kind of magic" },
53-
{ name: "type", text: "{FooHandler} callback" }]
50+
tags: [{ name: "type", text: "{FooHandler} callback" }]
5451
});

0 commit comments

Comments
 (0)