1- /// <reference path='../compiler/utilities.ts' />
2-
31/* @internal */
42namespace ts . Completions {
5- export function getCompletionsAtPosition ( host : LanguageServiceHost , typeChecker : TypeChecker , log : ( message : string ) => void , compilerOptions : CompilerOptions , sourceFile : SourceFile , position : number ) : CompletionInfo {
3+ export function getCompletionsAtPosition ( host : LanguageServiceHost , typeChecker : TypeChecker , log : ( message : string ) => void , compilerOptions : CompilerOptions , sourceFile : SourceFile , position : number ) : CompletionInfo | undefined {
64 if ( isInReferenceComment ( sourceFile , position ) ) {
75 return getTripleSlashReferenceCompletion ( sourceFile , position ) ;
86 }
@@ -134,7 +132,7 @@ namespace ts.Completions {
134132 return uniqueNames ;
135133 }
136134
137- function getStringLiteralCompletionEntries ( sourceFile : SourceFile , position : number ) {
135+ function getStringLiteralCompletionEntries ( sourceFile : SourceFile , position : number ) : CompletionInfo | undefined {
138136 const node = findPrecedingToken ( position , sourceFile ) ;
139137 if ( ! node || node . kind !== SyntaxKind . StringLiteral ) {
140138 return undefined ;
@@ -174,7 +172,7 @@ namespace ts.Completions {
174172 return getStringLiteralCompletionEntriesFromModuleNames ( < StringLiteral > node ) ;
175173 }
176174 else {
177- const argumentInfo = SignatureHelp . getContainingArgumentInfo ( node , position , sourceFile ) ;
175+ const argumentInfo = SignatureHelp . getImmediatelyContainingArgumentInfo ( node , position , sourceFile ) ;
178176 if ( argumentInfo ) {
179177 // Get string literal completions from specialized signatures of the target
180178 // i.e. declare function f(a: 'A');
@@ -188,7 +186,7 @@ namespace ts.Completions {
188186 }
189187 }
190188
191- function getStringLiteralCompletionEntriesFromPropertyAssignment ( element : ObjectLiteralElement ) {
189+ function getStringLiteralCompletionEntriesFromPropertyAssignment ( element : ObjectLiteralElement ) : CompletionInfo | undefined {
192190 const type = typeChecker . getContextualType ( ( < ObjectLiteralExpression > element . parent ) ) ;
193191 const entries : CompletionEntry [ ] = [ ] ;
194192 if ( type ) {
@@ -199,7 +197,7 @@ namespace ts.Completions {
199197 }
200198 }
201199
202- function getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo : SignatureHelp . ArgumentListInfo ) {
200+ function getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo : SignatureHelp . ArgumentListInfo ) : CompletionInfo | undefined {
203201 const candidates : Signature [ ] = [ ] ;
204202 const entries : CompletionEntry [ ] = [ ] ;
205203
@@ -219,7 +217,7 @@ namespace ts.Completions {
219217 return undefined ;
220218 }
221219
222- function getStringLiteralCompletionEntriesFromElementAccess ( node : ElementAccessExpression ) {
220+ function getStringLiteralCompletionEntriesFromElementAccess ( node : ElementAccessExpression ) : CompletionInfo | undefined {
223221 const type = typeChecker . getTypeAtLocation ( node . expression ) ;
224222 const entries : CompletionEntry [ ] = [ ] ;
225223 if ( type ) {
@@ -231,7 +229,7 @@ namespace ts.Completions {
231229 return undefined ;
232230 }
233231
234- function getStringLiteralCompletionEntriesFromContextualType ( node : StringLiteral ) {
232+ function getStringLiteralCompletionEntriesFromContextualType ( node : StringLiteral ) : CompletionInfo | undefined {
235233 const type = typeChecker . getContextualType ( node ) ;
236234 if ( type ) {
237235 const entries : CompletionEntry [ ] = [ ] ;
@@ -243,26 +241,26 @@ namespace ts.Completions {
243241 return undefined ;
244242 }
245243
246- function addStringLiteralCompletionsFromType ( type : Type , result : CompletionEntry [ ] ) : void {
244+ function addStringLiteralCompletionsFromType ( type : Type , result : Push < CompletionEntry > ) : void {
247245 if ( type && type . flags & TypeFlags . TypeParameter ) {
248246 type = typeChecker . getApparentType ( type ) ;
249247 }
250248 if ( ! type ) {
251249 return ;
252250 }
253251 if ( type . flags & TypeFlags . Union ) {
254- forEach ( ( < UnionType > type ) . types , t => addStringLiteralCompletionsFromType ( t , result ) ) ;
255- }
256- else {
257- if ( type . flags & TypeFlags . StringLiteral ) {
258- result . push ( {
259- name : ( < LiteralType > type ) . text ,
260- kindModifiers : ScriptElementKindModifier . none ,
261- kind : ScriptElementKind . variableElement ,
262- sortText : "0"
263- } ) ;
252+ for ( const t of ( < UnionType > type ) . types ) {
253+ addStringLiteralCompletionsFromType ( t , result ) ;
264254 }
265255 }
256+ else if ( type . flags & TypeFlags . StringLiteral ) {
257+ result . push ( {
258+ name : ( < LiteralType > type ) . text ,
259+ kindModifiers : ScriptElementKindModifier . none ,
260+ kind : ScriptElementKind . variableElement ,
261+ sortText : "0"
262+ } ) ;
263+ }
266264 }
267265
268266 function getStringLiteralCompletionEntriesFromModuleNames ( node : StringLiteral ) : CompletionInfo {
0 commit comments