@@ -54,7 +54,6 @@ import {
54
54
Expression ,
55
55
ExpressionWithTypeArguments ,
56
56
factory ,
57
- FileTextChanges ,
58
57
filter ,
59
58
find ,
60
59
findAncestor ,
@@ -294,7 +293,6 @@ import {
294
293
Program ,
295
294
programContainsModules ,
296
295
PropertyAccessExpression ,
297
- PropertyAssignment ,
298
296
PropertyDeclaration ,
299
297
PropertyName ,
300
298
PropertySignature ,
@@ -360,6 +358,8 @@ import {
360
358
UserPreferences ,
361
359
VariableDeclaration ,
362
360
walkUpParenthesizedExpressions ,
361
+ isPropertyAssignment ,
362
+ findNextToken ,
363
363
} from "./_namespaces/ts" ;
364
364
import { StringCompletions } from "./_namespaces/ts.Completions" ;
365
365
@@ -425,6 +425,8 @@ export enum CompletionSource {
425
425
ObjectLiteralMethodSnippet = "ObjectLiteralMethodSnippet/" ,
426
426
/** Case completions for switch statements */
427
427
SwitchCases = "SwitchCases/" ,
428
+ /** Completions for an Object literal expression */
429
+ ObjectLiteralExpression = "ObjectLiteralExpression/" ,
428
430
}
429
431
430
432
/** @internal */
@@ -1348,7 +1350,13 @@ function createCompletionEntry(
1348
1350
}
1349
1351
}
1350
1352
1351
- if ( ( origin ?. kind === SymbolOriginInfoKind . TypeOnlyAlias ) || ( contextToken && contextToken . kind !== SyntaxKind . OpenBraceToken && completionKind === CompletionKind . ObjectPropertyDeclaration && preferences . includeCompletionsWithInsertText ) ) {
1353
+ if ( ( origin ?. kind === SymbolOriginInfoKind . TypeOnlyAlias ) ) {
1354
+ hasAction = true ;
1355
+ }
1356
+
1357
+ if ( ( contextToken && isPropertyAssignment ( contextToken . parent ) && findNextToken ( contextToken , contextToken ?. parent , sourceFile ) ?. kind !== SyntaxKind . CommaToken &&
1358
+ completionKind === CompletionKind . ObjectPropertyDeclaration ) ) {
1359
+ source = CompletionSource . ObjectLiteralExpression ;
1352
1360
hasAction = true ;
1353
1361
}
1354
1362
@@ -2277,7 +2285,8 @@ function getSymbolCompletionFromEntryId(
2277
2285
return info && info . name === entryId . name && (
2278
2286
entryId . source === CompletionSource . ClassMemberSnippet && symbol . flags & SymbolFlags . ClassMember
2279
2287
|| entryId . source === CompletionSource . ObjectLiteralMethodSnippet && symbol . flags & ( SymbolFlags . Property | SymbolFlags . Method )
2280
- || getSourceFromOrigin ( origin ) === entryId . source )
2288
+ || getSourceFromOrigin ( origin ) === entryId . source
2289
+ || entryId . source === CompletionSource . ObjectLiteralExpression )
2281
2290
? { type : "symbol" as const , symbol, location, origin, contextToken, previousToken, isJsxInitializer, isTypeOnlyLocation }
2282
2291
: undefined ;
2283
2292
} ) || { type : "none" } ;
@@ -2466,24 +2475,16 @@ function getCompletionEntryCodeActionsAndSourceDisplay(
2466
2475
return { codeActions : [ codeAction ] , sourceDisplay : undefined } ;
2467
2476
}
2468
2477
2469
- if ( contextToken && isObjectLiteralExpression ( contextToken . parent . parent ) && previousToken ?. kind !== SyntaxKind . ColonToken ) {
2470
- let changes : FileTextChanges [ ] ;
2471
- if ( getLineAndCharacterOfPosition ( sourceFile , contextToken . getEnd ( ) ) . line !== getLineAndCharacterOfPosition ( sourceFile , position ) . line ) {
2472
- changes = textChanges . ChangeTracker . with (
2473
- { host, formatContext, preferences } ,
2474
- tracker => tracker . replacePropertyAssignment ( sourceFile , contextToken . parent as PropertyAssignment , contextToken . parent as PropertyAssignment ) ) ;
2475
- }
2476
- else {
2477
- changes = textChanges . ChangeTracker . with (
2478
- { host, formatContext, preferences } ,
2479
- tracker => tracker . replacePropertyAssignmentOnSameLine ( sourceFile , contextToken . parent as PropertyAssignment , contextToken . parent as PropertyAssignment ) ) ;
2480
- }
2478
+ if ( source === CompletionSource . ObjectLiteralExpression && contextToken ) {
2479
+ const changes = textChanges . ChangeTracker . with (
2480
+ { host, formatContext, preferences } ,
2481
+ tracker => tracker . insertText ( sourceFile , contextToken . end , "," ) ) ;
2481
2482
if ( changes ) {
2482
2483
return {
2483
2484
sourceDisplay : undefined ,
2484
2485
codeActions : [ {
2485
2486
changes,
2486
- description : diagnosticToString ( [ Diagnostics . Includes_imports_of_types_referenced_by_0 , name ] ) ,
2487
+ description : diagnosticToString ( [ Diagnostics . Add_missing_comma_for_an_object_member_completion_0 , name ] ) ,
2487
2488
} ] ,
2488
2489
} ;
2489
2490
}
0 commit comments