@@ -4,16 +4,18 @@ import { setStorage } from '../storage'
4
4
import ReactWebView from '../ReactWebView'
5
5
import { isEmptyWorkspace } from '../workspace'
6
6
import * as CR from 'typings'
7
+ import runTest from './runTest'
7
8
8
9
const COMMANDS = {
9
10
START : 'coderoad.start' ,
10
11
TUTORIAL_LAUNCH : 'coderoad.tutorial_launch' ,
12
+ TUTORIAL_SETUP : 'coderoad.tutorial_setup' ,
11
13
OPEN_WEBVIEW : 'coderoad.open_webview' ,
12
14
SEND_STATE : 'coderoad.send_state' ,
13
15
SEND_DATA : 'coderoad.send_data' ,
14
16
RECEIVE_ACTION : 'coderoad.receive_action' ,
15
17
OPEN_FILE : 'coderoad.open_file' ,
16
- RUN_TEST : 'coderoad.test_run ' ,
18
+ RUN_TEST : 'coderoad.run_test ' ,
17
19
}
18
20
19
21
interface CreateCommandProps {
@@ -62,6 +64,19 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
62
64
const { setup } = steps [ pos . stepId ] . actions
63
65
await git . gitLoadCommits ( setup )
64
66
} ,
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
+ } ,
65
80
// open a file
66
81
[ COMMANDS . OPEN_FILE ] : async ( relativeFilePath : string ) => {
67
82
console . log ( `OPEN_FILE ${ JSON . stringify ( relativeFilePath ) } ` )
@@ -85,6 +100,10 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
85
100
webview . postMessage ( { type : 'SET_DATA' , payload } )
86
101
} ,
87
102
[ COMMANDS . RECEIVE_ACTION ] : ( action : string | CR . Action ) => {
103
+ // send received actions from web-app into state machine
88
104
machine . send ( action )
105
+ } ,
106
+ [ COMMANDS . RUN_TEST ] : ( ) => {
107
+ runTest ( )
89
108
}
90
109
} )
0 commit comments