consolidate edits
This commit is contained in:
parent
d3661f5b6a
commit
ff061a1b93
3 changed files with 19 additions and 8 deletions
|
@ -31,7 +31,7 @@ namespace ts.codefix {
|
|||
|
||||
const newNodes = createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, checker);
|
||||
const changes = newNodesToChanges(newNodes, getOpenBraceOfClassLike(classDeclaration, sourceFile), context);
|
||||
if(changes && changes.length > 0) {
|
||||
if (changes && changes.length > 0) {
|
||||
return [{
|
||||
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
|
||||
changes
|
||||
|
|
|
@ -45,13 +45,13 @@ namespace ts.codefix {
|
|||
|
||||
function createAndAddMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind, hasIndexSigOfKind: boolean, newNodes: Node[]): void {
|
||||
if (hasIndexSigOfKind) {
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const indexInfoOfKind = checker.getIndexInfoOfType(type, kind);
|
||||
|
||||
if (!indexInfoOfKind) {
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
const newIndexSignatureDeclaration = checker.createIndexSignatureFromIndexInfo(indexInfoOfKind, kind, classDeclaration);
|
||||
newNodes.push(newIndexSignatureDeclaration);
|
||||
|
|
|
@ -3,17 +3,28 @@ namespace ts.codefix {
|
|||
|
||||
export function newNodesToChanges(newNodes: Node[], insertAfter: Node, context: CodeFixContext) {
|
||||
const sourceFile = context.sourceFile;
|
||||
if (!(newNodes)) {
|
||||
throw new Error("newNodesToChanges expects an array");
|
||||
}
|
||||
|
||||
const changeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
|
||||
|
||||
for (const newNode of newNodes) {
|
||||
changeTracker.insertNodeAfter(sourceFile, insertAfter, newNode, { suffix: context.newLineCharacter });
|
||||
}
|
||||
// TODO (aozgaa): concatenate changes into a single change.
|
||||
return changeTracker.getChanges();
|
||||
|
||||
const changes = changeTracker.getChanges();
|
||||
if (!(changes && changes.length > 0)) {
|
||||
return changes;
|
||||
}
|
||||
|
||||
Debug.assert(changes.length === 1);
|
||||
const consolidatedChanges: FileTextChanges[] = [{
|
||||
fileName: changes[0].fileName,
|
||||
textChanges: [{
|
||||
span: changes[0].textChanges[0].span,
|
||||
newText: changes[0].textChanges.reduce((prev, cur) => prev + cur.newText, "")
|
||||
}]
|
||||
|
||||
}]
|
||||
return consolidatedChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue