fix(52212): No member completions, and irrelevant value completions, when class property initializer has no semicolon (#52213)

This commit is contained in:
Oleksandr T
2023-01-13 14:23:36 -08:00
committed by GitHub
parent 41e4139357
commit 86ccd20e53
7 changed files with 746 additions and 8 deletions
+9 -8
View File
@@ -4829,7 +4829,7 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
return cls;
}
break;
case SyntaxKind.Identifier: {
case SyntaxKind.Identifier: {
const originalKeywordKind = identifierToKeywordKind(location as Identifier);
if (originalKeywordKind) {
return undefined;
@@ -4868,16 +4868,17 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
case SyntaxKind.CommaToken: // class c {getValue(): number, | }
return tryCast(contextToken.parent, isObjectTypeDeclaration);
default:
if (!isFromObjectTypeDeclaration(contextToken)) {
// class c extends React.Component { a: () => 1\n| }
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) {
if (isObjectTypeDeclaration(location)) {
// class C extends React.Component { a: () => 1\n| }
// class C { prop = ""\n | }
if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line) {
return location;
}
return undefined;
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown))
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
}
const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword;
return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown))
? contextToken.parent.parent as ObjectTypeDeclaration : undefined;
return undefined;
}
}