Skip to content

Commit ba5f09b

Browse files
committed
Localize 'in' in extraction description
1 parent bcc93f2 commit ba5f09b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3720,7 +3720,7 @@
37203720
"code": 95003
37213721
},
37223722

3723-
"Extract to {0}": {
3723+
"Extract to {0} in {1}": {
37243724
"category": "Message",
37253725
"code": 95004
37263726
},

src/services/refactors/extractSymbol.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.message, [extraction.functionDescription]);
46+
const description = formatStringFromArgs(Diagnostics.Extract_to_0_in_1.message, [extraction.functionDescription, extraction.scopeDescription]);
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.message, [extraction.constantDescription]);
61+
const description = formatStringFromArgs(Diagnostics.Extract_to_0_in_1.message, [extraction.constantDescription, extraction.scopeDescription]);
6262
if (!usedConstantNames.has(description)) {
6363
usedConstantNames.set(description, true);
6464
constantActions.push({
@@ -547,6 +547,7 @@ namespace ts.refactor.extractSymbol {
547547
readonly functionErrors: ReadonlyArray<Diagnostic>;
548548
readonly constantDescription: string;
549549
readonly constantErrors: ReadonlyArray<Diagnostic>;
550+
readonly scopeDescription: string;
550551
}
551552
/**
552553
* Given a piece of text to extract ('targetRange'), computes a list of possible extractions.
@@ -561,6 +562,11 @@ namespace ts.refactor.extractSymbol {
561562
functionErrors: functionErrorsPerScope[i],
562563
constantDescription: getDescriptionForConstantInScope(scope),
563564
constantErrors: constantErrorsPerScope[i],
565+
scopeDescription: isFunctionLikeDeclaration(scope)
566+
? getDescriptionForFunctionLikeDeclaration(scope)
567+
: isClassLike(scope)
568+
? getDescriptionForClassLikeDeclaration(scope)
569+
: getDescriptionForModuleLikeDeclaration(scope)
564570
}));
565571
return extractions;
566572
}
@@ -590,17 +596,15 @@ namespace ts.refactor.extractSymbol {
590596

591597
function getDescriptionForFunctionInScope(scope: Scope): string {
592598
return isFunctionLikeDeclaration(scope)
593-
? `inner function in ${getDescriptionForFunctionLikeDeclaration(scope)}`
599+
? "inner function"
594600
: isClassLike(scope)
595-
? `method in ${getDescriptionForClassLikeDeclaration(scope)}`
596-
: `function in ${getDescriptionForModuleLikeDeclaration(scope)}`;
601+
? "method"
602+
: "function";
597603
}
598604
function getDescriptionForConstantInScope(scope: Scope): string {
599-
return isFunctionLikeDeclaration(scope)
600-
? `constant in ${getDescriptionForFunctionLikeDeclaration(scope)}`
601-
: isClassLike(scope)
602-
? `readonly field in ${getDescriptionForClassLikeDeclaration(scope)}`
603-
: `constant in ${getDescriptionForModuleLikeDeclaration(scope)}`;
605+
return isClassLike(scope)
606+
? "readonly field"
607+
: "constant";
604608
}
605609
function getDescriptionForFunctionLikeDeclaration(scope: FunctionLikeDeclaration): string {
606610
switch (scope.kind) {

0 commit comments

Comments
 (0)