55namespace ts . refactor . extractSymbol {
66 const extractSymbol : Refactor = {
77 name : "Extract Symbol" ,
8- description : Diagnostics . Extract_symbol . message ,
8+ description : getLocaleSpecificMessage ( Diagnostics . Extract_symbol ) ,
99 getAvailableActions,
1010 getEditsForAction,
1111 } ;
@@ -43,7 +43,7 @@ namespace ts.refactor.extractSymbol {
4343 // Don't issue refactorings with duplicated names.
4444 // Scopes come back in "innermost first" order, so extractions will
4545 // preferentially go into nearer scopes
46- const description = formatStringFromArgs ( Diagnostics . Extract_to_0_in_1 . message , [ functionExtraction . description , functionExtraction . scopeDescription ] ) ;
46+ const description = functionExtraction . description ;
4747 if ( ! usedFunctionNames . has ( description ) ) {
4848 usedFunctionNames . set ( description , true ) ;
4949 functionActions . push ( {
@@ -58,7 +58,7 @@ namespace ts.refactor.extractSymbol {
5858 // Don't issue refactorings with duplicated names.
5959 // Scopes come back in "innermost first" order, so extractions will
6060 // preferentially go into nearer scopes
61- const description = formatStringFromArgs ( Diagnostics . Extract_to_0_in_1 . message , [ constantExtraction . description , constantExtraction . scopeDescription ] ) ;
61+ const description = constantExtraction . description ;
6262 if ( ! usedConstantNames . has ( description ) ) {
6363 usedConstantNames . set ( description , true ) ;
6464 constantActions . push ( {
@@ -78,15 +78,15 @@ namespace ts.refactor.extractSymbol {
7878 if ( functionActions . length ) {
7979 infos . push ( {
8080 name : extractSymbol . name ,
81- description : Diagnostics . Extract_function . message ,
81+ description : getLocaleSpecificMessage ( Diagnostics . Extract_function ) ,
8282 actions : functionActions
8383 } ) ;
8484 }
8585
8686 if ( constantActions . length ) {
8787 infos . push ( {
8888 name : extractSymbol . name ,
89- description : Diagnostics . Extract_constant . message ,
89+ description : getLocaleSpecificMessage ( Diagnostics . Extract_constant ) ,
9090 actions : constantActions
9191 } ) ;
9292 }
@@ -525,7 +525,6 @@ namespace ts.refactor.extractSymbol {
525525
526526 interface Extraction {
527527 readonly description : string ;
528- readonly scopeDescription : string ;
529528 readonly errors : ReadonlyArray < Diagnostic > ;
530529 }
531530
@@ -543,23 +542,43 @@ namespace ts.refactor.extractSymbol {
543542 const { scopes, readsAndWrites : { functionErrorsPerScope, constantErrorsPerScope } } = getPossibleExtractionsWorker ( targetRange , context ) ;
544543 // Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547
545544 const extractions = scopes . map ( ( scope , i ) : ScopeExtractions => {
545+ const functionDescriptionPart = getDescriptionForFunctionInScope ( scope ) ;
546+ const constantDescriptionPart = getDescriptionForConstantInScope ( scope ) ;
547+
546548 const scopeDescription = isFunctionLikeDeclaration ( scope )
547549 ? getDescriptionForFunctionLikeDeclaration ( scope )
548550 : isClassLike ( scope )
549551 ? getDescriptionForClassLikeDeclaration ( scope )
550552 : getDescriptionForModuleLikeDeclaration ( scope ) ;
553+
554+ let functionDescription : string ;
555+ let constantDescription : string ;
556+ if ( scopeDescription === SpecialScope . Global ) {
557+ functionDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_1_scope ) , [ functionDescriptionPart , "global" ] ) ;
558+ constantDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_1_scope ) , [ constantDescriptionPart , "global" ] ) ;
559+ }
560+ else if ( scopeDescription === SpecialScope . Module ) {
561+ functionDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_1_scope ) , [ functionDescriptionPart , "module" ] ) ;
562+ constantDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_1_scope ) , [ constantDescriptionPart , "module" ] ) ;
563+ }
564+ else {
565+ functionDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_1 ) , [ functionDescriptionPart , scopeDescription ] ) ;
566+ constantDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_1 ) , [ constantDescriptionPart , scopeDescription ] ) ;
567+ }
568+
569+ // Customize the phrasing for the innermost scope to increase clarity.
570+ if ( i === 0 && ! isClassLike ( scope ) ) {
571+ constantDescription = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Extract_to_0_in_enclosing_scope ) , [ constantDescriptionPart ] ) ;
572+ }
573+
551574 return {
552575 functionExtraction : {
553- description : getDescriptionForFunctionInScope ( scope ) ,
576+ description : functionDescription ,
554577 errors : functionErrorsPerScope [ i ] ,
555- scopeDescription,
556578 } ,
557579 constantExtraction : {
558- description : getDescriptionForConstantInScope ( scope ) ,
580+ description : constantDescription ,
559581 errors : constantErrorsPerScope [ i ] ,
560- scopeDescription : ( i === 0 && ! isClassLike ( scope ) )
561- ? "enclosing scope" // Like "global scope" and "module scope", this is not localized.
562- : scopeDescription ,
563582 } ,
564583 } ;
565584 } ) ;
@@ -628,10 +647,15 @@ namespace ts.refactor.extractSymbol {
628647 ? `class '${ scope . name . text } '`
629648 : scope . name ? `class expression '${ scope . name . text } '` : "anonymous class expression" ;
630649 }
631- function getDescriptionForModuleLikeDeclaration ( scope : SourceFile | ModuleBlock ) : string {
650+ function getDescriptionForModuleLikeDeclaration ( scope : SourceFile | ModuleBlock ) : string | SpecialScope {
632651 return scope . kind === SyntaxKind . ModuleBlock
633652 ? `namespace '${ scope . parent . name . getText ( ) } '`
634- : scope . externalModuleIndicator ? "module scope" : "global scope" ;
653+ : scope . externalModuleIndicator ? SpecialScope . Module : SpecialScope . Global ;
654+ }
655+
656+ const enum SpecialScope {
657+ Module ,
658+ Global ,
635659 }
636660
637661 function getUniqueName ( baseName : string , fileText : string ) : string {
0 commit comments