@@ -1538,7 +1538,7 @@ namespace ts.Completions {
15381538 * Relevant symbols are stored in the captured 'symbols' variable.
15391539 */
15401540 function tryGetClassLikeCompletionSymbols ( ) : GlobalsSearch {
1541- const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location ) ;
1541+ const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location , position ) ;
15421542 if ( ! decl ) return GlobalsSearch . Continue ;
15431543
15441544 // We're looking up possible property names from parent type.
@@ -2155,7 +2155,7 @@ namespace ts.Completions {
21552155 * Returns the immediate owning class declaration of a context token,
21562156 * on the condition that one exists and that the context implies completion should be given.
21572157 */
2158- function tryGetObjectTypeDeclarationCompletionContainer ( sourceFile : SourceFile , contextToken : Node | undefined , location : Node ) : ObjectTypeDeclaration | undefined {
2158+ function tryGetObjectTypeDeclarationCompletionContainer ( sourceFile : SourceFile , contextToken : Node | undefined , location : Node , position : number ) : ObjectTypeDeclaration | undefined {
21592159 // class c { method() { } | method2() { } }
21602160 switch ( location . kind ) {
21612161 case SyntaxKind . SyntaxList :
@@ -2165,9 +2165,15 @@ namespace ts.Completions {
21652165 if ( cls && ! findChildOfKind ( cls , SyntaxKind . CloseBraceToken , sourceFile ) ) {
21662166 return cls ;
21672167 }
2168+ break ;
2169+ case SyntaxKind . Identifier : // class c extends React.Component { a: () => 1\n compon| }
2170+ if ( isFromObjectTypeDeclaration ( location ) ) {
2171+ return findAncestor ( location , isObjectTypeDeclaration ) ;
2172+ }
21682173 }
21692174
21702175 if ( ! contextToken ) return undefined ;
2176+
21712177 switch ( contextToken . kind ) {
21722178 case SyntaxKind . SemicolonToken : // class c {getValue(): number; | }
21732179 case SyntaxKind . CloseBraceToken : // class c { method() { } | }
@@ -2179,7 +2185,13 @@ namespace ts.Completions {
21792185 case SyntaxKind . CommaToken : // class c {getValue(): number, | }
21802186 return tryCast ( contextToken . parent , isObjectTypeDeclaration ) ;
21812187 default :
2182- if ( ! isFromObjectTypeDeclaration ( contextToken ) ) return undefined ;
2188+ if ( ! isFromObjectTypeDeclaration ( contextToken ) ) {
2189+ // class c extends React.Component { a: () => 1\n| }
2190+ if ( getLineAndCharacterOfPosition ( sourceFile , contextToken . getEnd ( ) ) . line !== getLineAndCharacterOfPosition ( sourceFile , position ) . line && isObjectTypeDeclaration ( location ) ) {
2191+ return location ;
2192+ }
2193+ return undefined ;
2194+ }
21832195 const isValidKeyword = isClassLike ( contextToken . parent . parent ) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword ;
21842196 return ( isValidKeyword ( contextToken . kind ) || contextToken . kind === SyntaxKind . AsteriskToken || isIdentifier ( contextToken ) && isValidKeyword ( stringToToken ( contextToken . text ) ! ) ) // TODO: GH#18217
21852197 ? contextToken . parent . parent as ObjectTypeDeclaration : undefined ;
0 commit comments