Skip to content
Permalink
Browse files
fix(51170): Completing an unimplemented property overwrites rest of l…
…ine (#51175)

* fix(51170): skip insertText for class members with existing initializer

* skip insertText for class members with existing tokens
  • Loading branch information
a-tarasyuk committed Oct 17, 2022
1 parent a1d82fc commit 7406ee9c145cd7d6117391818d5a1eca2d66ca8f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
@@ -764,7 +764,7 @@ namespace ts.Completions {
if (preferences.includeCompletionsWithClassMemberSnippets &&
preferences.includeCompletionsWithInsertText &&
completionKind === CompletionKind.MemberLike &&
isClassLikeMemberCompletion(symbol, location)) {
isClassLikeMemberCompletion(symbol, location, sourceFile)) {
let importAdder;
({ insertText, isSnippet, importAdder, replacementSpan } = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext));
sortText = SortText.ClassMemberSnippets; // sortText has to be lower priority than the sortText for keywords. See #47852.
@@ -846,7 +846,7 @@ namespace ts.Completions {
};
}

function isClassLikeMemberCompletion(symbol: Symbol, location: Node): boolean {
function isClassLikeMemberCompletion(symbol: Symbol, location: Node, sourceFile: SourceFile): boolean {
// TODO: support JS files.
if (isInJSFile(location)) {
return false;
@@ -884,6 +884,7 @@ namespace ts.Completions {
location.parent.parent &&
isClassElement(location.parent) &&
location === location.parent.name &&
location.parent.getLastToken(sourceFile) === location.parent.name &&
isClassLike(location.parent.parent)
) ||
(
@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />

////interface I {
//// prop: string;
////}
////class C implements I {
//// public pr/**/: string = 'foo';
////}

verify.completions({
marker: "",
includes: [
{ name: "prop", isSnippet: undefined, insertText: undefined }
],
isNewIdentifierLocation: true,
preferences: {
includeCompletionsWithInsertText: true,
includeCompletionsWithSnippetText: true,
includeCompletionsWithClassMemberSnippets: true,
}
});
@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />

////interface I {
//// prop: string;
////}
////class C implements I {
//// public pr/**/: string | number;
////}

verify.completions({
marker: "",
includes: [
{ name: "prop", isSnippet: undefined, insertText: undefined }
],
isNewIdentifierLocation: true,
preferences: {
includeCompletionsWithInsertText: true,
includeCompletionsWithSnippetText: true,
includeCompletionsWithClassMemberSnippets: true,
}
});

0 comments on commit 7406ee9

Please sign in to comment.