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

Send setup actions even when no setup for position tracking#298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 1 commit intomasterfromfix/null-step-progress
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionssrc/actions/setupActions.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,9 @@ interface SetupActions {
}

exportconstsetupActions=async({ actions, send, path}:SetupActions):Promise<void>=>{
if(!actions){
return
}
const{ commands, commits, files, watchers}=actions

// validate commit is new
Expand Down
8 changes: 5 additions & 3 deletionssrc/actions/utils/loadWatchers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,9 +37,11 @@ const loadWatchers = (watchers: string[]) => {
fsWatcher.on('change',(path,event)=>{
constnow=+newDate()
if(!lastFire||lastFire-now>1000){
vscode.commands.executeCommand(COMMANDS.RUN_TEST,null,()=>{
// cleanup watcher on success
disposeWatcher(watcher)
vscode.commands.executeCommand(COMMANDS.RUN_TEST,{
onSuccess:()=>{
// cleanup watcher on success
disposeWatcher(watcher)
},
})
}
})
Expand Down
14 changes: 8 additions & 6 deletionssrc/channel/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -224,7 +224,7 @@ class Channel implements Channel {
alreadyConfigured: true,
})
// update the current stepId on startup
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
} catch (e) {
const error = {
type: 'UnknownError',
Expand DownExpand Up@@ -286,14 +286,15 @@ class Channel implements Channel {
return
// load step actions (git commits, commands, open files)
case 'SETUP_ACTIONS':
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
setupActions({ actions: action.payload, send: this.send })
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
setupActions({ actions: action.payload.actions, send: this.send })
return
// load solution step actions (git commits, commands, open files)
case 'SOLUTION_ACTIONS':
await solutionActions({ actions: action.payload, send: this.send })
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
await solutionActions({ actions: action.payload.actions, send: this.send })
// run test following solution to update position
vscode.commands.executeCommand(COMMANDS.RUN_TEST, action.payload)
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
return

default:
Expand DownExpand Up@@ -328,12 +329,13 @@ class Channel implements Channel {

switch (actionType) {
case 'TEST_PASS':
console.log('TEST_PASS', action)
const tutorial = this.context.tutorial.get()
if (!tutorial) {
throw new Error('Error with current tutorial. Tutorial may be missing an id.')
}
// update local storage stepProgress
const progress = this.context.progress.setStepComplete(tutorial, action.payload.stepId)
const progress = this.context.progress.setStepComplete(tutorial, action.payload.position.stepId)
this.context.position.setPositionFromProgress(tutorial, progress)
saveCommit()
}
Expand Down
42 changes: 25 additions & 17 deletionssrc/editor/commands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
import*asTfrom'typings'
import*asTTfrom'typings/tutorial'
import*asvscodefrom'vscode'
importcreateTestRunner,{Payload}from'../services/testRunner'
importcreateTestRunnerfrom'../services/testRunner'
import{setupActions}from'../actions/setupActions'
importcreateWebViewfrom'../webview'
importloggerfrom'../services/logger'

exportconstCOMMANDS={
START:'coderoad.start',
OPEN_WEBVIEW:'coderoad.open_webview',
CONFIG_TEST_RUNNER:'coderoad.config_test_runner',
RUN_TEST:'coderoad.run_test',
SET_CURRENT_STEP:'coderoad.set_current_step',
SET_CURRENT_POSITION:'coderoad.set_current_position',
}

interfaceCreateCommandProps{
Expand All@@ -20,7 +22,7 @@ interface CreateCommandProps {
exportconstcreateCommands=({ extensionPath, workspaceState}:CreateCommandProps)=>{
// React panel webview
letwebview:any
letcurrentStepId:string|null=''
letcurrentPosition:T.Position
lettestRunner:any

return{
Expand DownExpand Up@@ -55,32 +57,38 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
awaitsetupActions({actions:config.actions,send:webview.send,path:config.path})
}
testRunner=createTestRunner(config,{
onSuccess:(payload:Payload)=>{
onSuccess:(position:T.Position)=>{
logger('test pass position',position)
// send test pass message back to client
webview.send({type:'TEST_PASS', payload})
webview.send({type:'TEST_PASS',payload:{ position}})
},
onFail:(payload:Payload,message:string)=>{
onFail:(position:T.Position,message:string)=>{
// send test fail message back to client with failure message
webview.send({type:'TEST_FAIL',payload:{...payload, message}})
webview.send({type:'TEST_FAIL',payload:{position, message}})
},
onError:(payload:Payload)=>{
// send test error message back to client
webview.send({type:'TEST_ERROR', payload})
onError:(position:T.Position)=>{
// TODO: send test error message back to client
constmessage='Error with test runner'
webview.send({type:'TEST_ERROR',payload:{ position, message}})
},
onRun:(payload:Payload)=>{
onRun:(position:T.Position)=>{
// send test run message back to client
webview.send({type:'TEST_RUNNING', payload})
webview.send({type:'TEST_RUNNING',payload:{ position}})
},
})
},
[COMMANDS.SET_CURRENT_STEP]:({ stepId}:Payload)=>{
[COMMANDS.SET_CURRENT_POSITION]:(position:T.Position)=>{
// set from last setup stepAction
currentStepId=stepId
currentPosition=position
},
[COMMANDS.RUN_TEST]:(current:Payload|undefined,onSuccess:()=>void)=>{
[COMMANDS.RUN_TEST]:(callback?:{onSuccess:()=>void})=>{
logger('run test current',currentPosition)
// use stepId from client, or last set stepId
constpayload:Payload={stepId:current&&current.stepId?.length ?current.stepId :currentStepId}
testRunner(payload,onSuccess)
// const position: T.Position = {
// ...current,
// stepId: current && current.position.stepId?.length ? current.position.stepId : currentPosition.stepId,
// }
testRunner(currentPosition,callback?.onSuccess)
},
}
}
2 changes: 1 addition & 1 deletionsrc/services/logger/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import{LOG}from'../../environment'

exporttypeLog=string|object|null
exporttypeLog=string|object|null|undefined

constlogger=(...messages:Log[]):void=>{
if(!LOG){
Expand Down
32 changes: 15 additions & 17 deletionssrc/services/testRunner/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import{TutorialTestRunnerConfig}from'typings/tutorial'
import*asTfrom'typings'
import*asTTfrom'typings/tutorial'
import{exec}from'../node'
importloggerfrom'../logger'
importparserfrom'./parser'
Expand All@@ -7,22 +8,19 @@ import onError from '../sentry/onError'
import{clearOutput,displayOutput}from'./output'
import{formatFailOutput}from'./formatOutput'

exportinterfacePayload{
stepId:string|null
}

interfaceCallbacks{
onSuccess(payload:Payload):void
onFail(payload:Payload,message:string):void
onRun(payload:Payload):void
onError(payload:Payload):void
onSuccess(position:T.Position):void
onFail(position:T.Position,message:string):void
onRun(position:T.Position):void
onError(position:T.Position):void
}

constfailChannelName='CodeRoad (Tests)'
constlogChannelName='CodeRoad (Logs)'

constcreateTestRunner=(config:TutorialTestRunnerConfig,callbacks:Callbacks)=>{
returnasync(payload:Payload,onSuccess?:()=>void):Promise<void>=>{
constcreateTestRunner=(config:TT.TutorialTestRunnerConfig,callbacks:Callbacks)=>{
returnasync(position:T.Position,onSuccess?:()=>void):Promise<void>=>{
logger('createTestRunner',position)
conststartTime=throttle()
// throttle time early
if(!startTime){
Expand All@@ -32,7 +30,7 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
logger('------------------- RUN TEST -------------------')

// flag as running
callbacks.onRun(payload)
callbacks.onRun(position)

letresult:{stdout:string|undefined;stderr:string|undefined}
try{
Expand All@@ -59,12 +57,12 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
// FAIL also trigger stderr
if(stdout&&stdout.length&&!tap.ok){
constfirstFailMessage=tap.failed[0].message
callbacks.onFail(payload,firstFailMessage)
callbacks.onFail(position,firstFailMessage)
constoutput=formatFailOutput(tap)
displayOutput({channel:failChannelName,text:output,show:true})
return
}else{
callbacks.onError(payload)
callbacks.onError(position)
// open terminal with error string
displayOutput({channel:failChannelName,text:stderr,show:true})
return
Expand All@@ -74,14 +72,14 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
// PASS
if(tap.ok){
clearOutput(failChannelName)
callbacks.onSuccess(payload)
callbacks.onSuccess(position)
if(onSuccess){
onSuccess()
}
}else{
// should never get here
onError(newError(`Error with running test${JSON.stringify(payload)}`))
callbacks.onError(payload)
onError(newError(`Error with running test${JSON.stringify(position)}`))
callbacks.onError(position)
}
}
}
Expand Down
1 change: 1 addition & 0 deletionssrc/webview/render.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,7 @@ async function render(panel: vscode.WebviewPanel, rootPath: string) {
constcreateUri=(_filePath:string):any=>{
constfilePath=(_filePath.startsWith('vscode') ?_filePath.substr(16) :_filePath).replace('///','\\')

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

Expand Down
2 changes: 1 addition & 1 deletionweb-app/src/services/state/actions/context.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
// update progress by tracking completed
constcurrentProgress:T.Progress=context.progress

const{ stepId}=event.payload
const{ stepId}=event.payload.position

currentProgress.steps[stepId]=true

Expand Down
36 changes: 24 additions & 12 deletionsweb-app/src/services/state/actions/editor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,19 +22,24 @@ export default (editorSend: any) => ({
type:'EDITOR_TUTORIAL_CONTINUE_CONFIG',
payload:{
// pass position because current stepId or first stepId will be empty
stepId:context.position.stepId,
position:context.position,
},
})
},
loadLevel(context:CR.MachineContext):void{
constlevel:TT.Level=selectors.currentLevel(context)
if(level.setup){
// load step actions
editorSend({
type:'SETUP_ACTIONS',
payload:level.setup,
})
}
conststep:TT.Step|null=selectors.currentStep(context)
// load step actions
editorSend({
type:'SETUP_ACTIONS',
payload:{
position:{
stepId:step?.id||null,
levelId:level.id,
},
actions:level.setup,
},
})
},
loadStep(context:CR.MachineContext):void{
conststep:TT.Step|null=selectors.currentStep(context)
Expand All@@ -43,8 +48,12 @@ export default (editorSend: any) => ({
editorSend({
type:'SETUP_ACTIONS',
payload:{
stepId:step.id,
...step.setup,
// set position here
position:{
stepId:step.id,
levelId:context.position.levelId,
},
actions:step.setup,
},
})
}
Expand All@@ -56,8 +65,11 @@ export default (editorSend: any) => ({
editorSend({
type:'SOLUTION_ACTIONS',
payload:{
stepId:step.id,
...step.solution,
position:{
stepId:step.id,
levelId:context.position.levelId,
},
actions:step.solution,
},
})
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp