@@ -65,7 +65,6 @@ import {
65
65
find ,
66
66
findAncestor ,
67
67
findChildOfKind ,
68
- findNextToken ,
69
68
findPrecedingToken ,
70
69
first ,
71
70
firstDefined ,
@@ -1683,14 +1682,15 @@ function createCompletionEntry(
1683
1682
}
1684
1683
}
1685
1684
1686
- if ( ( origin ?. kind === SymbolOriginInfoKind . TypeOnlyAlias ) ) {
1685
+ if ( origin ?. kind === SymbolOriginInfoKind . TypeOnlyAlias ) {
1687
1686
hasAction = true ;
1688
1687
}
1689
1688
1690
1689
if ( completionKind === CompletionKind . ObjectPropertyDeclaration && contextToken &&
1691
1690
findPrecedingToken ( contextToken . pos , sourceFile , contextToken ) ?. kind !== SyntaxKind . CommaToken &&
1692
- findNextToken ( contextToken , contextToken . parent , sourceFile ) ?. kind !== SyntaxKind . CommaToken &&
1693
- ( findAncestor ( contextToken . parent , ( node : Node ) => isPropertyAssignment ( node ) ) ?. getLastToken ( ) === contextToken || isMethodDeclaration ( contextToken . parent . parent ) ) ) {
1691
+ ( isMethodDeclaration ( contextToken . parent . parent ) || isSpreadAssignment ( contextToken . parent ) || findAncestor ( contextToken . parent , ( node : Node ) => isPropertyAssignment ( node ) ) ?. getLastToken ( ) === contextToken ||
1692
+ isShorthandPropertyAssignment ( contextToken . parent ) && getLineAndCharacterOfPosition ( contextToken . getSourceFile ( ) , contextToken . getEnd ( ) ) . line !== getLineAndCharacterOfPosition ( contextToken . getSourceFile ( ) , position ) . line ) ) {
1693
+
1694
1694
source = CompletionSource . ObjectLiteralMemberWithComma ;
1695
1695
hasAction = true ;
1696
1696
}
@@ -2882,7 +2882,7 @@ function getCompletionEntryCodeActionsAndSourceDisplay(
2882
2882
sourceDisplay : undefined ,
2883
2883
codeActions : [ {
2884
2884
changes,
2885
- description : diagnosticToString ( [ Diagnostics . Add_missing_comma_for_an_object_member_completion_0 , name ] ) ,
2885
+ description : diagnosticToString ( [ Diagnostics . Add_missing_comma_for_object_member_completion_0 , name ] ) ,
2886
2886
} ] ,
2887
2887
} ;
2888
2888
}
@@ -4184,7 +4184,7 @@ function getCompletionData(
4184
4184
*/
4185
4185
function tryGetObjectLikeCompletionSymbols ( ) : GlobalsSearch | undefined {
4186
4186
const symbolsStartIndex = symbols . length ;
4187
- const objectLikeContainer = tryGetObjectLikeCompletionContainer ( contextToken ) ;
4187
+ const objectLikeContainer = tryGetObjectLikeCompletionContainer ( contextToken , position ) ;
4188
4188
if ( ! objectLikeContainer ) return GlobalsSearch . Continue ;
4189
4189
4190
4190
// We're looking up possible property names from contextual/inferred/declared type.
@@ -4912,7 +4912,7 @@ function getCompletionData(
4912
4912
* Returns the immediate owning object literal or binding pattern of a context token,
4913
4913
* on the condition that one exists and that the context implies completion should be given.
4914
4914
*/
4915
- function tryGetObjectLikeCompletionContainer ( contextToken : Node | undefined ) : ObjectLiteralExpression | ObjectBindingPattern | undefined {
4915
+ function tryGetObjectLikeCompletionContainer ( contextToken : Node | undefined , position : number ) : ObjectLiteralExpression | ObjectBindingPattern | undefined {
4916
4916
if ( contextToken ) {
4917
4917
const { parent } = contextToken ;
4918
4918
switch ( contextToken . kind ) {
@@ -4922,19 +4922,30 @@ function tryGetObjectLikeCompletionContainer(contextToken: Node | undefined): Ob
4922
4922
return parent ;
4923
4923
}
4924
4924
break ;
4925
- case SyntaxKind . CloseBraceToken : // const x = { } |
4926
- if ( parent . parent && parent . parent . parent && isMethodDeclaration ( parent . parent ) && isObjectLiteralExpression ( parent . parent . parent ) ) {
4927
- return parent . parent . parent ;
4928
- }
4929
- break ;
4930
4925
case SyntaxKind . AsteriskToken :
4931
4926
return isMethodDeclaration ( parent ) ? tryCast ( parent . parent , isObjectLiteralExpression ) : undefined ;
4932
4927
case SyntaxKind . AsyncKeyword :
4933
4928
return tryCast ( parent . parent , isObjectLiteralExpression ) ;
4934
4929
case SyntaxKind . Identifier :
4935
- return ( contextToken as Identifier ) . text === "async" && isShorthandPropertyAssignment ( contextToken . parent )
4936
- ? contextToken . parent . parent : undefined ;
4930
+ if ( ( contextToken as Identifier ) . text === "async" && isShorthandPropertyAssignment ( contextToken . parent ) ) {
4931
+ return contextToken . parent . parent ;
4932
+ }
4933
+ else {
4934
+ if ( isObjectLiteralExpression ( contextToken . parent . parent ) &&
4935
+ ( isSpreadAssignment ( contextToken . parent ) || isShorthandPropertyAssignment ( contextToken . parent ) &&
4936
+ ( getLineAndCharacterOfPosition ( contextToken . getSourceFile ( ) , contextToken . getEnd ( ) ) . line !== getLineAndCharacterOfPosition ( contextToken . getSourceFile ( ) , position ) . line ) ) ) {
4937
+ return contextToken . parent . parent ;
4938
+ }
4939
+ const ancestorNode = findAncestor ( parent , ( node : Node ) => isPropertyAssignment ( node ) ) ;
4940
+ if ( ancestorNode && ancestorNode . getLastToken ( ) === contextToken && isObjectLiteralExpression ( ancestorNode . parent ) ) {
4941
+ return ancestorNode . parent ;
4942
+ }
4943
+ }
4944
+ break ;
4937
4945
default :
4946
+ if ( parent . parent && parent . parent . parent && isMethodDeclaration ( parent . parent ) && isObjectLiteralExpression ( parent . parent . parent ) ) {
4947
+ return parent . parent . parent ;
4948
+ }
4938
4949
const ancestorNode = findAncestor ( parent , ( node : Node ) => isPropertyAssignment ( node ) ) ;
4939
4950
if ( contextToken . kind !== SyntaxKind . ColonToken && ancestorNode && ancestorNode . getLastToken ( ) === contextToken &&
4940
4951
isObjectLiteralExpression ( ancestorNode . parent ) ) {
0 commit comments