@@ -39,6 +39,11 @@ namespace ts.Completions {
39
39
return getStringLiteralCompletionEntries ( sourceFile , position , typeChecker , compilerOptions , host , log ) ;
40
40
}
41
41
42
+ const contextToken = findPrecedingToken ( position , sourceFile ) ;
43
+ if ( isInBreakOrContinue ( contextToken ) ) {
44
+ return getLabelCompletionAtPosition ( contextToken ) ;
45
+ }
46
+
42
47
const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options , compilerOptions . target ) ;
43
48
if ( ! completionData ) {
44
49
return undefined ;
@@ -223,6 +228,18 @@ namespace ts.Completions {
223
228
return uniques ;
224
229
}
225
230
231
+ function isInBreakOrContinue ( contextToken : Node ) : boolean {
232
+ return contextToken && isBreakOrContinueStatement ( contextToken . parent ) &&
233
+ ( contextToken . kind === SyntaxKind . BreakKeyword || contextToken . kind === SyntaxKind . ContinueKeyword || contextToken . kind === SyntaxKind . Identifier ) ;
234
+ }
235
+
236
+ function getLabelCompletionAtPosition ( contextToken : Node ) : CompletionInfo | undefined {
237
+ const entries = getLabelStatementCompletions ( contextToken . parent ) ;
238
+ if ( entries . length ) {
239
+ return { isGlobalCompletion : false , isMemberCompletion : false , isNewIdentifierLocation : false , entries } ;
240
+ }
241
+ }
242
+
226
243
function getStringLiteralCompletionEntries ( sourceFile : SourceFile , position : number , typeChecker : TypeChecker , compilerOptions : CompilerOptions , host : LanguageServiceHost , log : Log ) : CompletionInfo | undefined {
227
244
const node = findPrecedingToken ( position , sourceFile ) ;
228
245
if ( ! node || node . kind !== SyntaxKind . StringLiteral ) {
@@ -358,6 +375,32 @@ namespace ts.Completions {
358
375
return undefined ;
359
376
}
360
377
378
+ function getLabelStatementCompletions ( node : Node ) : CompletionEntry [ ] {
379
+ const entries : CompletionEntry [ ] = [ ] ;
380
+ const uniques = createMap < true > ( ) ;
381
+ let current = node ;
382
+
383
+ while ( current ) {
384
+ if ( isFunctionLike ( current ) ) {
385
+ break ;
386
+ }
387
+ if ( isLabeledStatement ( current ) ) {
388
+ const name = current . label . text ;
389
+ if ( ! uniques . has ( name ) ) {
390
+ uniques . set ( name , true ) ;
391
+ entries . push ( {
392
+ name,
393
+ kindModifiers : ScriptElementKindModifier . none ,
394
+ kind : ScriptElementKind . label ,
395
+ sortText : "0"
396
+ } ) ;
397
+ }
398
+ }
399
+ current = current . parent ;
400
+ }
401
+ return entries ;
402
+ }
403
+
361
404
function addStringLiteralCompletionsFromType ( type : Type , result : Push < CompletionEntry > , typeChecker : TypeChecker , uniques = createMap < true > ( ) ) : void {
362
405
if ( type && type . flags & TypeFlags . TypeParameter ) {
363
406
type = typeChecker . getBaseConstraintOfType ( type ) ;
0 commit comments