1
- /// <reference path='../compiler/utilities.ts' />
2
-
3
1
/* @internal */
4
2
namespace 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 {
6
4
if ( isInReferenceComment ( sourceFile , position ) ) {
7
5
return getTripleSlashReferenceCompletion ( sourceFile , position ) ;
8
6
}
@@ -134,7 +132,7 @@ namespace ts.Completions {
134
132
return uniqueNames ;
135
133
}
136
134
137
- function getStringLiteralCompletionEntries ( sourceFile : SourceFile , position : number ) {
135
+ function getStringLiteralCompletionEntries ( sourceFile : SourceFile , position : number ) : CompletionInfo | undefined {
138
136
const node = findPrecedingToken ( position , sourceFile ) ;
139
137
if ( ! node || node . kind !== SyntaxKind . StringLiteral ) {
140
138
return undefined ;
@@ -174,7 +172,7 @@ namespace ts.Completions {
174
172
return getStringLiteralCompletionEntriesFromModuleNames ( < StringLiteral > node ) ;
175
173
}
176
174
else {
177
- const argumentInfo = SignatureHelp . getContainingArgumentInfo ( node , position , sourceFile ) ;
175
+ const argumentInfo = SignatureHelp . getImmediatelyContainingArgumentInfo ( node , position , sourceFile ) ;
178
176
if ( argumentInfo ) {
179
177
// Get string literal completions from specialized signatures of the target
180
178
// i.e. declare function f(a: 'A');
@@ -188,7 +186,7 @@ namespace ts.Completions {
188
186
}
189
187
}
190
188
191
- function getStringLiteralCompletionEntriesFromPropertyAssignment ( element : ObjectLiteralElement ) {
189
+ function getStringLiteralCompletionEntriesFromPropertyAssignment ( element : ObjectLiteralElement ) : CompletionInfo | undefined {
192
190
const type = typeChecker . getContextualType ( ( < ObjectLiteralExpression > element . parent ) ) ;
193
191
const entries : CompletionEntry [ ] = [ ] ;
194
192
if ( type ) {
@@ -199,7 +197,7 @@ namespace ts.Completions {
199
197
}
200
198
}
201
199
202
- function getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo : SignatureHelp . ArgumentListInfo ) {
200
+ function getStringLiteralCompletionEntriesFromCallExpression ( argumentInfo : SignatureHelp . ArgumentListInfo ) : CompletionInfo | undefined {
203
201
const candidates : Signature [ ] = [ ] ;
204
202
const entries : CompletionEntry [ ] = [ ] ;
205
203
@@ -219,7 +217,7 @@ namespace ts.Completions {
219
217
return undefined ;
220
218
}
221
219
222
- function getStringLiteralCompletionEntriesFromElementAccess ( node : ElementAccessExpression ) {
220
+ function getStringLiteralCompletionEntriesFromElementAccess ( node : ElementAccessExpression ) : CompletionInfo | undefined {
223
221
const type = typeChecker . getTypeAtLocation ( node . expression ) ;
224
222
const entries : CompletionEntry [ ] = [ ] ;
225
223
if ( type ) {
@@ -231,7 +229,7 @@ namespace ts.Completions {
231
229
return undefined ;
232
230
}
233
231
234
- function getStringLiteralCompletionEntriesFromContextualType ( node : StringLiteral ) {
232
+ function getStringLiteralCompletionEntriesFromContextualType ( node : StringLiteral ) : CompletionInfo | undefined {
235
233
const type = typeChecker . getContextualType ( node ) ;
236
234
if ( type ) {
237
235
const entries : CompletionEntry [ ] = [ ] ;
@@ -243,26 +241,26 @@ namespace ts.Completions {
243
241
return undefined ;
244
242
}
245
243
246
- function addStringLiteralCompletionsFromType ( type : Type , result : CompletionEntry [ ] ) : void {
244
+ function addStringLiteralCompletionsFromType ( type : Type , result : Push < CompletionEntry > ) : void {
247
245
if ( type && type . flags & TypeFlags . TypeParameter ) {
248
246
type = typeChecker . getApparentType ( type ) ;
249
247
}
250
248
if ( ! type ) {
251
249
return ;
252
250
}
253
251
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 ) ;
264
254
}
265
255
}
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
+ }
266
264
}
267
265
268
266
function getStringLiteralCompletionEntriesFromModuleNames ( node : StringLiteral ) : CompletionInfo {
0 commit comments