Skip to content

Commit f37640a

Browse files
author
Arthur Ozga
committed
Add args to diagnostic message
1 parent 16b146f commit f37640a

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ namespace ts {
10781078
}
10791079
}
10801080

1081-
function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
1081+
export function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
10821082
baseIndex = baseIndex || 0;
10831083

10841084
return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,23 +3171,23 @@
31713171
"category": "Message",
31723172
"code": 90002
31733173
},
3174-
"Change 'extends' to 'implements'": {
3174+
"Change 'extends' to 'implements'.": {
31753175
"category": "Message",
31763176
"code": 90003
31773177
},
3178-
"Remove unused identifiers": {
3178+
"Remove unused identifiers.": {
31793179
"category": "Message",
31803180
"code": 90004
31813181
},
31823182
"Implement interface on reference": {
31833183
"category": "Message",
31843184
"code": 90005
31853185
},
3186-
"Implement interface on class": {
3186+
"Implement interface '{0}'.": {
31873187
"category": "Message",
31883188
"code": 90006
31893189
},
3190-
"Implement inherited abstract class": {
3190+
"Implement inherited abstract class.": {
31913191
"category": "Message",
31923192
"code": 90007
31933193
},

src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ts.codefix {
2020

2121
const insertion = getMissingMembersInsertion(classDecl, abstractAndNonPrivateExtendsSymbols, checker, context.newLineCharacter);
2222

23-
if (insertion.length > 0) {
23+
if (insertion) {
2424
return [{
2525
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
2626
changes: [{

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ namespace ts.codefix {
2727
const nonPrivateMembers = implementedTypeSymbols.filter(symbolRefersToNonPrivateMember);
2828

2929
const insertion = getMissingMembersInsertion(classDecl, nonPrivateMembers, checker, context.newLineCharacter);
30-
pushAction(result, insertion, getLocaleSpecificMessage(Diagnostics.Implement_interface_on_class));
30+
const message = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Implement_interface_0), [implementedTypeNode.getText()]);
31+
if (insertion) {
32+
pushAction(result, insertion, message);
33+
}
3134
}
3235

3336
return result;
@@ -39,19 +42,17 @@ namespace ts.codefix {
3942
}
4043

4144
function pushAction(result: CodeAction[], insertion: string, description: string): void {
42-
if (insertion && insertion.length) {
43-
const newAction: CodeAction = {
44-
description: description,
45-
changes: [{
46-
fileName: sourceFile.fileName,
47-
textChanges: [{
48-
span: { start: startPos, length: 0 },
49-
newText: insertion
50-
}]
45+
const newAction: CodeAction = {
46+
description: description,
47+
changes: [{
48+
fileName: sourceFile.fileName,
49+
textChanges: [{
50+
span: { start: startPos, length: 0 },
51+
newText: insertion
5152
}]
52-
};
53-
result.push(newAction);
54-
}
53+
}]
54+
};
55+
result.push(newAction);
5556
}
5657
}
5758
});

src/services/utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ namespace ts {
13631363
* Finds members of the resolved type that are missing in the class pointed to by class decl
13641364
* and generates source code for the missing members.
13651365
* @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for.
1366+
* @returns undefined iff there is no insertion available.
13661367
*/
13671368
export function getMissingMembersInsertion(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: Symbol[], checker: TypeChecker, newlineChar: string): string {
13681369
const classMembers = classDeclaration.symbol.members;
@@ -1373,7 +1374,7 @@ namespace ts {
13731374
for (const symbol of missingMembers) {
13741375
insertion = insertion.concat(getInsertionForMemberSymbol(symbol, classDeclaration, checker, newlineChar));
13751376
}
1376-
return insertion;
1377+
return insertion.length > 0 ? insertion : undefined;
13771378
}
13781379

13791380
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {

0 commit comments

Comments
 (0)