Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38a474f

Browse files
authored
Merge pull requestcoderoad#298 from coderoad/fix/null-step-progress
Send setup actions even when no setup for position tracking
2 parents7a56f9e +e5f140f commit38a474f

File tree

9 files changed

+83
-57
lines changed

9 files changed

+83
-57
lines changed

‎src/actions/setupActions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ interface SetupActions {
1414
}
1515

1616
exportconstsetupActions=async({ actions, send, path}:SetupActions):Promise<void>=>{
17+
if(!actions){
18+
return
19+
}
1720
const{ commands, commits, files, watchers}=actions
1821

1922
// validate commit is new

‎src/actions/utils/loadWatchers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const loadWatchers = (watchers: string[]) => {
3737
fsWatcher.on('change',(path,event)=>{
3838
constnow=+newDate()
3939
if(!lastFire||lastFire-now>1000){
40-
vscode.commands.executeCommand(COMMANDS.RUN_TEST,null,()=>{
41-
// cleanup watcher on success
42-
disposeWatcher(watcher)
40+
vscode.commands.executeCommand(COMMANDS.RUN_TEST,{
41+
onSuccess:()=>{
42+
// cleanup watcher on success
43+
disposeWatcher(watcher)
44+
},
4345
})
4446
}
4547
})

‎src/channel/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Channel implements Channel {
224224
alreadyConfigured:true,
225225
})
226226
// update the current stepId on startup
227-
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP,action.payload)
227+
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION,action.payload.position)
228228
}catch(e){
229229
consterror={
230230
type:'UnknownError',
@@ -286,14 +286,15 @@ class Channel implements Channel {
286286
return
287287
// load step actions (git commits, commands, open files)
288288
case'SETUP_ACTIONS':
289-
awaitvscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP,action.payload)
290-
setupActions({actions:action.payload,send:this.send})
289+
awaitvscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION,action.payload.position)
290+
setupActions({actions:action.payload.actions,send:this.send})
291291
return
292292
// load solution step actions (git commits, commands, open files)
293293
case'SOLUTION_ACTIONS':
294-
awaitsolutionActions({actions:action.payload,send:this.send})
294+
awaitvscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION,action.payload.position)
295+
awaitsolutionActions({actions:action.payload.actions,send:this.send})
295296
// run test following solution to update position
296-
vscode.commands.executeCommand(COMMANDS.RUN_TEST,action.payload)
297+
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
297298
return
298299

299300
default:
@@ -328,12 +329,13 @@ class Channel implements Channel {
328329

329330
switch(actionType){
330331
case'TEST_PASS':
332+
console.log('TEST_PASS',action)
331333
consttutorial=this.context.tutorial.get()
332334
if(!tutorial){
333335
thrownewError('Error with current tutorial. Tutorial may be missing an id.')
334336
}
335337
// update local storage stepProgress
336-
constprogress=this.context.progress.setStepComplete(tutorial,action.payload.stepId)
338+
constprogress=this.context.progress.setStepComplete(tutorial,action.payload.position.stepId)
337339
this.context.position.setPositionFromProgress(tutorial,progress)
338340
saveCommit()
339341
}

‎src/editor/commands.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import*asTfrom'typings'
12
import*asTTfrom'typings/tutorial'
23
import*asvscodefrom'vscode'
3-
importcreateTestRunner,{Payload}from'../services/testRunner'
4+
importcreateTestRunnerfrom'../services/testRunner'
45
import{setupActions}from'../actions/setupActions'
56
importcreateWebViewfrom'../webview'
7+
importloggerfrom'../services/logger'
68

79
exportconstCOMMANDS={
810
START:'coderoad.start',
911
OPEN_WEBVIEW:'coderoad.open_webview',
1012
CONFIG_TEST_RUNNER:'coderoad.config_test_runner',
1113
RUN_TEST:'coderoad.run_test',
12-
SET_CURRENT_STEP:'coderoad.set_current_step',
14+
SET_CURRENT_POSITION:'coderoad.set_current_position',
1315
}
1416

1517
interfaceCreateCommandProps{
@@ -20,7 +22,7 @@ interface CreateCommandProps {
2022
exportconstcreateCommands=({ extensionPath, workspaceState}:CreateCommandProps)=>{
2123
// React panel webview
2224
letwebview:any
23-
letcurrentStepId:string|null=''
25+
letcurrentPosition:T.Position
2426
lettestRunner:any
2527

2628
return{
@@ -55,32 +57,38 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
5557
awaitsetupActions({actions:config.actions,send:webview.send,path:config.path})
5658
}
5759
testRunner=createTestRunner(config,{
58-
onSuccess:(payload:Payload)=>{
60+
onSuccess:(position:T.Position)=>{
61+
logger('test pass position',position)
5962
// send test pass message back to client
60-
webview.send({type:'TEST_PASS', payload})
63+
webview.send({type:'TEST_PASS',payload:{ position}})
6164
},
62-
onFail:(payload:Payload,message:string)=>{
65+
onFail:(position:T.Position,message:string)=>{
6366
// send test fail message back to client with failure message
64-
webview.send({type:'TEST_FAIL',payload:{...payload, message}})
67+
webview.send({type:'TEST_FAIL',payload:{position, message}})
6568
},
66-
onError:(payload:Payload)=>{
67-
// send test error message back to client
68-
webview.send({type:'TEST_ERROR', payload})
69+
onError:(position:T.Position)=>{
70+
// TODO: send test error message back to client
71+
constmessage='Error with test runner'
72+
webview.send({type:'TEST_ERROR',payload:{ position, message}})
6973
},
70-
onRun:(payload:Payload)=>{
74+
onRun:(position:T.Position)=>{
7175
// send test run message back to client
72-
webview.send({type:'TEST_RUNNING', payload})
76+
webview.send({type:'TEST_RUNNING',payload:{ position}})
7377
},
7478
})
7579
},
76-
[COMMANDS.SET_CURRENT_STEP]:({ stepId}:Payload)=>{
80+
[COMMANDS.SET_CURRENT_POSITION]:(position:T.Position)=>{
7781
// set from last setup stepAction
78-
currentStepId=stepId
82+
currentPosition=position
7983
},
80-
[COMMANDS.RUN_TEST]:(current:Payload|undefined,onSuccess:()=>void)=>{
84+
[COMMANDS.RUN_TEST]:(callback?:{onSuccess:()=>void})=>{
85+
logger('run test current',currentPosition)
8186
// use stepId from client, or last set stepId
82-
constpayload:Payload={stepId:current&&current.stepId?.length ?current.stepId :currentStepId}
83-
testRunner(payload,onSuccess)
87+
// const position: T.Position = {
88+
// ...current,
89+
// stepId: current && current.position.stepId?.length ? current.position.stepId : currentPosition.stepId,
90+
// }
91+
testRunner(currentPosition,callback?.onSuccess)
8492
},
8593
}
8694
}

‎src/services/logger/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{LOG}from'../../environment'
22

3-
exporttypeLog=string|object|null
3+
exporttypeLog=string|object|null|undefined
44

55
constlogger=(...messages:Log[]):void=>{
66
if(!LOG){

‎src/services/testRunner/index.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import{TutorialTestRunnerConfig}from'typings/tutorial'
1+
import*asTfrom'typings'
2+
import*asTTfrom'typings/tutorial'
23
import{exec}from'../node'
34
importloggerfrom'../logger'
45
importparserfrom'./parser'
@@ -7,22 +8,19 @@ import onError from '../sentry/onError'
78
import{clearOutput,displayOutput}from'./output'
89
import{formatFailOutput}from'./formatOutput'
910

10-
exportinterfacePayload{
11-
stepId:string|null
12-
}
13-
1411
interfaceCallbacks{
15-
onSuccess(payload:Payload):void
16-
onFail(payload:Payload,message:string):void
17-
onRun(payload:Payload):void
18-
onError(payload:Payload):void
12+
onSuccess(position:T.Position):void
13+
onFail(position:T.Position,message:string):void
14+
onRun(position:T.Position):void
15+
onError(position:T.Position):void
1916
}
2017

2118
constfailChannelName='CodeRoad (Tests)'
2219
constlogChannelName='CodeRoad (Logs)'
2320

24-
constcreateTestRunner=(config:TutorialTestRunnerConfig,callbacks:Callbacks)=>{
25-
returnasync(payload:Payload,onSuccess?:()=>void):Promise<void>=>{
21+
constcreateTestRunner=(config:TT.TutorialTestRunnerConfig,callbacks:Callbacks)=>{
22+
returnasync(position:T.Position,onSuccess?:()=>void):Promise<void>=>{
23+
logger('createTestRunner',position)
2624
conststartTime=throttle()
2725
// throttle time early
2826
if(!startTime){
@@ -32,7 +30,7 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
3230
logger('------------------- RUN TEST -------------------')
3331

3432
// flag as running
35-
callbacks.onRun(payload)
33+
callbacks.onRun(position)
3634

3735
letresult:{stdout:string|undefined;stderr:string|undefined}
3836
try{
@@ -59,12 +57,12 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
5957
// FAIL also trigger stderr
6058
if(stdout&&stdout.length&&!tap.ok){
6159
constfirstFailMessage=tap.failed[0].message
62-
callbacks.onFail(payload,firstFailMessage)
60+
callbacks.onFail(position,firstFailMessage)
6361
constoutput=formatFailOutput(tap)
6462
displayOutput({channel:failChannelName,text:output,show:true})
6563
return
6664
}else{
67-
callbacks.onError(payload)
65+
callbacks.onError(position)
6866
// open terminal with error string
6967
displayOutput({channel:failChannelName,text:stderr,show:true})
7068
return
@@ -74,14 +72,14 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
7472
// PASS
7573
if(tap.ok){
7674
clearOutput(failChannelName)
77-
callbacks.onSuccess(payload)
75+
callbacks.onSuccess(position)
7876
if(onSuccess){
7977
onSuccess()
8078
}
8179
}else{
8280
// should never get here
83-
onError(newError(`Error with running test${JSON.stringify(payload)}`))
84-
callbacks.onError(payload)
81+
onError(newError(`Error with running test${JSON.stringify(position)}`))
82+
callbacks.onError(position)
8583
}
8684
}
8785
}

‎src/webview/render.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ async function render(panel: vscode.WebviewPanel, rootPath: string) {
3131
constcreateUri=(_filePath:string):any=>{
3232
constfilePath=(_filePath.startsWith('vscode') ?_filePath.substr(16) :_filePath).replace('///','\\')
3333

34+
//@ts-ignore
3435
returnpanel.webview.asWebviewUri(vscode.Uri.file(path.join(rootPath,filePath)))
3536
}
3637

‎web-app/src/services/state/actions/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
109109
// update progress by tracking completed
110110
constcurrentProgress:T.Progress=context.progress
111111

112-
const{ stepId}=event.payload
112+
const{ stepId}=event.payload.position
113113

114114
currentProgress.steps[stepId]=true
115115

‎web-app/src/services/state/actions/editor.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@ export default (editorSend: any) => ({
2222
type:'EDITOR_TUTORIAL_CONTINUE_CONFIG',
2323
payload:{
2424
// pass position because current stepId or first stepId will be empty
25-
stepId:context.position.stepId,
25+
position:context.position,
2626
},
2727
})
2828
},
2929
loadLevel(context:CR.MachineContext):void{
3030
constlevel:TT.Level=selectors.currentLevel(context)
31-
if(level.setup){
32-
// load step actions
33-
editorSend({
34-
type:'SETUP_ACTIONS',
35-
payload:level.setup,
36-
})
37-
}
31+
conststep:TT.Step|null=selectors.currentStep(context)
32+
// load step actions
33+
editorSend({
34+
type:'SETUP_ACTIONS',
35+
payload:{
36+
position:{
37+
stepId:step?.id||null,
38+
levelId:level.id,
39+
},
40+
actions:level.setup,
41+
},
42+
})
3843
},
3944
loadStep(context:CR.MachineContext):void{
4045
conststep:TT.Step|null=selectors.currentStep(context)
@@ -43,8 +48,12 @@ export default (editorSend: any) => ({
4348
editorSend({
4449
type:'SETUP_ACTIONS',
4550
payload:{
46-
stepId:step.id,
47-
...step.setup,
51+
// set position here
52+
position:{
53+
stepId:step.id,
54+
levelId:context.position.levelId,
55+
},
56+
actions:step.setup,
4857
},
4958
})
5059
}
@@ -56,8 +65,11 @@ export default (editorSend: any) => ({
5665
editorSend({
5766
type:'SOLUTION_ACTIONS',
5867
payload:{
59-
stepId:step.id,
60-
...step.solution,
68+
position:{
69+
stepId:step.id,
70+
levelId:context.position.levelId,
71+
},
72+
actions:step.solution,
6173
},
6274
})
6375
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp