"use strict" ; import { window , commands , workspace , Disposable , ExtensionContext , StatusBarAlignment , StatusBarItem , TextDocument } from "vscode" ; export function activate ( context ) { let discourager = new Discourager ( ) ; let disposable = commands . registerCommand ( "discourage.toggle" , ( ) => { discourager . updateDiscourageMessage ( ) ; } ) ; workspace . onDidSaveTextDocument ( e => { discourager . updateDiscourageMessage ( ) ; } ) ; context . subscriptions . push ( discourager ) ; context . subscriptions . push ( disposable ) ; } export function deactivate ( ) { } class Discourager { private _statusBarItem : StatusBarItem ; private _discouragements = [ "That was pretty meh..." , "Uh... are you ok?" , "Not sure about what you just did there..." , "Do you want me to be nice... or honest?" , "Maybe you should take the rest of the day off..." , "I'm not going to say you made a mistake... but..." , "Was that a typo, or..." , "Yikes..." ] ; private _timer : any ; private statusBarAutoDismiss ( millisecBeforeDismiss ) { if ( ! this . _statusBarItem ) { return ; } clearTimeout ( this . _timer ) ; let that = this ; this . _timer = setTimeout ( function ( ) { that . _statusBarItem . hide ( ) ; } , millisecBeforeDismiss ) ; } private getRandomDiscouragement ( ) { return this . _discouragements [ Math . floor ( Math . random ( ) * this . _discouragements . length ) ] ; } public updateDiscourageMessage ( ) { if ( ! this . _statusBarItem ) { this . _statusBarItem = window . createStatusBarItem ( StatusBarAlignment . Left ) ; } let editor = window . activeTextEditor ; if ( ! editor ) { this . _statusBarItem . hide ( ) ; return ; } this . _statusBarItem . text = this . getRandomDiscouragement ( ) ; this . _statusBarItem . show ( ) ; this . statusBarAutoDismiss ( 5000 ) ; } dispose ( ) { this . _statusBarItem . dispose ( ) ; } }