@@ -4,16 +4,18 @@ import { setStorage } from '../storage'
44import ReactWebView from '../ReactWebView'
55import { isEmptyWorkspace } from '../workspace'
66import * as CR from 'typings'
7+ import runTest from './runTest'
78
89const COMMANDS = {
910 START : 'coderoad.start' ,
1011 TUTORIAL_LAUNCH : 'coderoad.tutorial_launch' ,
12+ TUTORIAL_SETUP : 'coderoad.tutorial_setup' ,
1113 OPEN_WEBVIEW : 'coderoad.open_webview' ,
1214 SEND_STATE : 'coderoad.send_state' ,
1315 SEND_DATA : 'coderoad.send_data' ,
1416 RECEIVE_ACTION : 'coderoad.receive_action' ,
1517 OPEN_FILE : 'coderoad.open_file' ,
16- RUN_TEST : 'coderoad.test_run ' ,
18+ RUN_TEST : 'coderoad.run_test ' ,
1719}
1820
1921interface CreateCommandProps {
@@ -62,6 +64,19 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
6264 const { setup } = steps [ pos . stepId ] . actions
6365 await git . gitLoadCommits ( setup )
6466 } ,
67+ [ COMMANDS . TUTORIAL_SETUP ] : async ( tutorial : CR . Tutorial ) => {
68+ console . log ( 'tutorial setup' , tutorial )
69+ // setup onSave hook
70+ const languageIds = tutorial . meta . languages
71+ console . log ( `languageIds: ${ languageIds . join ( ', ' ) } ` )
72+ vscode . workspace . onDidSaveTextDocument ( ( document : vscode . TextDocument ) => {
73+ console . log ( 'save document' , document )
74+ if ( languageIds . includes ( document . languageId ) && document . uri . scheme === 'file' ) {
75+ // do work
76+ vscode . commands . executeCommand ( 'coderoad.run_test' )
77+ }
78+ } )
79+ } ,
6580 // open a file
6681 [ COMMANDS . OPEN_FILE ] : async ( relativeFilePath : string ) => {
6782 console . log ( `OPEN_FILE ${ JSON . stringify ( relativeFilePath ) } ` )
@@ -85,6 +100,10 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
85100 webview . postMessage ( { type : 'SET_DATA' , payload } )
86101 } ,
87102 [ COMMANDS . RECEIVE_ACTION ] : ( action : string | CR . Action ) => {
103+ // send received actions from web-app into state machine
88104 machine . send ( action )
105+ } ,
106+ [ COMMANDS . RUN_TEST ] : ( ) => {
107+ runTest ( )
89108 }
90109} )
0 commit comments