Skip to content

Commit 682f812

Browse files
author
Paul van Brenk
committed
PR feedback
1 parent 3df79d5 commit 682f812

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

src/services/codefixes/codeFixProvider.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts {
99
errorCode: string;
1010
sourceFile: SourceFile;
1111
span: TextSpan;
12-
checker: TypeChecker;
12+
program: Program;
1313
newLineCharacter: string;
1414
}
1515

@@ -27,24 +27,22 @@ namespace ts {
2727
});
2828
}
2929

30-
export class CodeFixProvider {
31-
public static getSupportedErrorCodes() {
32-
return Object.keys(codeFixes);
33-
}
30+
export function getSupportedErrorCodes() {
31+
return Object.keys(codeFixes);
32+
}
3433

35-
public getFixes(context: CodeFixContext): CodeAction[] {
36-
const fixes = codeFixes[context.errorCode];
37-
let allActions: CodeAction[] = [];
34+
export function getFixes(context: CodeFixContext): CodeAction[] {
35+
const fixes = codeFixes[context.errorCode];
36+
let allActions: CodeAction[] = [];
3837

39-
forEach(fixes, f => {
40-
const actions = f.getCodeActions(context);
41-
if (actions && actions.length > 0) {
42-
allActions = allActions.concat(actions);
43-
}
44-
});
38+
forEach(fixes, f => {
39+
const actions = f.getCodeActions(context);
40+
if (actions && actions.length > 0) {
41+
allActions = allActions.concat(actions);
42+
}
43+
});
4544

46-
return allActions;
47-
}
45+
return allActions;
4846
}
4947
}
50-
}
48+
}

src/services/services.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ namespace ts {
695695
}
696696

697697
export function getSupportedCodeFixes() {
698-
return codefix.CodeFixProvider.getSupportedErrorCodes();
698+
return codefix.getSupportedErrorCodes();
699699
}
700700

701701
// Cache host information about script Should be refreshed
@@ -918,7 +918,6 @@ namespace ts {
918918
documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService {
919919

920920
const syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
921-
const codeFixProvider: codefix.CodeFixProvider = new codefix.CodeFixProvider();
922921
let ruleProvider: formatting.RulesProvider;
923922
let program: Program;
924923
let lastProjectVersion: string;
@@ -1588,19 +1587,18 @@ namespace ts {
15881587
function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: string[]): CodeAction[] {
15891588
synchronizeHostData();
15901589
const sourceFile = getValidSourceFile(fileName);
1591-
const checker = program.getTypeChecker();
15921590
let allFixes: CodeAction[] = [];
15931591

15941592
forEach(errorCodes, error => {
15951593
const context = {
15961594
errorCode: error,
15971595
sourceFile: sourceFile,
15981596
span: { start, length: end - start },
1599-
checker: checker,
1597+
program: program,
16001598
newLineCharacter: getNewLineOrDefaultFromHost(host)
16011599
};
16021600

1603-
const fixes = codeFixProvider.getFixes(context);
1601+
const fixes = codefix.getFixes(context);
16041602
if (fixes) {
16051603
allFixes = allFixes.concat(fixes);
16061604
}

0 commit comments

Comments
 (0)