Add args to diagnostic message

This commit is contained in:
Arthur Ozga 2016-11-28 16:47:26 -06:00
parent 16b146f882
commit f37640a43e
5 changed files with 22 additions and 20 deletions

View file

@ -1078,7 +1078,7 @@ namespace ts {
}
}
function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
export function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
baseIndex = baseIndex || 0;
return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]);

View file

@ -3171,11 +3171,11 @@
"category": "Message",
"code": 90002
},
"Change 'extends' to 'implements'": {
"Change 'extends' to 'implements'.": {
"category": "Message",
"code": 90003
},
"Remove unused identifiers": {
"Remove unused identifiers.": {
"category": "Message",
"code": 90004
},
@ -3183,11 +3183,11 @@
"category": "Message",
"code": 90005
},
"Implement interface on class": {
"Implement interface '{0}'.": {
"category": "Message",
"code": 90006
},
"Implement inherited abstract class": {
"Implement inherited abstract class.": {
"category": "Message",
"code": 90007
},

View file

@ -20,7 +20,7 @@ namespace ts.codefix {
const insertion = getMissingMembersInsertion(classDecl, abstractAndNonPrivateExtendsSymbols, checker, context.newLineCharacter);
if (insertion.length > 0) {
if (insertion) {
return [{
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
changes: [{

View file

@ -27,7 +27,10 @@ namespace ts.codefix {
const nonPrivateMembers = implementedTypeSymbols.filter(symbolRefersToNonPrivateMember);
const insertion = getMissingMembersInsertion(classDecl, nonPrivateMembers, checker, context.newLineCharacter);
pushAction(result, insertion, getLocaleSpecificMessage(Diagnostics.Implement_interface_on_class));
const message = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Implement_interface_0), [implementedTypeNode.getText()]);
if (insertion) {
pushAction(result, insertion, message);
}
}
return result;
@ -39,19 +42,17 @@ namespace ts.codefix {
}
function pushAction(result: CodeAction[], insertion: string, description: string): void {
if (insertion && insertion.length) {
const newAction: CodeAction = {
description: description,
changes: [{
fileName: sourceFile.fileName,
textChanges: [{
span: { start: startPos, length: 0 },
newText: insertion
}]
const newAction: CodeAction = {
description: description,
changes: [{
fileName: sourceFile.fileName,
textChanges: [{
span: { start: startPos, length: 0 },
newText: insertion
}]
};
result.push(newAction);
}
}]
};
result.push(newAction);
}
}
});

View file

@ -1363,6 +1363,7 @@ namespace ts {
* Finds members of the resolved type that are missing in the class pointed to by class decl
* and generates source code for the missing members.
* @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for.
* @returns undefined iff there is no insertion available.
*/
export function getMissingMembersInsertion(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: Symbol[], checker: TypeChecker, newlineChar: string): string {
const classMembers = classDeclaration.symbol.members;
@ -1373,7 +1374,7 @@ namespace ts {
for (const symbol of missingMembers) {
insertion = insertion.concat(getInsertionForMemberSymbol(symbol, classDeclaration, checker, newlineChar));
}
return insertion;
return insertion.length > 0 ? insertion : undefined;
}
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {