Skip to content

fix(55650): Wrong/missing quick info in JSDoc @implements tag #56884

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
Jan 9, 2024
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
11 changes: 9 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ import {
isJSDoc,
isJSDocAugmentsTag,
isJSDocFunctionType,
isJSDocImplementsTag,
isJSDocLinkLike,
isJSDocMemberName,
isJSDocNameReference,
Expand Down Expand Up @@ -2452,7 +2453,7 @@ export function isPartOfTypeNode(node: Node): boolean {
case SyntaxKind.VoidKeyword:
return node.parent.kind !== SyntaxKind.VoidExpression;
case SyntaxKind.ExpressionWithTypeArguments:
return isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
return isPartOfTypeExpressionWithTypeArguments(node);
case SyntaxKind.TypeParameter:
return node.parent.kind === SyntaxKind.MappedType || node.parent.kind === SyntaxKind.InferType;

Expand Down Expand Up @@ -2491,7 +2492,7 @@ export function isPartOfTypeNode(node: Node): boolean {
}
switch (parent.kind) {
case SyntaxKind.ExpressionWithTypeArguments:
return isHeritageClause(parent.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
return isPartOfTypeExpressionWithTypeArguments(parent);
case SyntaxKind.TypeParameter:
return node === (parent as TypeParameterDeclaration).constraint;
case SyntaxKind.JSDocTemplateTag:
Expand Down Expand Up @@ -2527,6 +2528,12 @@ export function isPartOfTypeNode(node: Node): boolean {
return false;
}

function isPartOfTypeExpressionWithTypeArguments(node: Node) {
return isJSDocImplementsTag(node.parent)
|| isJSDocAugmentsTag(node.parent)
|| isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
}

/** @internal */
export function isChildOfNodeWithKind(node: Node, kind: SyntaxKind): boolean {
while (node) {
Expand Down
308 changes: 308 additions & 0 deletions tests/baselines/reference/quickInfoJsDocTags15.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
// === QuickInfo ===
=== /b.js ===
// import * as _a from "./a.js";
// /**
// * @implements {_a.Foo}
// ^^^
// | ----------------------------------------------------------------------
// | type Foo = {
// | getName: _a.Bar;
// | }
// | ----------------------------------------------------------------------
// */
// class C1 { }
//
// /**
// * @extends {_a.Foo}
// ^^^
// | ----------------------------------------------------------------------
// | type Foo = {
// | getName: _a.Bar;
// | }
// | ----------------------------------------------------------------------
// */
// class C2 { }
//
// /**
// * @augments {_a.Foo}
// ^^^
// | ----------------------------------------------------------------------
// | type Foo = {
// | getName: _a.Bar;
// | }
// | ----------------------------------------------------------------------
// */
// class C3 { }

[
{
"marker": {
"fileName": "/b.js",
"position": 56,
"name": "1"
},
"item": {
"kind": "type",
"kindModifiers": "",
"textSpan": {
"start": 53,
"length": 3
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "{",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": " ",
"kind": "space"
},
{
"text": "getName",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "_a",
"kind": "aliasName"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "Bar",
"kind": "aliasName"
},
{
"text": ";",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "}",
"kind": "punctuation"
}
],
"documentation": []
}
},
{
"marker": {
"fileName": "/b.js",
"position": 99,
"name": "2"
},
"item": {
"kind": "type",
"kindModifiers": "",
"textSpan": {
"start": 96,
"length": 3
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "{",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": " ",
"kind": "space"
},
{
"text": "getName",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "_a",
"kind": "aliasName"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "Bar",
"kind": "aliasName"
},
{
"text": ";",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "}",
"kind": "punctuation"
}
],
"documentation": []
}
},
{
"marker": {
"fileName": "/b.js",
"position": 143,
"name": "3"
},
"item": {
"kind": "type",
"kindModifiers": "",
"textSpan": {
"start": 140,
"length": 3
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "{",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": " ",
"kind": "space"
},
{
"text": "getName",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "_a",
"kind": "aliasName"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "Bar",
"kind": "aliasName"
},
{
"text": ";",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "}",
"kind": "punctuation"
}
],
"documentation": []
}
}
]
36 changes: 36 additions & 0 deletions tests/cases/fourslash/quickInfoJsDocTags15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference path="fourslash.ts" />

// @allowJs: true
// @checkJs: true
// @filename: /a.js
/////**
//// * @callback Bar
//// * @param {string} name
//// * @returns {string}
//// */
////
/////**
//// * @typedef Foo
//// * @property {Bar} getName
//// */
////export const foo = 1;

// @filename: /b.js
////import * as _a from "./a.js";
/////**
//// * @implements {_a.Foo/*1*/}
//// */
////class C1 { }
////
/////**
//// * @extends {_a.Foo/*2*/}
//// */
////class C2 { }
////
/////**
//// * @augments {_a.Foo/*3*/}
//// */
////class C3 { }

goTo.file("/b.js")
verify.baselineQuickInfo();