import { AbstractFormatter } from './Formatters/AbstractFormatter' ; import { CoverageMapProvider } from './CoverageMapProvider' ; import { DefaultFormatter } from './Formatters/DefaultFormatter' ; import { GutterFormatter } from './Formatters/GutterFormatter' ; import * as vscode from 'vscode' ; export type CoverageStatus = 'covered' | 'partially-covered' | 'uncovered' ; export type CoverageColors = { [ key in CoverageStatus ] ? : string ; } ; export class CoverageOverlay { static readonly defaultVisibility = false ; static readonly defaultFormatter = 'DefaultFormatter' ; formatter : AbstractFormatter ; private _enabled : boolean ; constructor ( context , coverageMapProvider , enabled = CoverageOverlay . defaultVisibility , coverageFormatter = CoverageOverlay . defaultFormatter , colors ? ) { this . _enabled = enabled ; switch ( coverageFormatter ) { case 'GutterFormatter' : this . formatter = new GutterFormatter ( context , coverageMapProvider , colors ) ; break ; default : this . formatter = new DefaultFormatter ( coverageMapProvider , colors ) ; break ; } } get enabled ( ) : boolean { return this . _enabled ; } set enabled ( value ) { this . _enabled = value ; this . updateVisibleEditors ( ) ; } /** give formatter opportunity to dispose the decorators */ dispose ( ) { this . formatter . dispose ( ) ; } toggleVisibility ( ) { this . _enabled = ! this . _enabled ; this . updateVisibleEditors ( ) ; } updateVisibleEditors ( ) { for ( const editor of vscode . window . visibleTextEditors ) { this . update ( editor ) ; } } update ( editor ) { if ( ! editor . document ) { return ; } if ( this . _enabled ) { this . formatter . format ( editor ) ; } else { this . formatter . clear ( editor ) ; } } }