@@ -40,7 +40,7 @@ namespace ts.refactor.extractMethod {
4040 // Don't issue refactorings with duplicated names.
4141 // Scopes come back in "innermost first" order, so extractions will
4242 // preferentially go into nearer scopes
43- const description = formatStringFromArgs ( Diagnostics . Extract_function_into_0 . message , [ extr . scopeDescription ] ) ;
43+ const description = formatStringFromArgs ( Diagnostics . Extract_to_0 . message , [ extr . scopeDescription ] ) ;
4444 if ( ! usedNames . has ( description ) ) {
4545 usedNames . set ( description , true ) ;
4646 actions . push ( {
@@ -543,44 +543,45 @@ namespace ts.refactor.extractMethod {
543543 }
544544 }
545545
546- function getDescriptionForScope ( scope : Scope ) {
547- if ( isFunctionLike ( scope ) ) {
548- switch ( scope . kind ) {
549- case SyntaxKind . Constructor :
550- return "constructor" ;
551- case SyntaxKind . FunctionExpression :
552- return scope . name
553- ? `function expression ${ scope . name . text } `
554- : "anonymous function expression" ;
555- case SyntaxKind . FunctionDeclaration :
556- return `function '${ scope . name . text } '` ;
557- case SyntaxKind . ArrowFunction :
558- return "arrow function" ;
559- case SyntaxKind . MethodDeclaration :
560- return `method '${ scope . name . getText ( ) } ` ;
561- case SyntaxKind . GetAccessor :
562- return `'get ${ scope . name . getText ( ) } '` ;
563- case SyntaxKind . SetAccessor :
564- return `'set ${ scope . name . getText ( ) } '` ;
565- }
566- }
567- else if ( isModuleBlock ( scope ) ) {
568- return `namespace '${ scope . parent . name . getText ( ) } '` ;
569- }
570- else if ( isClassLike ( scope ) ) {
571- return scope . kind === SyntaxKind . ClassDeclaration
572- ? `class '${ scope . name . text } '`
573- : scope . name && scope . name . text
574- ? `class expression '${ scope . name . text } '`
575- : "anonymous class expression" ;
576- }
577- else if ( isSourceFile ( scope ) ) {
578- return scope . externalModuleIndicator ? "module scope" : "global scope" ;
579- }
580- else {
581- return "unknown" ;
546+ function getDescriptionForScope ( scope : Scope ) : string {
547+ return isFunctionLikeDeclaration ( scope )
548+ ? `inner function in ${ getDescriptionForFunctionLikeDeclaration ( scope ) } `
549+ : isClassLike ( scope )
550+ ? `method in ${ getDescriptionForClassLikeDeclaration ( scope ) } `
551+ : `function in ${ getDescriptionForModuleLikeDeclaration ( scope ) } ` ;
552+ }
553+ function getDescriptionForFunctionLikeDeclaration ( scope : FunctionLikeDeclaration ) : string {
554+ switch ( scope . kind ) {
555+ case SyntaxKind . Constructor :
556+ return "constructor" ;
557+ case SyntaxKind . FunctionExpression :
558+ return scope . name
559+ ? `function expression '${ scope . name . text } '`
560+ : "anonymous function expression" ;
561+ case SyntaxKind . FunctionDeclaration :
562+ return `function '${ scope . name . text } '` ;
563+ case SyntaxKind . ArrowFunction :
564+ return "arrow function" ;
565+ case SyntaxKind . MethodDeclaration :
566+ return `method '${ scope . name . getText ( ) } ` ;
567+ case SyntaxKind . GetAccessor :
568+ return `'get ${ scope . name . getText ( ) } '` ;
569+ case SyntaxKind . SetAccessor :
570+ return `'set ${ scope . name . getText ( ) } '` ;
571+ default :
572+ Debug . assertNever ( scope ) ;
582573 }
583574 }
575+ function getDescriptionForClassLikeDeclaration ( scope : ClassLikeDeclaration ) : string {
576+ return scope . kind === SyntaxKind . ClassDeclaration
577+ ? `class '${ scope . name . text } '`
578+ : scope . name ? `class expression '${ scope . name . text } '` : "anonymous class expression" ;
579+ }
580+ function getDescriptionForModuleLikeDeclaration ( scope : SourceFile | ModuleBlock ) : string {
581+ return scope . kind === SyntaxKind . ModuleBlock
582+ ? `namespace '${ scope . parent . name . getText ( ) } '`
583+ : scope . externalModuleIndicator ? "module scope" : "global scope" ;
584+ }
584585
585586 function getUniqueName ( isNameOkay : ( name : string ) => boolean ) {
586587 let functionNameText = "newFunction" ;
0 commit comments