From 32786412dea7d11aabd691035c319bc2bb17158d Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Tue, 9 Nov 2021 12:10:03 -0800 Subject: [PATCH] Cherry-pick PR #46737 into release-4.5 (#46742) Component commits: 74cd7a5c6c fix extra newline 8df5bef4bd Merge branch 'main' into gabritto/issue46609 67d631cb28 fix test Co-authored-by: Gabriela Araujo Britto --- src/services/completions.ts | 7 ++- .../fourslash/completionsOverridingMethod.ts | 34 ++++------ .../fourslash/completionsOverridingMethod1.ts | 3 +- .../completionsOverridingMethod10.ts | 63 +++++++++++++++++++ .../fourslash/completionsOverridingMethod2.ts | 3 +- .../fourslash/completionsOverridingMethod3.ts | 3 +- .../fourslash/completionsOverridingMethod4.ts | 4 +- .../fourslash/completionsOverridingMethod5.ts | 12 ++-- .../fourslash/completionsOverridingMethod6.ts | 11 ++-- .../fourslash/completionsOverridingMethod7.ts | 3 +- .../fourslash/completionsOverridingMethod8.ts | 2 +- .../fourslash/completionsOverridingMethod9.ts | 4 +- .../completionsOverridingProperties.ts | 4 +- 13 files changed, 103 insertions(+), 50 deletions(-) create mode 100644 tests/cases/fourslash/completionsOverridingMethod10.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 7035722b3ec83..9b2747db14d2f 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -851,7 +851,7 @@ namespace ts.Completions { removeComments: true, module: options.module, target: options.target, - omitTrailingSemicolon: true, + omitTrailingSemicolon: false, newLine: getNewLineKind(getNewLineCharacter(options, maybeBind(host, host.getNewLine))), }); const importAdder = codefix.createImportAdder(sourceFile, program, preferences, host); @@ -923,7 +923,10 @@ namespace ts.Completions { isAbstract); if (completionNodes.length) { - insertText = printer.printSnippetList(ListFormat.MultiLine, factory.createNodeArray(completionNodes), sourceFile); + insertText = printer.printSnippetList( + ListFormat.MultiLine | ListFormat.NoTrailingNewLine, + factory.createNodeArray(completionNodes), + sourceFile); } return { insertText, isSnippet, importAdder }; diff --git a/tests/cases/fourslash/completionsOverridingMethod.ts b/tests/cases/fourslash/completionsOverridingMethod.ts index 997dc0a887b40..a45dae3f333ad 100644 --- a/tests/cases/fourslash/completionsOverridingMethod.ts +++ b/tests/cases/fourslash/completionsOverridingMethod.ts @@ -129,8 +129,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"foo(param1: string, param2: boolean): Promise {\n}\n", + insertText: "foo(param1: string, param2: boolean): Promise {\n}", } ], }); @@ -152,8 +151,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"foo(a: string, b: string): string {\n}\n", + insertText: "foo(a: string, b: string): string {\n}", } ], }); @@ -175,8 +173,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"foo(a: string): string {\n}\n", + insertText: "foo(a: string): string {\n}", } ], }); @@ -198,8 +195,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"foo(a: string): string {\n}\n", + insertText: "foo(a: string): string {\n}", } ], }); @@ -221,8 +217,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"foo(a: string): string {\n}\n", + insertText: "foo(a: string): string {\n}", } ], }); @@ -244,8 +239,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"foo(a: string): string {\n}\n", + insertText: "foo(a: string): string {\n}", } ], }); @@ -268,9 +262,10 @@ verify.completions({ end: 0, }, insertText: -"foo(a: string): string;\n\ -foo(a: undefined, b: number): string;\n\ -foo(a: any, b?: any): string {\n}\n", +`foo(a: string): string; +foo(a: undefined, b: number): string; +foo(a: any, b?: any): string { +}`, } ], }); @@ -302,8 +297,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"met(n: number): number {\n}\n", + insertText: "met(n: number): number {\n}", } ], }); @@ -325,8 +319,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"met(t: T): T {\n}\n", + insertText: "met(t: T): T {\n}", }, { name: "metcons", @@ -336,8 +329,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"metcons(t: T): T {\n}\n", + insertText: "metcons(t: T): T {\n}", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod1.ts b/tests/cases/fourslash/completionsOverridingMethod1.ts index 395e4272d86e4..8b59ca919bf24 100644 --- a/tests/cases/fourslash/completionsOverridingMethod1.ts +++ b/tests/cases/fourslash/completionsOverridingMethod1.ts @@ -30,8 +30,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"override foo(a: string): void {\n}\n", + insertText: "override foo(a: string): void {\n}", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod10.ts b/tests/cases/fourslash/completionsOverridingMethod10.ts new file mode 100644 index 0000000000000..77da16fb4dd73 --- /dev/null +++ b/tests/cases/fourslash/completionsOverridingMethod10.ts @@ -0,0 +1,63 @@ +/// + +// @Filename: a.ts +// @newline: LF +// Case: formatting: semicolons +////interface Base { +//// a: string; +//// b(a: string): void; +//// c(a: string): string; +//// c(a: number): number; +////} +////class Sub implements Base { +//// /*a*/ +////} + + +verify.completions({ + marker: "a", + isNewIdentifierLocation: true, + preferences: { + includeCompletionsWithInsertText: true, + includeCompletionsWithSnippetText: false, + includeCompletionsWithClassMemberSnippets: true, + }, + includes: [ + { + name: "a", + sortText: completion.SortText.LocationPriority, + replacementSpan: { + fileName: "", + pos: 0, + end: 0, + }, + insertText: "a: string;", + }, + { + name: "b", + sortText: completion.SortText.LocationPriority, + replacementSpan: { + fileName: "", + pos: 0, + end: 0, + }, + insertText: +`b(a: string): void { +}`, + }, + { + name: "c", + sortText: completion.SortText.LocationPriority, + replacementSpan: { + fileName: "", + pos: 0, + end: 0, + }, + insertText: +`c(a: string): string; +c(a: number): number; +c(a: any): string | number { +}`, + }, + ], +}); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod2.ts b/tests/cases/fourslash/completionsOverridingMethod2.ts index b4fdf1f3c35d0..f479259d18c42 100644 --- a/tests/cases/fourslash/completionsOverridingMethod2.ts +++ b/tests/cases/fourslash/completionsOverridingMethod2.ts @@ -29,8 +29,7 @@ verify.completions({ end: 0, }, isSnippet: true, - insertText: -"\"\\$usd\"(a: number): number {\n $0\n}\n", + insertText: "\"\\$usd\"(a: number): number {\n $0\n}", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod3.ts b/tests/cases/fourslash/completionsOverridingMethod3.ts index 1cb0bd646801f..c6ffd11c37a14 100644 --- a/tests/cases/fourslash/completionsOverridingMethod3.ts +++ b/tests/cases/fourslash/completionsOverridingMethod3.ts @@ -29,8 +29,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"boo(): string;\n", + insertText: "boo(): string;", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod4.ts b/tests/cases/fourslash/completionsOverridingMethod4.ts index 35da54835f8c1..6b70dda01154c 100644 --- a/tests/cases/fourslash/completionsOverridingMethod4.ts +++ b/tests/cases/fourslash/completionsOverridingMethod4.ts @@ -48,7 +48,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "protected hint(): string {\n}\n", + insertText: "protected hint(): string {\n}", }, { name: "refuse", @@ -58,7 +58,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "public refuse(): string {\n}\n", + insertText: "public refuse(): string {\n}", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod5.ts b/tests/cases/fourslash/completionsOverridingMethod5.ts index 80e74160196da..58c03962e47ba 100644 --- a/tests/cases/fourslash/completionsOverridingMethod5.ts +++ b/tests/cases/fourslash/completionsOverridingMethod5.ts @@ -34,7 +34,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "met(n: string): void {\n}\n", + insertText: "met(n: string): void {\n}", }, { name: "met2", @@ -44,7 +44,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "met2(n: number): void {\n}\n", + insertText: "met2(n: number): void {\n}", } ], }); @@ -66,7 +66,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "met(n: string): void;\n", + insertText: "met(n: string): void;", }, { name: "met2", @@ -76,7 +76,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "met2(n: number): void;\n", + insertText: "met2(n: number): void;", } ], }); @@ -98,7 +98,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "met(n: string): void;\n", + insertText: "met(n: string): void;", }, { name: "met2", @@ -108,7 +108,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "met2(n: number): void;\n", + insertText: "met2(n: number): void;", } ], }); diff --git a/tests/cases/fourslash/completionsOverridingMethod6.ts b/tests/cases/fourslash/completionsOverridingMethod6.ts index d6828a6e30450..d9bb2bb7843a1 100644 --- a/tests/cases/fourslash/completionsOverridingMethod6.ts +++ b/tests/cases/fourslash/completionsOverridingMethod6.ts @@ -43,7 +43,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "method(): number {\n}\n", + insertText: "method(): number {\n}", }, ], }); @@ -65,7 +65,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "method(): number;\n", + insertText: "method(): number;", }, ], }); @@ -88,9 +88,10 @@ verify.completions({ end: 0, }, insertText: - "fun(a: number): number;\n\ -public fun(a: undefined, b: string): number;\n\ -public fun(a: any, b?: any): number {\n}\n", +`fun(a: number): number; +public fun(a: undefined, b: string): number; +public fun(a: any, b?: any): number { +}`, }, ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod7.ts b/tests/cases/fourslash/completionsOverridingMethod7.ts index f0e3b5df5a252..0fa6c30643ad7 100644 --- a/tests/cases/fourslash/completionsOverridingMethod7.ts +++ b/tests/cases/fourslash/completionsOverridingMethod7.ts @@ -31,8 +31,7 @@ verify.completions({ }, insertText: `M(t: T): void; -abstract M(t: T, x: number): void; -`, +abstract M(t: T, x: number): void;`, }, ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod8.ts b/tests/cases/fourslash/completionsOverridingMethod8.ts index 9724dfee22abe..fced40bd21e2e 100644 --- a/tests/cases/fourslash/completionsOverridingMethod8.ts +++ b/tests/cases/fourslash/completionsOverridingMethod8.ts @@ -32,7 +32,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "method(p: I): void {\n}\n", + insertText: "method(p: I): void {\n}", hasAction: true, source: completion.CompletionSource.ClassMemberSnippet, }], diff --git a/tests/cases/fourslash/completionsOverridingMethod9.ts b/tests/cases/fourslash/completionsOverridingMethod9.ts index 8f9cac56feb8a..76f91a68c2b7e 100644 --- a/tests/cases/fourslash/completionsOverridingMethod9.ts +++ b/tests/cases/fourslash/completionsOverridingMethod9.ts @@ -28,7 +28,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "a?: number;\n" + insertText: "a?: number;" }, { name: "b", @@ -38,7 +38,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: "b(x: number): void {\n}\n" + insertText: "b(x: number): void {\n}" }, ], }); diff --git a/tests/cases/fourslash/completionsOverridingProperties.ts b/tests/cases/fourslash/completionsOverridingProperties.ts index b930255e28c60..fad97f78fd6d5 100644 --- a/tests/cases/fourslash/completionsOverridingProperties.ts +++ b/tests/cases/fourslash/completionsOverridingProperties.ts @@ -5,7 +5,6 @@ // Case: Properties ////class Base { //// protected foo: string = "bar"; -//// ////} //// ////class Sub extends Base { @@ -32,8 +31,7 @@ verify.completions({ pos: 0, end: 0, }, - insertText: -"protected foo: string;\n", + insertText: "protected foo: string;", } ], }); \ No newline at end of file