fix(55939): JS Doc comment not shown in signature help when overload tag exists (#56139)

This commit is contained in:
Oleksandr T 2023-10-28 01:24:07 +03:00 committed by GitHub
parent a25321afce
commit f25f2bb75d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 404 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import {
isFunctionTypeNode,
isIdentifier,
isJSDoc,
isJSDocOverloadTag,
isJSDocParameterTag,
isJSDocPropertyLikeTag,
isJSDocTypeLiteral,
@ -230,6 +231,11 @@ function getCommentHavingNodes(declaration: Declaration): readonly (JSDoc | JSDo
case SyntaxKind.JSDocCallbackTag:
case SyntaxKind.JSDocTypedefTag:
return [declaration as JSDocTypedefTag, (declaration as JSDocTypedefTag).parent];
case SyntaxKind.JSDocSignature:
if (isJSDocOverloadTag(declaration.parent)) {
return [declaration.parent.parent];
}
// falls through
default:
return getJSDocCommentsAndTags(declaration);
}

View File

@ -0,0 +1,369 @@
// === SignatureHelp ===
=== /tests/cases/fourslash/./a.js ===
// /**
// * First overload
// * @overload
// * @param {number} a
// * @returns {void}
// */
//
// /**
// * Second overload
// * @overload
// * @param {string} a
// * @returns {void}
// */
//
// /**
// * @param {string | number} a
// * @returns {void}
// */
// function f(a) {}
//
// f(1);
// ^
// | ----------------------------------------------------------------------
// | f(**a: number**): void
// | First overload
// | ----------------------------------------------------------------------
// f("");
// ^
// | ----------------------------------------------------------------------
// | f(**a: string**): void
// | Second overload
// | ----------------------------------------------------------------------
[
{
"marker": {
"fileName": "/tests/cases/fourslash/./a.js",
"position": 238,
"name": "a"
},
"item": {
"items": [
{
"isVariadic": false,
"prefixDisplayParts": [
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
}
],
"suffixDisplayParts": [
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"separatorDisplayParts": [
{
"text": ",",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
}
],
"parameters": [
{
"name": "a",
"documentation": [],
"displayParts": [
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"isOptional": false,
"isRest": false
}
],
"documentation": [
{
"text": "First overload",
"kind": "text"
}
],
"tags": []
},
{
"isVariadic": false,
"prefixDisplayParts": [
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
}
],
"suffixDisplayParts": [
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"separatorDisplayParts": [
{
"text": ",",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
}
],
"parameters": [
{
"name": "a",
"documentation": [],
"displayParts": [
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
],
"isOptional": false,
"isRest": false
}
],
"documentation": [
{
"text": "Second overload",
"kind": "text"
}
],
"tags": []
}
],
"applicableSpan": {
"start": 238,
"length": 1
},
"selectedItemIndex": 0,
"argumentIndex": 0,
"argumentCount": 1
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/./a.js",
"position": 244,
"name": "b"
},
"item": {
"items": [
{
"isVariadic": false,
"prefixDisplayParts": [
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
}
],
"suffixDisplayParts": [
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"separatorDisplayParts": [
{
"text": ",",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
}
],
"parameters": [
{
"name": "a",
"documentation": [],
"displayParts": [
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"isOptional": false,
"isRest": false
}
],
"documentation": [
{
"text": "First overload",
"kind": "text"
}
],
"tags": []
},
{
"isVariadic": false,
"prefixDisplayParts": [
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
}
],
"suffixDisplayParts": [
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"separatorDisplayParts": [
{
"text": ",",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
}
],
"parameters": [
{
"name": "a",
"documentation": [],
"displayParts": [
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
],
"isOptional": false,
"isRest": false
}
],
"documentation": [
{
"text": "Second overload",
"kind": "text"
}
],
"tags": []
}
],
"applicableSpan": {
"start": 244,
"length": 2
},
"selectedItemIndex": 1,
"argumentIndex": 0,
"argumentCount": 1
}
}
]

View File

@ -0,0 +1,29 @@
/// <reference path="fourslash.ts" />
// @allowJs: true
// @checkJs: true
// @filename: ./a.js
/////**
//// * First overload
//// * @overload
//// * @param {number} a
//// * @returns {void}
//// */
////
/////**
//// * Second overload
//// * @overload
//// * @param {string} a
//// * @returns {void}
//// */
////
/////**
//// * @param {string | number} a
//// * @returns {void}
//// */
////function f(a) {}
////
////f(/*a*/1);
////f(/*b*/"");
verify.baselineSignatureHelp();