From b00e37060501fad1d7e7b3c4387128b61d8372ce Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 17 Apr 2018 12:42:23 -0700 Subject: [PATCH] Add '?' in quick info for optional properties/methods (#23480) --- src/services/symbolDisplay.ts | 4 ++++ tests/cases/fourslash/findAllRefsForObjectSpread.ts | 4 ++-- .../findAllRefsObjectBindingElementPropertyName10.ts | 2 +- .../quickInfoForObjectBindingElementPropertyName03.ts | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 66367905af8..7431393df87 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -549,6 +549,10 @@ namespace ts.SymbolDisplay { const fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbolToDisplay, enclosingDeclaration || sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing | SymbolFormatFlags.AllowAnyNodeKind); addRange(displayParts, fullSymbolDisplayParts); + + if (symbol.flags & SymbolFlags.Optional) { + displayParts.push(punctuationPart(SyntaxKind.QuestionToken)); + } } function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) { diff --git a/tests/cases/fourslash/findAllRefsForObjectSpread.ts b/tests/cases/fourslash/findAllRefsForObjectSpread.ts index 970806922ed..c6f111672c8 100644 --- a/tests/cases/fourslash/findAllRefsForObjectSpread.ts +++ b/tests/cases/fourslash/findAllRefsForObjectSpread.ts @@ -12,12 +12,12 @@ const [r0, r1, r2, r3] = ranges; // members of spread types only refer to themselves and the resulting property verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2, r3] }]); -verify.referenceGroups(r1, [{ definition: "(property) A2.a: number", ranges: [r1, r2] }]); +verify.referenceGroups(r1, [{ definition: "(property) A2.a?: number", ranges: [r1, r2] }]); // but the resulting property refers to everything verify.referenceGroups(r2, [ { definition: "(property) A1.a: string", ranges: [r0, r2, r3] }, - { definition: "(property) A2.a: number", ranges: [r1] }, + { definition: "(property) A2.a?: number", ranges: [r1] }, ]); verify.referenceGroups(r3, [{ definition: "(property) A1.a: string", ranges: [r0, r2, r3] }]); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts index 1c79d326dbc..500ca7fe3cf 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts @@ -8,4 +8,4 @@ ////function f ({ [|next|]: { [|next|]: x} }: Recursive) { ////} -verify.singleReferenceGroup("(property) Recursive.next: Recursive"); +verify.singleReferenceGroup("(property) Recursive.next?: Recursive"); diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts index c29a7265eab..9378c99126c 100644 --- a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts @@ -9,5 +9,5 @@ ////} for (const marker of test.markerNames()) { - verify.quickInfoAt(marker, "(property) Recursive.next: Recursive"); + verify.quickInfoAt(marker, "(property) Recursive.next?: Recursive"); } \ No newline at end of file