@@ -1617,7 +1617,7 @@ namespace ts.Completions {
16171617 * Relevant symbols are stored in the captured 'symbols' variable.
16181618 */
16191619 function tryGetClassLikeCompletionSymbols ( ) : GlobalsSearch {
1620- const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location ) ;
1620+ const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location , position ) ;
16211621 if ( ! decl ) return GlobalsSearch . Continue ;
16221622
16231623 // We're looking up possible property names from parent type.
@@ -2234,7 +2234,7 @@ namespace ts.Completions {
22342234 * Returns the immediate owning class declaration of a context token,
22352235 * on the condition that one exists and that the context implies completion should be given.
22362236 */
2237- function tryGetObjectTypeDeclarationCompletionContainer ( sourceFile : SourceFile , contextToken : Node | undefined , location : Node ) : ObjectTypeDeclaration | undefined {
2237+ function tryGetObjectTypeDeclarationCompletionContainer ( sourceFile : SourceFile , contextToken : Node | undefined , location : Node , position : number ) : ObjectTypeDeclaration | undefined {
22382238 // class c { method() { } | method2() { } }
22392239 switch ( location . kind ) {
22402240 case SyntaxKind . SyntaxList :
@@ -2244,9 +2244,15 @@ namespace ts.Completions {
22442244 if ( cls && ! findChildOfKind ( cls , SyntaxKind . CloseBraceToken , sourceFile ) ) {
22452245 return cls ;
22462246 }
2247+ break ;
2248+ case SyntaxKind . Identifier : // class c extends React.Component { a: () => 1\n compon| }
2249+ if ( isFromObjectTypeDeclaration ( location ) ) {
2250+ return findAncestor ( location , isObjectTypeDeclaration ) ;
2251+ }
22472252 }
22482253
22492254 if ( ! contextToken ) return undefined ;
2255+
22502256 switch ( contextToken . kind ) {
22512257 case SyntaxKind . SemicolonToken : // class c {getValue(): number; | }
22522258 case SyntaxKind . CloseBraceToken : // class c { method() { } | }
@@ -2258,7 +2264,13 @@ namespace ts.Completions {
22582264 case SyntaxKind . CommaToken : // class c {getValue(): number, | }
22592265 return tryCast ( contextToken . parent , isObjectTypeDeclaration ) ;
22602266 default :
2261- if ( ! isFromObjectTypeDeclaration ( contextToken ) ) return undefined ;
2267+ if ( ! isFromObjectTypeDeclaration ( contextToken ) ) {
2268+ // class c extends React.Component { a: () => 1\n| }
2269+ if ( getLineAndCharacterOfPosition ( sourceFile , contextToken . getEnd ( ) ) . line !== getLineAndCharacterOfPosition ( sourceFile , position ) . line && isObjectTypeDeclaration ( location ) ) {
2270+ return location ;
2271+ }
2272+ return undefined ;
2273+ }
22622274 const isValidKeyword = isClassLike ( contextToken . parent . parent ) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword ;
22632275 return ( isValidKeyword ( contextToken . kind ) || contextToken . kind === SyntaxKind . AsteriskToken || isIdentifier ( contextToken ) && isValidKeyword ( stringToToken ( contextToken . text ) ! ) ) // TODO: GH#18217
22642276 ? contextToken . parent . parent as ObjectTypeDeclaration : undefined ;
0 commit comments