import * as ts from 'typescript/lib/tsserverlibrary' ; import * as pluginApi from '../tsc_wrapped/plugin_api' ; import { Checker } from './checker' ; import { registerRules } from './runner' ; function init ( ) { return { create ( info ) { const oldService = info . languageService ; const proxy = pluginApi . createProxy ( oldService ) ; proxy . getSemanticDiagnostics = ( fileName ) => { const program = oldService . getProgram ( ) ; if ( ! program ) { throw new Error ( 'Failed to initialize tsetse language_service_plugin: program is undefined' ) ; } const checker = new Checker ( program ) ; registerRules ( checker , info . config . disabledRules || [ ] ) ; const result = [ ... oldService . getSemanticDiagnostics ( fileName ) ] ; result . push ( ... checker . execute ( program . getSourceFile ( fileName ) ! ) . map ( failure => failure . toDiagnostic ( ) ) ) ; return result ; } ; return proxy ; } } ; } export = init ;