mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 01:39:28 -06:00
feat(27601): include JSDoc comments for destructuring arguments (#46886)
This commit is contained in:
parent
46d1cb11e2
commit
0d5abd8a15
@ -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);
|
||||
}
|
||||
|
||||
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,14 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface Options {
|
||||
//// /**
|
||||
//// * A description of foo
|
||||
//// */
|
||||
//// foo: string;
|
||||
////}
|
||||
////
|
||||
////function f({ foo }: Options) {
|
||||
//// foo/*1*/;
|
||||
////}
|
||||
|
||||
verify.baselineQuickInfo();
|
||||
@ -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();
|
||||
@ -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();
|
||||
Loading…
x
Reference in New Issue
Block a user