Skip to content

Commit

Permalink
Cherry-pick PR #46737 into release-4.5 (#46742)
Browse files Browse the repository at this point in the history
Component commits:
74cd7a5 fix extra newline

8df5bef Merge branch 'main' into gabritto/issue46609

67d631c fix test

Co-authored-by: Gabriela Araujo Britto <gabrielaa@microsoft.com>
  • Loading branch information
typescript-bot and gabritto committed Nov 9, 2021
1 parent 2857273 commit 3278641
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 50 deletions.
7 changes: 5 additions & 2 deletions src/services/completions.ts
Expand Up @@ -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);
Expand Down Expand Up @@ -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 };
Expand Down
34 changes: 13 additions & 21 deletions tests/cases/fourslash/completionsOverridingMethod.ts
Expand Up @@ -129,8 +129,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"foo(param1: string, param2: boolean): Promise<void> {\n}\n",
insertText: "foo(param1: string, param2: boolean): Promise<void> {\n}",
}
],
});
Expand All @@ -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}",
}
],
});
Expand All @@ -175,8 +173,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"foo(a: string): string {\n}\n",
insertText: "foo(a: string): string {\n}",
}
],
});
Expand All @@ -198,8 +195,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"foo(a: string): string {\n}\n",
insertText: "foo(a: string): string {\n}",
}
],
});
Expand All @@ -221,8 +217,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"foo(a: string): string {\n}\n",
insertText: "foo(a: string): string {\n}",
}
],
});
Expand All @@ -244,8 +239,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"foo(a: string): string {\n}\n",
insertText: "foo(a: string): string {\n}",
}
],
});
Expand All @@ -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 {
}`,
}
],
});
Expand Down Expand Up @@ -302,8 +297,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"met(n: number): number {\n}\n",
insertText: "met(n: number): number {\n}",
}
],
});
Expand All @@ -325,8 +319,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"met<T>(t: T): T {\n}\n",
insertText: "met<T>(t: T): T {\n}",
},
{
name: "metcons",
Expand All @@ -336,8 +329,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"metcons<T extends string | number>(t: T): T {\n}\n",
insertText: "metcons<T extends string | number>(t: T): T {\n}",
}
],
});
3 changes: 1 addition & 2 deletions tests/cases/fourslash/completionsOverridingMethod1.ts
Expand Up @@ -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}",
}
],
});
63 changes: 63 additions & 0 deletions tests/cases/fourslash/completionsOverridingMethod10.ts
@@ -0,0 +1,63 @@
/// <reference path="fourslash.ts" />

// @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 {
}`,
},
],
});
3 changes: 1 addition & 2 deletions tests/cases/fourslash/completionsOverridingMethod2.ts
Expand Up @@ -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}",
}
],
});
3 changes: 1 addition & 2 deletions tests/cases/fourslash/completionsOverridingMethod3.ts
Expand Up @@ -29,8 +29,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"boo(): string;\n",
insertText: "boo(): string;",
}
],
});
4 changes: 2 additions & 2 deletions tests/cases/fourslash/completionsOverridingMethod4.ts
Expand Up @@ -48,7 +48,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "protected hint(): string {\n}\n",
insertText: "protected hint(): string {\n}",
},
{
name: "refuse",
Expand All @@ -58,7 +58,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "public refuse(): string {\n}\n",
insertText: "public refuse(): string {\n}",
}
],
});
12 changes: 6 additions & 6 deletions tests/cases/fourslash/completionsOverridingMethod5.ts
Expand Up @@ -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",
Expand All @@ -44,7 +44,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "met2(n: number): void {\n}\n",
insertText: "met2(n: number): void {\n}",
}
],
});
Expand All @@ -66,7 +66,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "met(n: string): void;\n",
insertText: "met(n: string): void;",
},
{
name: "met2",
Expand All @@ -76,7 +76,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "met2(n: number): void;\n",
insertText: "met2(n: number): void;",
}
],
});
Expand All @@ -98,7 +98,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "met(n: string): void;\n",
insertText: "met(n: string): void;",
},
{
name: "met2",
Expand All @@ -108,7 +108,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "met2(n: number): void;\n",
insertText: "met2(n: number): void;",
}
],
});
Expand Down
11 changes: 6 additions & 5 deletions tests/cases/fourslash/completionsOverridingMethod6.ts
Expand Up @@ -43,7 +43,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "method(): number {\n}\n",
insertText: "method(): number {\n}",
},
],
});
Expand All @@ -65,7 +65,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "method(): number;\n",
insertText: "method(): number;",
},
],
});
Expand All @@ -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 {
}`,
},
],
});
3 changes: 1 addition & 2 deletions tests/cases/fourslash/completionsOverridingMethod7.ts
Expand Up @@ -31,8 +31,7 @@ verify.completions({
},
insertText:
`M<T>(t: T): void;
abstract M<T>(t: T, x: number): void;
`,
abstract M<T>(t: T, x: number): void;`,
},
],
});
2 changes: 1 addition & 1 deletion tests/cases/fourslash/completionsOverridingMethod8.ts
Expand Up @@ -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,
}],
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/fourslash/completionsOverridingMethod9.ts
Expand Up @@ -28,7 +28,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "a?: number;\n"
insertText: "a?: number;"
},
{
name: "b",
Expand All @@ -38,7 +38,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText: "b(x: number): void {\n}\n"
insertText: "b(x: number): void {\n}"
},
],
});
4 changes: 1 addition & 3 deletions tests/cases/fourslash/completionsOverridingProperties.ts
Expand Up @@ -5,7 +5,6 @@
// Case: Properties
////class Base {
//// protected foo: string = "bar";
////
////}
////
////class Sub extends Base {
Expand All @@ -32,8 +31,7 @@ verify.completions({
pos: 0,
end: 0,
},
insertText:
"protected foo: string;\n",
insertText: "protected foo: string;",
}
],
});

0 comments on commit 3278641

Please sign in to comment.