Skip to content

Commit 7406ee9

Browse files
authoredOct 17, 2022
fix(51170): Completing an unimplemented property overwrites rest of line (#51175)
* fix(51170): skip insertText for class members with existing initializer * skip insertText for class members with existing tokens
1 parent a1d82fc commit 7406ee9

4 files changed

+45
-2
lines changed
 

‎src/services/completions.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ namespace ts.Completions {
764764
if (preferences.includeCompletionsWithClassMemberSnippets &&
765765
preferences.includeCompletionsWithInsertText &&
766766
completionKind === CompletionKind.MemberLike &&
767-
isClassLikeMemberCompletion(symbol, location)) {
767+
isClassLikeMemberCompletion(symbol, location, sourceFile)) {
768768
let importAdder;
769769
({ insertText, isSnippet, importAdder, replacementSpan } = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext));
770770
sortText = SortText.ClassMemberSnippets; // sortText has to be lower priority than the sortText for keywords. See #47852.
@@ -846,7 +846,7 @@ namespace ts.Completions {
846846
};
847847
}
848848

849-
function isClassLikeMemberCompletion(symbol: Symbol, location: Node): boolean {
849+
function isClassLikeMemberCompletion(symbol: Symbol, location: Node, sourceFile: SourceFile): boolean {
850850
// TODO: support JS files.
851851
if (isInJSFile(location)) {
852852
return false;
@@ -884,6 +884,7 @@ namespace ts.Completions {
884884
location.parent.parent &&
885885
isClassElement(location.parent) &&
886886
location === location.parent.name &&
887+
location.parent.getLastToken(sourceFile) === location.parent.name &&
887888
isClassLike(location.parent.parent)
888889
) ||
889890
(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface I {
4+
//// prop: string;
5+
////}
6+
////class C implements I {
7+
//// public pr/**/: string = 'foo';
8+
////}
9+
10+
verify.completions({
11+
marker: "",
12+
includes: [
13+
{ name: "prop", isSnippet: undefined, insertText: undefined }
14+
],
15+
isNewIdentifierLocation: true,
16+
preferences: {
17+
includeCompletionsWithInsertText: true,
18+
includeCompletionsWithSnippetText: true,
19+
includeCompletionsWithClassMemberSnippets: true,
20+
}
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface I {
4+
//// prop: string;
5+
////}
6+
////class C implements I {
7+
//// public pr/**/: string | number;
8+
////}
9+
10+
verify.completions({
11+
marker: "",
12+
includes: [
13+
{ name: "prop", isSnippet: undefined, insertText: undefined }
14+
],
15+
isNewIdentifierLocation: true,
16+
preferences: {
17+
includeCompletionsWithInsertText: true,
18+
includeCompletionsWithSnippetText: true,
19+
includeCompletionsWithClassMemberSnippets: true,
20+
}
21+
});

0 commit comments

Comments
 (0)