From 682f81257d345f72e230a53aa864d3dee4af6bdc Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Fri, 16 Sep 2016 14:52:33 -0700 Subject: [PATCH] PR feedback --- src/services/codefixes/codeFixProvider.ts | 32 +++++++++++------------ src/services/services.ts | 8 +++--- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/services/codefixes/codeFixProvider.ts b/src/services/codefixes/codeFixProvider.ts index 9c4e7404c95..55aa8d38f7a 100644 --- a/src/services/codefixes/codeFixProvider.ts +++ b/src/services/codefixes/codeFixProvider.ts @@ -9,7 +9,7 @@ namespace ts { errorCode: string; sourceFile: SourceFile; span: TextSpan; - checker: TypeChecker; + program: Program; newLineCharacter: string; } @@ -27,24 +27,22 @@ namespace ts { }); } - export class CodeFixProvider { - public static getSupportedErrorCodes() { - return Object.keys(codeFixes); - } + export function getSupportedErrorCodes() { + return Object.keys(codeFixes); + } - public getFixes(context: CodeFixContext): CodeAction[] { - const fixes = codeFixes[context.errorCode]; - let allActions: CodeAction[] = []; + export function getFixes(context: CodeFixContext): CodeAction[] { + const fixes = codeFixes[context.errorCode]; + let allActions: CodeAction[] = []; - forEach(fixes, f => { - const actions = f.getCodeActions(context); - if (actions && actions.length > 0) { - allActions = allActions.concat(actions); - } - }); + forEach(fixes, f => { + const actions = f.getCodeActions(context); + if (actions && actions.length > 0) { + allActions = allActions.concat(actions); + } + }); - return allActions; - } + return allActions; } } -} \ No newline at end of file +} diff --git a/src/services/services.ts b/src/services/services.ts index b481ffa5269..bf6ea627899 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -695,7 +695,7 @@ namespace ts { } export function getSupportedCodeFixes() { - return codefix.CodeFixProvider.getSupportedErrorCodes(); + return codefix.getSupportedErrorCodes(); } // Cache host information about script Should be refreshed @@ -918,7 +918,6 @@ namespace ts { documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService { const syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host); - const codeFixProvider: codefix.CodeFixProvider = new codefix.CodeFixProvider(); let ruleProvider: formatting.RulesProvider; let program: Program; let lastProjectVersion: string; @@ -1588,7 +1587,6 @@ namespace ts { function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: string[]): CodeAction[] { synchronizeHostData(); const sourceFile = getValidSourceFile(fileName); - const checker = program.getTypeChecker(); let allFixes: CodeAction[] = []; forEach(errorCodes, error => { @@ -1596,11 +1594,11 @@ namespace ts { errorCode: error, sourceFile: sourceFile, span: { start, length: end - start }, - checker: checker, + program: program, newLineCharacter: getNewLineOrDefaultFromHost(host) }; - const fixes = codeFixProvider.getFixes(context); + const fixes = codefix.getFixes(context); if (fixes) { allFixes = allFixes.concat(fixes); }