@@ -1538,7 +1538,7 @@ namespace ts.Completions {
1538
1538
* Relevant symbols are stored in the captured 'symbols' variable.
1539
1539
*/
1540
1540
function tryGetClassLikeCompletionSymbols ( ) : GlobalsSearch {
1541
- const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location ) ;
1541
+ const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location , position ) ;
1542
1542
if ( ! decl ) return GlobalsSearch . Continue ;
1543
1543
1544
1544
// We're looking up possible property names from parent type.
@@ -2155,7 +2155,7 @@ namespace ts.Completions {
2155
2155
* Returns the immediate owning class declaration of a context token,
2156
2156
* on the condition that one exists and that the context implies completion should be given.
2157
2157
*/
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 {
2159
2159
// class c { method() { } | method2() { } }
2160
2160
switch ( location . kind ) {
2161
2161
case SyntaxKind . SyntaxList :
@@ -2165,9 +2165,15 @@ namespace ts.Completions {
2165
2165
if ( cls && ! findChildOfKind ( cls , SyntaxKind . CloseBraceToken , sourceFile ) ) {
2166
2166
return cls ;
2167
2167
}
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
+ }
2168
2173
}
2169
2174
2170
2175
if ( ! contextToken ) return undefined ;
2176
+
2171
2177
switch ( contextToken . kind ) {
2172
2178
case SyntaxKind . SemicolonToken : // class c {getValue(): number; | }
2173
2179
case SyntaxKind . CloseBraceToken : // class c { method() { } | }
@@ -2179,7 +2185,13 @@ namespace ts.Completions {
2179
2185
case SyntaxKind . CommaToken : // class c {getValue(): number, | }
2180
2186
return tryCast ( contextToken . parent , isObjectTypeDeclaration ) ;
2181
2187
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
+ }
2183
2195
const isValidKeyword = isClassLike ( contextToken . parent . parent ) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword ;
2184
2196
return ( isValidKeyword ( contextToken . kind ) || contextToken . kind === SyntaxKind . AsteriskToken || isIdentifier ( contextToken ) && isValidKeyword ( stringToToken ( contextToken . text ) ! ) ) // TODO: GH#18217
2185
2197
? contextToken . parent . parent as ObjectTypeDeclaration : undefined ;
0 commit comments