Skip to content

feat(27601): Copy JSDoc from type when destructing arguments #46886

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 1 commit into from
Feb 3, 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: 13 additions & 0 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,19 @@ namespace ts.SymbolDisplay {
}
}

if (documentation.length === 0 && isIdentifier(location) && symbol.valueDeclaration && isBindingElement(symbol.valueDeclaration)) {
const declaration = symbol.valueDeclaration;
const parent = declaration.parent;
if (isIdentifier(declaration.name) && isObjectBindingPattern(parent)) {
const name = getTextOfIdentifierOrLiteral(declaration.name);
const objectType = typeChecker.getTypeAtLocation(parent);
documentation = firstDefined(objectType.isUnion() ? objectType.types : [objectType], t => {
const prop = t.getProperty(name);
return prop ? prop.getDocumentationComment(typeChecker) : undefined;
}) || emptyArray;
}
}

if (tags.length === 0 && !hasMultipleSignatures) {
tags = symbol.getContextualJsDocTags(enclosingDeclaration, typeChecker);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName03.ts",
"position": 122,
"name": "1"
},
"quickInfo": {
"kind": "parameter",
"kindModifiers": "",
"textSpan": {
"start": 119,
"length": 3
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "parameter",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "foo",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
],
"documentation": [
{
"text": "A description of foo",
"kind": "text"
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName04.ts",
"position": 193,
"name": "1"
},
"quickInfo": {
"kind": "parameter",
"kindModifiers": "",
"textSpan": {
"start": 192,
"length": 1
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "parameter",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "{",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": " ",
"kind": "space"
},
{
"text": "b",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
},
{
"text": ";",
"kind": "punctuation"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "}",
"kind": "punctuation"
}
],
"documentation": [
{
"text": "A description of 'a'",
"kind": "text"
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName04.ts",
"position": 200,
"name": "2"
},
"quickInfo": {
"kind": "parameter",
"kindModifiers": "",
"textSpan": {
"start": 199,
"length": 1
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "parameter",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "b",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
],
"documentation": [
{
"text": "A description of 'b'",
"kind": "text"
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName05.ts",
"position": 137,
"name": ""
},
"quickInfo": {
"kind": "parameter",
"kindModifiers": "",
"textSpan": {
"start": 136,
"length": 1
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "parameter",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "|",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"documentation": [
{
"text": "A description of a",
"kind": "text"
}
]
}
}
]
14 changes: 14 additions & 0 deletions tests/cases/fourslash/quickInfoForObjectBindingElementName03.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

////interface Options {
//// /**
//// * A description of foo
//// */
//// foo: string;
////}
////
////function f({ foo }: Options) {
//// foo/*1*/;
////}

verify.baselineQuickInfo();
20 changes: 20 additions & 0 deletions tests/cases/fourslash/quickInfoForObjectBindingElementName04.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts" />

////interface Options {
//// /**
//// * A description of 'a'
//// */
//// a: {
//// /**
//// * A description of 'b'
//// */
//// b: string;
//// }
////}
////
////function f({ a, a: { b } }: Options) {
//// a/*1*/;
//// b/*2*/;
////}

verify.baselineQuickInfo();
17 changes: 17 additions & 0 deletions tests/cases/fourslash/quickInfoForObjectBindingElementName05.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />

////interface A {
//// /**
//// * A description of a
//// */
//// a: number;
////}
////interface B {
//// a: string;
////}
////
////function f({ a }: A | B) {
//// a/**/;
////}

verify.baselineQuickInfo();