import * as vs from "vscode" ; import * as tsu from "@derander/tsunami" ; import { TsunamiPlugin } from "./TsunamiPlugin" ; import { VscodeCommand , VscodeTextEditorCommand } from "./commands/VscodeCommand" ; const TS_MODE = [ { language : "typescriptreact" } , { language : "typescript" } ] ; export class TsunamiExtension implements TsunamiPlugin { constructor ( private context , private plugins , private commands , private textEditorCommands ) { } private registerCommands ( ) { const disposables = [ ] ; for ( let command of this . commands ) { disposables . push ( vs . commands . registerCommand ( command . commandName , async ( ... args ) => { try { await command . execute ( ... args ) ; } catch ( e ) { console . error ( e ) ; } } ) ) ; } for ( let command of this . textEditorCommands ) { disposables . push ( vs . commands . registerTextEditorCommand ( command . commandName , async ( editor , edit , ... args ) => { try { await command . execute ( editor , edit , ... args ) ; } catch ( e ) { console . error ( e ) ; } } ) ) ; } return disposables ; } public bindToContext ( context ) { const disposables = this . registerCommands ( ) ; disposables . push ( vs . workspace . onDidSaveTextDocument ( document => { if ( vs . languages . match ( TS_MODE , document ) > 0 ) { this . context . reloadFile ( document . fileName , document . getText ( ) ) ; } } ) ) ; this . plugins . forEach ( plugin => plugin . bindToContext ( context ) ) ; disposables . forEach ( d => context . subscriptions . push ( d ) ) ; } }