mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add args to diagnostic message
This commit is contained in:
@@ -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: [{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user