From d2fbd1e6e5ce39a6207f992a2bae435976cc9347 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 27 Dec 2020 21:15:10 +0800 Subject: [PATCH] Add test suits and tests --- src/harness/fourslashImpl.ts | 12 ++++++ src/harness/fourslashInterfaceImpl.ts | 11 ++++++ src/services/inlineHints.ts | 2 +- tests/cases/fourslash/fourslash.ts | 14 +++++++ .../cases/fourslash/inlineHintsShouldWork1.ts | 20 ++++++++++ .../fourslash/inlineHintsShouldWork10.ts | 9 +++++ .../fourslash/inlineHintsShouldWork11.ts | 24 ++++++++++++ .../fourslash/inlineHintsShouldWork12.ts | 23 ++++++++++++ .../fourslash/inlineHintsShouldWork13.ts | 16 ++++++++ .../fourslash/inlineHintsShouldWork14.ts | 8 ++++ .../fourslash/inlineHintsShouldWork15.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork16.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork17.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork18.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork19.ts | 14 +++++++ .../cases/fourslash/inlineHintsShouldWork2.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork20.ts | 7 ++++ .../fourslash/inlineHintsShouldWork21.ts | 7 ++++ .../fourslash/inlineHintsShouldWork22.ts | 14 +++++++ .../fourslash/inlineHintsShouldWork23.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork24.ts | 20 ++++++++++ .../fourslash/inlineHintsShouldWork25.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork26.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork27.ts | 22 +++++++++++ .../fourslash/inlineHintsShouldWork28.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork29.ts | 33 +++++++++++++++++ .../cases/fourslash/inlineHintsShouldWork3.ts | 20 ++++++++++ .../fourslash/inlineHintsShouldWork30.ts | 15 ++++++++ .../fourslash/inlineHintsShouldWork31.ts | 18 +++++++++ .../cases/fourslash/inlineHintsShouldWork4.ts | 29 +++++++++++++++ .../cases/fourslash/inlineHintsShouldWork5.ts | 26 +++++++++++++ .../cases/fourslash/inlineHintsShouldWork6.ts | 16 ++++++++ .../cases/fourslash/inlineHintsShouldWork7.ts | 30 +++++++++++++++ .../cases/fourslash/inlineHintsShouldWork8.ts | 30 +++++++++++++++ .../cases/fourslash/inlineHintsShouldWork9.ts | 37 +++++++++++++++++++ 35 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/inlineHintsShouldWork1.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork10.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork11.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork12.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork13.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork14.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork15.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork16.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork17.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork18.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork19.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork2.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork20.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork21.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork22.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork23.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork24.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork25.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork26.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork27.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork28.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork29.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork3.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork30.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork31.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork4.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork5.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork6.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork7.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork8.ts create mode 100644 tests/cases/fourslash/inlineHintsShouldWork9.ts diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 551ac9aef1889..5815de1d14ab4 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -824,6 +824,18 @@ namespace FourSlash { }); } + public verifyInlineHints(expected: readonly FourSlashInterface.VerifyInlineHintsOptions[], span: ts.TextSpan = { start: 0, length: this.activeFile.content.length }, preference?: ts.InlineHintsOptions) { + const hints = this.languageService.provideInlineHints(this.activeFile.fileName, span, preference); + assert.equal(hints.length, expected.length, "Number of hints"); + const sortHints = (a: ts.InlineHint, b: ts.InlineHint) => a.position - b.position; + ts.zipWith(hints.sort(sortHints), [...expected].sort(sortHints), (actual, expected) => { + assert.equal(actual.text, expected.text, "Text"); + assert.equal(actual.position, expected.position, "Position"); + assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore"); + assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter"); + }); + } + public verifyCompletions(options: FourSlashInterface.VerifyCompletionsOptions) { if (options.marker === undefined) { this.verifyCompletionsWorker(options); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 6fd2d834039d2..d2b226f6ef129 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -243,6 +243,10 @@ namespace FourSlashInterface { } } + public getInlineHints(expected: readonly VerifyInlineHintsOptions[], span: ts.TextSpan, preference?: ts.InlineHintsOptions) { + this.state.verifyInlineHints(expected, span, preference); + } + public quickInfoIs(expectedText: string, expectedDocumentation?: string) { this.state.verifyQuickInfoString(expectedText, expectedDocumentation); } @@ -1645,6 +1649,13 @@ namespace FourSlashInterface { readonly containerKind?: ts.ScriptElementKind; } + export interface VerifyInlineHintsOptions { + text: string; + position: number + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; + } + export type ArrayOrSingle = T | readonly T[]; export interface VerifyCompletionListContainsOptions extends ts.UserPreferences { diff --git a/src/services/inlineHints.ts b/src/services/inlineHints.ts index 87b07268d000a..18fe79f7a3aa4 100644 --- a/src/services/inlineHints.ts +++ b/src/services/inlineHints.ts @@ -7,7 +7,7 @@ namespace ts.InlineHints { whitespaceAfter?: boolean; } - const maxHintsLength = 20; + const maxHintsLength = 30; export function provideInlineHints(context: InlineHintsContext): HintInfo[] { const { file, program, span, cancellationToken, preferences } = context; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index d2ea70036a4b5..9918613ae0c8d 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -381,6 +381,7 @@ declare namespace FourSlashInterface { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: { name: string, text?: string }[] | undefined): void; + getInlineHints(expected: readonly VerifyInlineHintsOptions[], span?: TextSpan, preference?: InlineHintsOptions); getSyntacticDiagnostics(expected: ReadonlyArray): void; getSemanticDiagnostics(expected: ReadonlyArray): void; getSuggestionDiagnostics(expected: ReadonlyArray): void; @@ -614,6 +615,11 @@ declare namespace FourSlashInterface { readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative"; readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; } + interface InlineHintsOptions extends UserPreferences { + readonly includeInlineParameterName?: boolean; + readonly includeInlineFunctionParameterType?: boolean; + readonly includeInlineVariableType?: boolean; + } interface CompletionsOptions { readonly marker?: ArrayOrSingle; readonly isNewIdentifierLocation?: boolean; @@ -711,6 +717,14 @@ declare namespace FourSlashInterface { readonly commands?: ReadonlyArray<{}>; } + export interface VerifyInlineHintsOptions { + text: string; + position: number + whitespaceBefore?: boolean; + whitespaceAfter?: boolean; + } + + interface VerifyNavigateToOptions { readonly pattern: string; readonly fileName?: string; diff --git a/tests/cases/fourslash/inlineHintsShouldWork1.ts b/tests/cases/fourslash/inlineHintsShouldWork1.ts new file mode 100644 index 0000000000000..2a4fd5e60b85b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork1.ts @@ -0,0 +1,20 @@ +/// + +//// function foo (a: number, b: number) {} +//// foo(/*a*/1, /*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork10.ts b/tests/cases/fourslash/inlineHintsShouldWork10.ts new file mode 100644 index 0000000000000..5cbe1a8309604 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork10.ts @@ -0,0 +1,9 @@ +/// + +//// declare const unknownCall: any; +//// unknownCall(); + +const markers = test.markers(); +verify.getInlineHints([], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork11.ts b/tests/cases/fourslash/inlineHintsShouldWork11.ts new file mode 100644 index 0000000000000..f8af60f41d19a --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork11.ts @@ -0,0 +1,24 @@ +/// + +//// function foo(a: number) { +//// return (b: number) => { +//// return a + b +//// } +//// } +//// foo(/*a*/1)(/*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork12.ts b/tests/cases/fourslash/inlineHintsShouldWork12.ts new file mode 100644 index 0000000000000..2ad65c3e1a7b1 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork12.ts @@ -0,0 +1,23 @@ +/// + +//// function foo(a: (b: number) => number) { +//// return a(/*a*/1) + 2 +//// } + +//// foo(/*b*/(c: number) => c + 1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'b:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork13.ts b/tests/cases/fourslash/inlineHintsShouldWork13.ts new file mode 100644 index 0000000000000..e88e0ffb02e3b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork13.ts @@ -0,0 +1,16 @@ +/// + +//// function foo (a: number, b: number) {} +//// declare const a: 1; +//// foo(a, /*b*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'b:', + position: markers[0].position, + whitespaceAfter: true + }, +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork14.ts b/tests/cases/fourslash/inlineHintsShouldWork14.ts new file mode 100644 index 0000000000000..4181305b842a7 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork14.ts @@ -0,0 +1,8 @@ +/// + +//// function foo (a: number, b: number) {} +//// foo(1, 2); + +verify.getInlineHints([], undefined, { + includeInlineParameterName: false +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork15.ts b/tests/cases/fourslash/inlineHintsShouldWork15.ts new file mode 100644 index 0000000000000..5668f2eaec8ac --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork15.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = 123; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':123', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork16.ts b/tests/cases/fourslash/inlineHintsShouldWork16.ts new file mode 100644 index 0000000000000..5668f2eaec8ac --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork16.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = 123; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':123', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork17.ts b/tests/cases/fourslash/inlineHintsShouldWork17.ts new file mode 100644 index 0000000000000..32dfbf4b66363 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork17.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = { a: 123 }; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':{ a: number; }', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork18.ts b/tests/cases/fourslash/inlineHintsShouldWork18.ts new file mode 100644 index 0000000000000..dfec616b21c40 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork18.ts @@ -0,0 +1,15 @@ +/// + +//// class Class {} +//// const a/*a*/ = new Class(); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':Class', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork19.ts b/tests/cases/fourslash/inlineHintsShouldWork19.ts new file mode 100644 index 0000000000000..e7ebbc99f84e1 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork19.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = () => 123; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':() => number', + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork2.ts b/tests/cases/fourslash/inlineHintsShouldWork2.ts new file mode 100644 index 0000000000000..3f52c17e0153b --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork2.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (a: number, { c }: any) {} +//// foo(/*a*/1, { c: 1}); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork20.ts b/tests/cases/fourslash/inlineHintsShouldWork20.ts new file mode 100644 index 0000000000000..db6719bfbfcdb --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork20.ts @@ -0,0 +1,7 @@ +/// + +//// const a = 123; + +verify.getInlineHints([], undefined, { + includeInlineVariableType: false +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork21.ts b/tests/cases/fourslash/inlineHintsShouldWork21.ts new file mode 100644 index 0000000000000..15b92c2096ac3 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork21.ts @@ -0,0 +1,7 @@ +/// + +//// const a; + +verify.getInlineHints([], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork22.ts b/tests/cases/fourslash/inlineHintsShouldWork22.ts new file mode 100644 index 0000000000000..4b26abd6c202d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork22.ts @@ -0,0 +1,14 @@ +/// + +//// const a/*a*/ = "I'm very very very very very very very very very long"; + +const markers = test.markers(); +verify.getInlineHints([ + { + text: `:"I'm very very very very ve...`, + position: markers[0].position, + whitespaceBefore: true + }, +], undefined, { + includeInlineVariableType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork23.ts b/tests/cases/fourslash/inlineHintsShouldWork23.ts new file mode 100644 index 0000000000000..7a9536da8d8bf --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork23.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (Im_very_very_very_very_very_very_very_long: number) {} +//// foo(/*a*/1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'Im_very_very_very_very_very...:', + position: markers[0].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork24.ts b/tests/cases/fourslash/inlineHintsShouldWork24.ts new file mode 100644 index 0000000000000..527b5b17c28ee --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork24.ts @@ -0,0 +1,20 @@ +/// + +//// type F = (a: string, b: number) => void +//// const f: F = (a/*a*/, b/*b*/) => { } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: ':number', + position: markers[1].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork25.ts b/tests/cases/fourslash/inlineHintsShouldWork25.ts new file mode 100644 index 0000000000000..a75947f8e6eae --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork25.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (cb: (a: string) => void) {} +//// foo((a/*a*/) => { }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork26.ts b/tests/cases/fourslash/inlineHintsShouldWork26.ts new file mode 100644 index 0000000000000..5165e0462c89a --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork26.ts @@ -0,0 +1,15 @@ +/// + +//// function foo (cb: (a: Exclude<1 | 2 | 3, 1>) => void) {} +//// foo((a/*a*/) => { }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':Exclude<1 | 2 | 3, 1>', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork27.ts b/tests/cases/fourslash/inlineHintsShouldWork27.ts new file mode 100644 index 0000000000000..e637fd55b7a0d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork27.ts @@ -0,0 +1,22 @@ +/// + +//// function foo (a: (b: (c: (d: Exclude<1 | 2 | 3, 1>) => void) => void) => void) {} +//// foo(a/*a*/ => { +//// a(d/*b*/ => {}) +//// }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':(c: (d: Exclude<1 | 2 | 3, ...', + position: markers[0].position, + whitespaceBefore: true + }, + { + text: ':Exclude<1 | 2 | 3, 1>', + position: markers[1].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork28.ts b/tests/cases/fourslash/inlineHintsShouldWork28.ts new file mode 100644 index 0000000000000..b04c846cd49c4 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork28.ts @@ -0,0 +1,15 @@ +/// + +//// type F = (a: string, b: number) => void +//// const f: F = (a/*a*/, b: number) => { } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':string', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork29.ts b/tests/cases/fourslash/inlineHintsShouldWork29.ts new file mode 100644 index 0000000000000..12d0f7d44cad5 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork29.ts @@ -0,0 +1,33 @@ +/// + +//// function foo (a: (b: (c: (d: Exclude<1 | 2 | 3, 1>) => void) => void) => void) {} +//// foo(/*a*/a/*b*/ => { +//// a(/*c*/d/*d*/ => {}) +//// }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: ':(c: (d: Exclude<1 | 2 | 3, ...', + position: markers[1].position, + whitespaceBefore: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + }, + { + text: ':Exclude<1 | 2 | 3, 1>', + position: markers[3].position, + whitespaceBefore: true + } +], undefined, { + includeInlineParameterName: true, + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork3.ts b/tests/cases/fourslash/inlineHintsShouldWork3.ts new file mode 100644 index 0000000000000..4efe2728d1b13 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork3.ts @@ -0,0 +1,20 @@ +/// + +//// function foo (a: number, ...b: number[]) {} +//// foo(/*a*/1, /*b*/1, 1, 1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork30.ts b/tests/cases/fourslash/inlineHintsShouldWork30.ts new file mode 100644 index 0000000000000..1d8af95a9e687 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork30.ts @@ -0,0 +1,15 @@ +/// + +//// function f(v: T, a: (v: T) => void) {} +//// f(1, a/*a*/ => { }) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':T', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork31.ts b/tests/cases/fourslash/inlineHintsShouldWork31.ts new file mode 100644 index 0000000000000..9f015881eb216 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork31.ts @@ -0,0 +1,18 @@ +/// + +//// type F = (a: { +//// a: number +//// b: string +//// }) => void +//// const f: F = (a/*a*/) => { } + +const markers = test.markers(); +verify.getInlineHints([ + { + text: ':{ a: number; b: string; }', + position: markers[0].position, + whitespaceBefore: true + } +], undefined, { + includeInlineFunctionParameterType: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork4.ts b/tests/cases/fourslash/inlineHintsShouldWork4.ts new file mode 100644 index 0000000000000..1686b08d6e8d3 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork4.ts @@ -0,0 +1,29 @@ +/// + +//// declare function foo(w: number): void +//// declare function foo(a: number, b: number): void; +//// declare function foo(a: number | undefined, b: number | undefined): void; + +//// foo(/*a*/1) +//// foo(/*b*/1, /*c*/2) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'w:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork5.ts b/tests/cases/fourslash/inlineHintsShouldWork5.ts new file mode 100644 index 0000000000000..9d4582b541040 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork5.ts @@ -0,0 +1,26 @@ +/// + +//// type Args = [a: number, b: number] +//// declare function foo(c: number, ...args: Args); +//// foo(/*a*/1, /*b*/2, /*c*/3) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'c:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'a:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork6.ts b/tests/cases/fourslash/inlineHintsShouldWork6.ts new file mode 100644 index 0000000000000..388e1286f6247 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork6.ts @@ -0,0 +1,16 @@ +/// + +//// type Args = [number, number] +//// declare function foo(c: number, ...args: Args); +//// foo(/*a*/1, 2, 3) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'c:', + position: markers[0].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork7.ts b/tests/cases/fourslash/inlineHintsShouldWork7.ts new file mode 100644 index 0000000000000..624914c83e89d --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork7.ts @@ -0,0 +1,30 @@ +/// + +//// interface Call { +//// (a: number): void +//// (b: number, c: number): void +//// } +//// declare const call: Call; +//// call(/*a*/1); +//// call(/*b*/1, /*c*/2); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork8.ts b/tests/cases/fourslash/inlineHintsShouldWork8.ts new file mode 100644 index 0000000000000..77fe2067182f9 --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork8.ts @@ -0,0 +1,30 @@ +/// + +//// class Class { +//// constructor(a: number); +//// constructor(b: number, c: number); +//// constructor(b: number, c?: number) { } +//// } +//// new Class(/*a*/1) +//// new Class(/*b*/1, /*c*/2) + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +}); diff --git a/tests/cases/fourslash/inlineHintsShouldWork9.ts b/tests/cases/fourslash/inlineHintsShouldWork9.ts new file mode 100644 index 0000000000000..84ec6d92574cb --- /dev/null +++ b/tests/cases/fourslash/inlineHintsShouldWork9.ts @@ -0,0 +1,37 @@ +/// + +//// interface Call { +//// (a: number): void +//// (b: number, c: number): void +//// new (d: number): Call +//// } +//// declare const call: Call; +//// call(/*a*/1); +//// call(/*b*/1, /*c*/2); +//// new call(/*d*/1); + +const markers = test.markers(); +verify.getInlineHints([ + { + text: 'a:', + position: markers[0].position, + whitespaceAfter: true + }, + { + text: 'b:', + position: markers[1].position, + whitespaceAfter: true + }, + { + text: 'c:', + position: markers[2].position, + whitespaceAfter: true + }, + { + text: 'd:', + position: markers[3].position, + whitespaceAfter: true + } +], undefined, { + includeInlineParameterName: true +});