import * as vscode from 'vscode' ; import { Main } from './main' ; import { Config } from './config' ; export function activate ( context ) { console . log ( 'Ruby detected. Sonic Pi editor extension active!' ) ; let main = new Main ( ) ; main . checkSonicPiPath ( ) ; let config = new Config ( ) ; if ( config . launchSonicPiServerAutomatically ( ) === 'start' ) { main . startServer ( ) ; } let isRecording = false ; let disposable = vscode . commands . registerCommand ( 'sonicpieditor.startserver' , ( ) => { main . startServer ( ) ; } ) ; disposable = vscode . commands . registerTextEditorCommand ( 'sonicpieditor.run' , ( textEditor ) => { let doc = textEditor . document ; if ( doc . languageId !== 'ruby' ) { let textEditors = vscode . window . visibleTextEditors ; let rubyEditors = textEditors . filter ( ( editor ) => { return editor . document . languageId === 'ruby' ; } ) ; if ( ! rubyEditors . length ) { return ; } doc = rubyEditors [ 0 ] . document ; } let code = doc . getText ( ) ; main . flashCode ( textEditor , true ) ; main . runCode ( code ) ; } ) ; disposable = vscode . commands . registerTextEditorCommand ( 'sonicpieditor.runselected' , ( textEditor ) => { let doc = textEditor . document ; if ( doc . languageId !== 'ruby' ) { let textEditors = vscode . window . visibleTextEditors ; let rubyEditors = textEditors . filter ( ( editor ) => { return editor . document . languageId === 'ruby' ; } ) ; if ( ! rubyEditors . length ) { return ; } doc = rubyEditors [ 0 ] . document ; } let code = doc . getText ( textEditor . selection ) ; if ( ! code ) { let runFileWhenRunSelectedIsEmpty = config . runFileWhenRunSelectedIsEmpty ( ) ; if ( ! runFileWhenRunSelectedIsEmpty ) { vscode . window . showWarningMessage ( 'You tried to Run selected code with no code selected.' + 'Do you want to run the whole file when this happens?' , 'Yes, once' , 'Yes, always' , 'No, never' ) . then ( item => { if ( item === 'Yes, once' ) { code = doc . getText ( ) ; main . flashCode ( textEditor , true ) ; main . runCode ( code ) ; } else if ( item === 'Yes, always' ) { config . updateRunFileWhenRunSelectedIsEmpty ( 'always' ) ; code = doc . getText ( ) ; main . flashCode ( textEditor , true ) ; main . runCode ( code ) ; } else if ( item === 'No, never' ) { config . updateRunFileWhenRunSelectedIsEmpty ( 'never' ) ; } } ) ; return ; } else if ( runFileWhenRunSelectedIsEmpty === 'never' ) { return ; } else if ( runFileWhenRunSelectedIsEmpty === 'always' ) { code = doc . getText ( ) ; main . flashCode ( textEditor , true ) ; main . runCode ( code ) ; } } main . flashCode ( textEditor , false ) ; main . runCode ( code , textEditor . selection . start . line ) ; } ) ; disposable = vscode . commands . registerCommand ( 'sonicpieditor.stop' , ( ) => { main . stopAllJobs ( ) ; } ) ; disposable = vscode . commands . registerCommand ( 'sonicpieditor.togglerecording' , ( ) => { isRecording = ! isRecording ; if ( isRecording ) { main . startRecording ( ) ; } else { main . stopRecording ( ) ; vscode . window . showSaveDialog ( { filters : { 'Wave file' : [ 'wav' ] } } ) . then ( uri => { if ( uri ) { main . saveRecording ( uri . fsPath ) ; } else { main . deleteRecording ( ) ; } } ) ; } } ) ; context . subscriptions . push ( disposable ) ; } export function deactivate ( ) { }