Add args to diagnostic message
This commit is contained in:
parent
16b146f882
commit
f37640a43e
|
@ -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;
|
baseIndex = baseIndex || 0;
|
||||||
|
|
||||||
return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]);
|
return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]);
|
||||||
|
|
|
@ -3171,11 +3171,11 @@
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 90002
|
"code": 90002
|
||||||
},
|
},
|
||||||
"Change 'extends' to 'implements'": {
|
"Change 'extends' to 'implements'.": {
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 90003
|
"code": 90003
|
||||||
},
|
},
|
||||||
"Remove unused identifiers": {
|
"Remove unused identifiers.": {
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 90004
|
"code": 90004
|
||||||
},
|
},
|
||||||
|
@ -3183,11 +3183,11 @@
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 90005
|
"code": 90005
|
||||||
},
|
},
|
||||||
"Implement interface on class": {
|
"Implement interface '{0}'.": {
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 90006
|
"code": 90006
|
||||||
},
|
},
|
||||||
"Implement inherited abstract class": {
|
"Implement inherited abstract class.": {
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 90007
|
"code": 90007
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace ts.codefix {
|
||||||
|
|
||||||
const insertion = getMissingMembersInsertion(classDecl, abstractAndNonPrivateExtendsSymbols, checker, context.newLineCharacter);
|
const insertion = getMissingMembersInsertion(classDecl, abstractAndNonPrivateExtendsSymbols, checker, context.newLineCharacter);
|
||||||
|
|
||||||
if (insertion.length > 0) {
|
if (insertion) {
|
||||||
return [{
|
return [{
|
||||||
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
|
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
|
||||||
changes: [{
|
changes: [{
|
||||||
|
|
|
@ -27,7 +27,10 @@ namespace ts.codefix {
|
||||||
const nonPrivateMembers = implementedTypeSymbols.filter(symbolRefersToNonPrivateMember);
|
const nonPrivateMembers = implementedTypeSymbols.filter(symbolRefersToNonPrivateMember);
|
||||||
|
|
||||||
const insertion = getMissingMembersInsertion(classDecl, nonPrivateMembers, checker, context.newLineCharacter);
|
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;
|
return result;
|
||||||
|
@ -39,19 +42,17 @@ namespace ts.codefix {
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushAction(result: CodeAction[], insertion: string, description: string): void {
|
function pushAction(result: CodeAction[], insertion: string, description: string): void {
|
||||||
if (insertion && insertion.length) {
|
const newAction: CodeAction = {
|
||||||
const newAction: CodeAction = {
|
description: description,
|
||||||
description: description,
|
changes: [{
|
||||||
changes: [{
|
fileName: sourceFile.fileName,
|
||||||
fileName: sourceFile.fileName,
|
textChanges: [{
|
||||||
textChanges: [{
|
span: { start: startPos, length: 0 },
|
||||||
span: { start: startPos, length: 0 },
|
newText: insertion
|
||||||
newText: insertion
|
|
||||||
}]
|
|
||||||
}]
|
}]
|
||||||
};
|
}]
|
||||||
result.push(newAction);
|
};
|
||||||
}
|
result.push(newAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1363,6 +1363,7 @@ namespace ts {
|
||||||
* Finds members of the resolved type that are missing in the class pointed to by class decl
|
* 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.
|
* and generates source code for the missing members.
|
||||||
* @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for.
|
* @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 {
|
export function getMissingMembersInsertion(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: Symbol[], checker: TypeChecker, newlineChar: string): string {
|
||||||
const classMembers = classDeclaration.symbol.members;
|
const classMembers = classDeclaration.symbol.members;
|
||||||
|
@ -1373,7 +1374,7 @@ namespace ts {
|
||||||
for (const symbol of missingMembers) {
|
for (const symbol of missingMembers) {
|
||||||
insertion = insertion.concat(getInsertionForMemberSymbol(symbol, classDeclaration, checker, newlineChar));
|
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 {
|
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {
|
||||||
|
|
Loading…
Reference in a new issue