import * as vscode from "vscode" ; import CompileLessCommand from "./CompileLessCommand" ; const LESS_EXT = ".less" ; const COMPILE_COMMAND = "easyLess.compile" ; let lessDiagnosticCollection ; export function activate ( context ) { lessDiagnosticCollection = vscode . languages . createDiagnosticCollection ( ) ; const compileLessSub = vscode . commands . registerCommand ( COMPILE_COMMAND , ( ) => { const activeEditor = vscode . window . activeTextEditor ; if ( activeEditor ) { const document = activeEditor . document ; if ( document . fileName . endsWith ( LESS_EXT ) ) { document . save ( ) ; new CompileLessCommand ( document , lessDiagnosticCollection ) . execute ( ) ; } else { vscode . window . showWarningMessage ( "This command only works for .less files." ) ; } } else { vscode . window . showInformationMessage ( "This command is only available when a .less editor is open." ) ; } } ) ; const didSaveEvent = vscode . workspace . onDidSaveTextDocument ( ( document ) => { if ( document . fileName . endsWith ( LESS_EXT ) ) { new CompileLessCommand ( document , lessDiagnosticCollection ) . execute ( ) ; } } ) ; const willSaveEvent = vscode . workspace . onWillSaveTextDocument ( ( e ) => { if ( e . document . fileName . endsWith ( LESS_EXT ) && ! e . document . isDirty ) { new CompileLessCommand ( e . document , lessDiagnosticCollection ) . execute ( ) ; } } ) ; const didCloseEvent = vscode . workspace . onDidCloseTextDocument ( ( doc ) => { if ( doc . fileName . endsWith ( LESS_EXT ) ) { lessDiagnosticCollection . delete ( doc . uri ) ; } } ) ; context . subscriptions . push ( compileLessSub ) ; context . subscriptions . push ( willSaveEvent ) ; context . subscriptions . push ( didSaveEvent ) ; context . subscriptions . push ( didCloseEvent ) ; } export function deactivate ( ) { if ( lessDiagnosticCollection ) { lessDiagnosticCollection . dispose ( ) ; } }