Skip to content

Commit 3a38c8e

Browse files
committed
Replace TextChangesContext with RefactorOrCodeFixContext
Thanks to @Andy-MS for the suggestion!
1 parent 13bf7f9 commit 3a38c8e

23 files changed

Lines changed: 47 additions & 59 deletions

src/services/codeFixProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ts {
77
getAllCodeActions?(context: CodeFixAllContext): CombinedCodeActions;
88
}
99

10-
export interface CodeFixContextBase extends RefactorOrCodeFixContext {
10+
export interface CodeFixContextBase extends textChanges.TextChangesContext {
1111
sourceFile: SourceFile;
1212
program: Program;
1313
cancellationToken: CancellationToken;
@@ -83,7 +83,7 @@ namespace ts {
8383

8484
export function codeFixAll(context: CodeFixAllContext, errorCodes: number[], use: (changes: textChanges.ChangeTracker, error: Diagnostic, commands: Push<CodeActionCommand>) => void): CombinedCodeActions {
8585
const commands: CodeActionCommand[] = [];
86-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t =>
86+
const changes = textChanges.ChangeTracker.with(context, t =>
8787
eachDiagnostic(context, errorCodes, diag => use(t, diag, commands)));
8888
return createCombinedCodeActions(changes, commands.length === 0 ? undefined : commands);
8989
}

src/services/codefixes/addMissingInvocationForDecorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ts.codefix {
55
registerCodeFix({
66
errorCodes,
77
getCodeActions: (context) => {
8-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => makeChange(t, context.sourceFile, context.span.start));
8+
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
99
return [{ description: getLocaleSpecificMessage(Diagnostics.Call_decorator_expression), changes, fixId }];
1010
},
1111
fixIds: [fixId],

src/services/codefixes/correctQualifiedNameToIndexedAccessType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ts.codefix {
77
getCodeActions(context) {
88
const qualifiedName = getQualifiedName(context.sourceFile, context.span.start);
99
if (!qualifiedName) return undefined;
10-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => doChange(t, context.sourceFile, qualifiedName));
10+
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, context.sourceFile, qualifiedName));
1111
const description = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Rewrite_as_the_indexed_access_type_0), [`${qualifiedName.left.text}["${qualifiedName.right.text}"]`]);
1212
return [{ description, changes, fixId }];
1313
},

src/services/codefixes/disableJsDiagnostics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace ts.codefix {
1515
return undefined;
1616
}
1717

18-
const newLineCharacter = getNewLineFromContext(context);
18+
const newLineCharacter = textChanges.getNewLineFromContext(context);
1919

2020
return [{
2121
description: getLocaleSpecificMessage(Diagnostics.Ignore_this_error_message),
@@ -38,7 +38,7 @@ namespace ts.codefix {
3838
fixIds: [fixId], // No point applying as a group, doing it once will fix all errors
3939
getAllCodeActions: context => codeFixAllWithTextChanges(context, errorCodes, (changes, err) => {
4040
if (err.start !== undefined) {
41-
changes.push(getIgnoreCommentLocationForLocation(err.file!, err.start, getNewLineFromContext(context)));
41+
changes.push(getIgnoreCommentLocationForLocation(err.file!, err.start, textChanges.getNewLineFromContext(context)));
4242
}
4343
}),
4444
});

src/services/codefixes/fixAddMissingMember.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace ts.codefix {
9696
}
9797

9898
function getActionsForAddMissingMemberInJavaScriptFile(context: CodeFixContext, classDeclarationSourceFile: SourceFile, classDeclaration: ClassLikeDeclaration, tokenName: string, makeStatic: boolean): CodeFixAction | undefined {
99-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => addMissingMemberInJs(t, classDeclarationSourceFile, classDeclaration, tokenName, makeStatic));
99+
const changes = textChanges.ChangeTracker.with(context, t => addMissingMemberInJs(t, classDeclarationSourceFile, classDeclaration, tokenName, makeStatic));
100100
if (changes.length === 0) return undefined;
101101
const description = formatStringFromArgs(getLocaleSpecificMessage(makeStatic ? Diagnostics.Initialize_static_property_0 : Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]);
102102
return { description, changes, fixId };
@@ -144,7 +144,7 @@ namespace ts.codefix {
144144

145145
function createAddPropertyDeclarationAction(context: CodeFixContext, classDeclarationSourceFile: SourceFile, classDeclaration: ClassLikeDeclaration, makeStatic: boolean, tokenName: string, typeNode: TypeNode): CodeFixAction {
146146
const description = formatStringFromArgs(getLocaleSpecificMessage(makeStatic ? Diagnostics.Declare_static_property_0 : Diagnostics.Declare_property_0), [tokenName]);
147-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => addPropertyDeclaration(t, classDeclarationSourceFile, classDeclaration, tokenName, typeNode, makeStatic));
147+
const changes = textChanges.ChangeTracker.with(context, t => addPropertyDeclaration(t, classDeclarationSourceFile, classDeclaration, tokenName, typeNode, makeStatic));
148148
return { description, changes, fixId };
149149
}
150150

@@ -176,14 +176,14 @@ namespace ts.codefix {
176176
[indexingParameter],
177177
typeNode);
178178

179-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => t.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, indexSignature));
179+
const changes = textChanges.ChangeTracker.with(context, t => t.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, indexSignature));
180180
// No fixId here because code-fix-all currently only works on adding individual named properties.
181181
return { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_property_0), [tokenName]), changes, fixId: undefined };
182182
}
183183

184184
function getActionForMethodDeclaration(context: CodeFixContext, classDeclarationSourceFile: SourceFile, classDeclaration: ClassLikeDeclaration, token: Identifier, callExpression: CallExpression, makeStatic: boolean, inJs: boolean): CodeFixAction | undefined {
185185
const description = formatStringFromArgs(getLocaleSpecificMessage(makeStatic ? Diagnostics.Declare_static_method_0 : Diagnostics.Declare_method_0), [token.text]);
186-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => addMethodDeclaration(t, classDeclarationSourceFile, classDeclaration, token, callExpression, makeStatic, inJs));
186+
const changes = textChanges.ChangeTracker.with(context, t => addMethodDeclaration(t, classDeclarationSourceFile, classDeclaration, token, callExpression, makeStatic, inJs));
187187
return { description, changes, fixId };
188188
}
189189

src/services/codefixes/fixAwaitInSyncFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ts.codefix {
1111
const { sourceFile, span } = context;
1212
const nodes = getNodes(sourceFile, span.start);
1313
if (!nodes) return undefined;
14-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => doChange(t, sourceFile, nodes));
14+
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, nodes));
1515
return [{ description: getLocaleSpecificMessage(Diagnostics.Add_async_modifier_to_containing_function), changes, fixId }];
1616
},
1717
fixIds: [fixId],

src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts.codefix {
99
errorCodes,
1010
getCodeActions(context) {
1111
const { program, sourceFile, span } = context;
12-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t =>
12+
const changes = textChanges.ChangeTracker.with(context, t =>
1313
addMissingMembers(getClass(sourceFile, span.start), sourceFile, program.getTypeChecker(), t));
1414
return changes.length === 0 ? undefined : [{ description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class), changes, fixId }];
1515
},

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ts.codefix {
1010
const classDeclaration = getClass(sourceFile, span.start);
1111
const checker = program.getTypeChecker();
1212
return mapDefined<ExpressionWithTypeArguments, CodeFixAction>(getClassImplementsHeritageClauseElements(classDeclaration), implementedTypeNode => {
13-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => addMissingDeclarations(checker, implementedTypeNode, sourceFile, classDeclaration, t));
13+
const changes = textChanges.ChangeTracker.with(context, t => addMissingDeclarations(checker, implementedTypeNode, sourceFile, classDeclaration, t));
1414
if (changes.length === 0) return undefined;
1515
const description = formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Implement_interface_0), [implementedTypeNode.getText()]);
1616
return { description, changes, fixId };

src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts.codefix {
99
const nodes = getNodes(sourceFile, span.start);
1010
if (!nodes) return undefined;
1111
const { constructor, superCall } = nodes;
12-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => doChange(t, sourceFile, constructor, superCall));
12+
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, constructor, superCall));
1313
return [{ description: getLocaleSpecificMessage(Diagnostics.Make_super_call_the_first_statement_in_the_constructor), changes, fixId }];
1414
},
1515
fixIds: [fixId],

src/services/codefixes/fixConstructorForDerivedNeedSuperCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ts.codefix {
77
getCodeActions(context) {
88
const { sourceFile, span } = context;
99
const ctr = getNode(sourceFile, span.start);
10-
const changes = textChanges.ChangeTracker.with(toTextChangesContext(context), t => doChange(t, sourceFile, ctr));
10+
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, ctr));
1111
return [{ description: getLocaleSpecificMessage(Diagnostics.Add_missing_super_call), changes, fixId }];
1212
},
1313
fixIds: [fixId],

0 commit comments

Comments
 (0)