@@ -1617,7 +1617,7 @@ namespace ts.Completions {
1617
1617
* Relevant symbols are stored in the captured 'symbols' variable.
1618
1618
*/
1619
1619
function tryGetClassLikeCompletionSymbols ( ) : GlobalsSearch {
1620
- const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location ) ;
1620
+ const decl = tryGetObjectTypeDeclarationCompletionContainer ( sourceFile , contextToken , location , position ) ;
1621
1621
if ( ! decl ) return GlobalsSearch . Continue ;
1622
1622
1623
1623
// We're looking up possible property names from parent type.
@@ -2234,7 +2234,7 @@ namespace ts.Completions {
2234
2234
* Returns the immediate owning class declaration of a context token,
2235
2235
* on the condition that one exists and that the context implies completion should be given.
2236
2236
*/
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 {
2238
2238
// class c { method() { } | method2() { } }
2239
2239
switch ( location . kind ) {
2240
2240
case SyntaxKind . SyntaxList :
@@ -2244,9 +2244,15 @@ namespace ts.Completions {
2244
2244
if ( cls && ! findChildOfKind ( cls , SyntaxKind . CloseBraceToken , sourceFile ) ) {
2245
2245
return cls ;
2246
2246
}
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
+ }
2247
2252
}
2248
2253
2249
2254
if ( ! contextToken ) return undefined ;
2255
+
2250
2256
switch ( contextToken . kind ) {
2251
2257
case SyntaxKind . SemicolonToken : // class c {getValue(): number; | }
2252
2258
case SyntaxKind . CloseBraceToken : // class c { method() { } | }
@@ -2258,7 +2264,13 @@ namespace ts.Completions {
2258
2264
case SyntaxKind . CommaToken : // class c {getValue(): number, | }
2259
2265
return tryCast ( contextToken . parent , isObjectTypeDeclaration ) ;
2260
2266
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
+ }
2262
2274
const isValidKeyword = isClassLike ( contextToken . parent . parent ) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword ;
2263
2275
return ( isValidKeyword ( contextToken . kind ) || contextToken . kind === SyntaxKind . AsteriskToken || isIdentifier ( contextToken ) && isValidKeyword ( stringToToken ( contextToken . text ) ! ) ) // TODO: GH#18217
2264
2276
? contextToken . parent . parent as ObjectTypeDeclaration : undefined ;
0 commit comments