From ba5f09b66d7f51ef7f54e8cf4f7893df331f98b2 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 2 Oct 2017 15:30:52 -0700 Subject: [PATCH] Localize 'in' in extraction description --- src/compiler/diagnosticMessages.json | 2 +- src/services/refactors/extractSymbol.ts | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4465976d170..292c7f305c0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3720,7 +3720,7 @@ "code": 95003 }, - "Extract to {0}": { + "Extract to {0} in {1}": { "category": "Message", "code": 95004 }, diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 352ab91c6b9..912992be50f 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -43,7 +43,7 @@ namespace ts.refactor.extractSymbol { // Don't issue refactorings with duplicated names. // Scopes come back in "innermost first" order, so extractions will // preferentially go into nearer scopes - const description = formatStringFromArgs(Diagnostics.Extract_to_0.message, [extraction.functionDescription]); + const description = formatStringFromArgs(Diagnostics.Extract_to_0_in_1.message, [extraction.functionDescription, extraction.scopeDescription]); if (!usedFunctionNames.has(description)) { usedFunctionNames.set(description, true); functionActions.push({ @@ -58,7 +58,7 @@ namespace ts.refactor.extractSymbol { // Don't issue refactorings with duplicated names. // Scopes come back in "innermost first" order, so extractions will // preferentially go into nearer scopes - const description = formatStringFromArgs(Diagnostics.Extract_to_0.message, [extraction.constantDescription]); + const description = formatStringFromArgs(Diagnostics.Extract_to_0_in_1.message, [extraction.constantDescription, extraction.scopeDescription]); if (!usedConstantNames.has(description)) { usedConstantNames.set(description, true); constantActions.push({ @@ -547,6 +547,7 @@ namespace ts.refactor.extractSymbol { readonly functionErrors: ReadonlyArray; readonly constantDescription: string; readonly constantErrors: ReadonlyArray; + readonly scopeDescription: string; } /** * Given a piece of text to extract ('targetRange'), computes a list of possible extractions. @@ -561,6 +562,11 @@ namespace ts.refactor.extractSymbol { functionErrors: functionErrorsPerScope[i], constantDescription: getDescriptionForConstantInScope(scope), constantErrors: constantErrorsPerScope[i], + scopeDescription: isFunctionLikeDeclaration(scope) + ? getDescriptionForFunctionLikeDeclaration(scope) + : isClassLike(scope) + ? getDescriptionForClassLikeDeclaration(scope) + : getDescriptionForModuleLikeDeclaration(scope) })); return extractions; } @@ -590,17 +596,15 @@ namespace ts.refactor.extractSymbol { function getDescriptionForFunctionInScope(scope: Scope): string { return isFunctionLikeDeclaration(scope) - ? `inner function in ${getDescriptionForFunctionLikeDeclaration(scope)}` + ? "inner function" : isClassLike(scope) - ? `method in ${getDescriptionForClassLikeDeclaration(scope)}` - : `function in ${getDescriptionForModuleLikeDeclaration(scope)}`; + ? "method" + : "function"; } function getDescriptionForConstantInScope(scope: Scope): string { - return isFunctionLikeDeclaration(scope) - ? `constant in ${getDescriptionForFunctionLikeDeclaration(scope)}` - : isClassLike(scope) - ? `readonly field in ${getDescriptionForClassLikeDeclaration(scope)}` - : `constant in ${getDescriptionForModuleLikeDeclaration(scope)}`; + return isClassLike(scope) + ? "readonly field" + : "constant"; } function getDescriptionForFunctionLikeDeclaration(scope: FunctionLikeDeclaration): string { switch (scope.kind) {