@@ -39,6 +39,10 @@ namespace ts.Completions {
39
39
return getStringLiteralCompletionEntries ( sourceFile , position , typeChecker , compilerOptions , host , log ) ;
40
40
}
41
41
42
+ if ( isInBreakOrContinue ( sourceFile , position ) ) {
43
+ return getLabelCompletionAtPosition ( sourceFile , position ) ;
44
+ }
45
+
42
46
const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options , compilerOptions . target ) ;
43
47
if ( ! completionData ) {
44
48
return undefined ;
@@ -211,6 +215,19 @@ namespace ts.Completions {
211
215
return uniques ;
212
216
}
213
217
218
+ function getLabelCompletionAtPosition ( sourceFile : SourceFile , position : number ) : CompletionInfo | undefined {
219
+ const contextToken : Node = findPrecedingToken ( position , sourceFile ) ;
220
+ if ( ! contextToken || ! contextToken . parent || ! isBreakOrContinueStatement ( contextToken . parent ) ) {
221
+ return undefined ;
222
+ }
223
+ const entries : CompletionEntry [ ] = [ ] ;
224
+ addLabelStatementCompletions ( contextToken . parent , entries ) ;
225
+
226
+ if ( entries . length ) {
227
+ return { isGlobalCompletion : false , isMemberCompletion : false , isNewIdentifierLocation : false , entries } ;
228
+ }
229
+ }
230
+
214
231
function getStringLiteralCompletionEntries ( sourceFile : SourceFile , position : number , typeChecker : TypeChecker , compilerOptions : CompilerOptions , host : LanguageServiceHost , log : Log ) : CompletionInfo | undefined {
215
232
const node = findPrecedingToken ( position , sourceFile ) ;
216
233
if ( ! node || node . kind !== SyntaxKind . StringLiteral ) {
@@ -346,6 +363,28 @@ namespace ts.Completions {
346
363
return undefined ;
347
364
}
348
365
366
+ function addLabelStatementCompletions ( node : Node , entries : CompletionEntry [ ] , uniques = createMap < true > ( ) ) : void {
367
+ let current : Node = node ;
368
+ while ( current ) {
369
+ if ( isFunctionLike ( current ) ) {
370
+ break ;
371
+ }
372
+ if ( isLabeledStatement ( current ) ) {
373
+ const name = current . label . escapedText as string ;
374
+ if ( ! uniques . has ( name ) ) {
375
+ uniques . set ( name , true ) ;
376
+ entries . push ( {
377
+ name,
378
+ kindModifiers : ScriptElementKindModifier . none ,
379
+ kind : ScriptElementKind . label ,
380
+ sortText : "0"
381
+ } ) ;
382
+ }
383
+ }
384
+ current = current . parent ;
385
+ }
386
+ }
387
+
349
388
function addStringLiteralCompletionsFromType ( type : Type , result : Push < CompletionEntry > , typeChecker : TypeChecker , uniques = createMap < true > ( ) ) : void {
350
389
if ( type && type . flags & TypeFlags . TypeParameter ) {
351
390
type = typeChecker . getBaseConstraintOfType ( type ) ;
0 commit comments