@@ -4296,6 +4296,7 @@ namespace ts {
4296
4296
kindModifiers : getSymbolModifiers ( symbol ) ,
4297
4297
sortText : "0" ,
4298
4298
} ;
4299
+
4299
4300
}
4300
4301
4301
4302
function getCompletionEntriesFromSymbols ( symbols : Symbol [ ] , entries : CompletionEntry [ ] , location : Node , performCharacterChecks : boolean ) : Map < string > {
@@ -4324,22 +4325,58 @@ namespace ts {
4324
4325
return undefined ;
4325
4326
}
4326
4327
4327
- const argumentInfo = SignatureHelp . getContainingArgumentInfo ( node , position , sourceFile ) ;
4328
- if ( argumentInfo ) {
4329
- // Get string literal completions from specialized signatures of the target
4330
- return getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo ) ;
4328
+ if ( node . parent . kind === SyntaxKind . PropertyAssignment && node . parent . parent . kind === SyntaxKind . ObjectLiteralExpression ) {
4329
+ // Get quoted name of properties of the object literal expression
4330
+ // i.e. interface ConfigFiles {
4331
+ // 'jspm:dev': string
4332
+ // }
4333
+ // let files: ConfigFiles = {
4334
+ // '/*completion position*/'
4335
+ // }
4336
+ //
4337
+ // function foo(c: ConfigFiles) {}
4338
+ // foo({
4339
+ // '/*completion position*/'
4340
+ // });
4341
+ return getStringLiteralCompletionEntriesFromPropertyAssignment ( < ObjectLiteralElement > node . parent ) ;
4331
4342
}
4332
4343
else if ( isElementAccessExpression ( node . parent ) && node . parent . argumentExpression === node ) {
4333
4344
// Get all names of properties on the expression
4345
+ // i.e. interface A {
4346
+ // 'prop1': string
4347
+ // }
4348
+ // let a: A;
4349
+ // a['/*completion position*/']
4334
4350
return getStringLiteralCompletionEntriesFromElementAccess ( node . parent ) ;
4335
4351
}
4336
4352
else {
4337
- // Otherwise, get the completions from the contextual type if one exists
4353
+ const argumentInfo = SignatureHelp . getContainingArgumentInfo ( node , position , sourceFile ) ;
4354
+ if ( argumentInfo ) {
4355
+ // Get string literal completions from specialized signatures of the target
4356
+ // i.e. declare function f(a: 'A');
4357
+ // f("/*completion position*/")
4358
+ return getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo , node ) ;
4359
+ }
4360
+
4361
+ // Get completion for string literal from string literal type
4362
+ // i.e. var x: "hi" | "hello" = "/*completion position*/"
4338
4363
return getStringLiteralCompletionEntriesFromContextualType ( < StringLiteral > node ) ;
4339
4364
}
4340
4365
}
4341
4366
4342
- function getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo : SignatureHelp . ArgumentListInfo ) {
4367
+ function getStringLiteralCompletionEntriesFromPropertyAssignment ( element : ObjectLiteralElement ) {
4368
+ const typeChecker = program . getTypeChecker ( ) ;
4369
+ const type = typeChecker . getContextualType ( ( < ObjectLiteralExpression > element . parent ) ) ;
4370
+ const entries : CompletionEntry [ ] = [ ] ;
4371
+ if ( type ) {
4372
+ getCompletionEntriesFromSymbols ( type . getApparentProperties ( ) , entries , element , /*performCharacterChecks*/ false ) ;
4373
+ if ( entries . length ) {
4374
+ return { isMemberCompletion : true , isNewIdentifierLocation : true , entries } ;
4375
+ }
4376
+ }
4377
+ }
4378
+
4379
+ function getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo : SignatureHelp . ArgumentListInfo , location : Node ) {
4343
4380
const typeChecker = program . getTypeChecker ( ) ;
4344
4381
const candidates : Signature [ ] = [ ] ;
4345
4382
const entries : CompletionEntry [ ] = [ ] ;
0 commit comments