Skip to content

Commit

Permalink
fix(55650): show quick info in JSDoc @implements tag
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Dec 26, 2023
1 parent d027e96 commit eb09afb
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 2 deletions.
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
106 changes: 106 additions & 0 deletions tests/baselines/reference/quickInfoJsDocTags15.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// === QuickInfo ===
=== /b.js ===
// import * as _a from "./a.js";
// /**
// * @implements {_a.Foo}
// ^^^
// | ----------------------------------------------------------------------
// | type Foo = {
// | getName: _a.Bar;
// | }
// | ----------------------------------------------------------------------
// */
// class Foo { }

[
{
"marker": {
"fileName": "/b.js",
"position": 56,
"name": "2"
},
"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": []
}
}
]
26 changes: 26 additions & 0 deletions tests/cases/fourslash/quickInfoJsDocTags15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <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/*2*/}
//// */
////class Foo { }

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

0 comments on commit eb09afb

Please sign in to comment.