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

Commitd7b7ed3

Browse files
committed
setup tutorialConfig
1 parentcfbf955 commitd7b7ed3

File tree

15 files changed

+224
-219
lines changed

15 files changed

+224
-219
lines changed

‎src/editor/Channel.tsrenamed to‎src/Channel.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import*asCRfrom'typings'
22
import*asvscodefrom'vscode'
33

4+
importtutorialConfigfrom'./actions/tutorialConfig'
5+
importsetupActionsfrom'./actions/setupActions'
6+
importsolutionActionsfrom'./actions/solutionActions'
7+
48
interfaceChannel{
59
receive(action:CR.Action):void
6-
send(action:CR.Action):void
10+
send(action:CR.Action):Promise<void>
711
}
812

913
classChannelimplementsChannel{
@@ -13,23 +17,29 @@ class Channel implements Channel {
1317
}
1418

1519
// receive from webview
16-
publicreceive(action:CR.Action){
20+
publicreceive=(action:CR.Action)=>{
1721
constactionType:string=typeofaction==='string' ?action :action.type
18-
console.log('RECEIVED',actionType)
22+
console.log('RECEIVED:',actionType)
1923
switch(actionType){
2024
case'TEST_RUN':
25+
vscode.commands.executeCommand('coderoad.run_test')
2126
return
2227
case'TUTORIAL_CONFIG':
28+
tutorialConfig(action.payload)
29+
return
30+
case'SETUP_ACTIONS':
31+
setupActions(action.payload)
2332
return
24-
case'STEP_ACTIONS':
33+
case'SOLUTION_ACTIONS':
34+
solutionActions(action.payload)
2535
return
26-
// add other cases
2736
default:
37+
console.log(`No match for action type:${actionType}`)
2838
return
2939
}
3040
}
3141
// send to webview
32-
publicasyncsend(action:CR.Action){
42+
publicsend=async(action:CR.Action)=>{
3343
constsuccess=awaitthis.postMessage(action)
3444
if(!success){
3545
thrownewError(`Message post failure:${JSON.stringify(action)}`)

‎src/editor/commands/runTest.tsrenamed to‎src/actions/runTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asvscodefrom'vscode'
2-
import{exec}from'../../services/node'
2+
import{exec}from'../services/node'
33

44
// ensure only latest run_test action is taken
55
letcurrentId=0

‎src/actions/setupActions.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import*asGfrom'typings/graphql'
2+
import{join}from'path'
3+
import*asvscodefrom'vscode'
4+
import*asgitfrom'../services/git'
5+
import{exec}from'../services/node'
6+
7+
interfaceErrorMessageFilter{
8+
[lang:string]:{
9+
[key:string]:string
10+
}
11+
}
12+
13+
// TODO: should be loaded on startup based on language
14+
consterrorMessageFilter:ErrorMessageFilter={
15+
js:{
16+
'node-gyp':'Error running npm setup command'
17+
}
18+
}
19+
20+
constsetupActions=async({commands, commits, files}:G.StepActions):Promise<void>=>{
21+
// run commits
22+
for(constcommitofcommits){
23+
awaitgit.loadCommit(commit)
24+
}
25+
26+
// run command
27+
for(constcommandofcommands){
28+
const{stdout, stderr}=awaitexec(command)
29+
if(stderr){
30+
console.error(stderr)
31+
// language specific error messages from running commands
32+
for(constmessageofObject.keys(errorMessageFilter.js)){
33+
if(stderr.match(message)){
34+
// ignored error
35+
thrownewError('Error running setup command')
36+
}
37+
}
38+
}
39+
console.log(`run command:${command}`,stdout)
40+
}
41+
42+
// open files
43+
for(constfilePathoffiles){
44+
console.log(`OPEN_FILE${filePath}`)
45+
try{
46+
// TODO: re-enable after testing
47+
// const workspaceRoots: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders
48+
// if (!workspaceRoots || !workspaceRoots.length) {
49+
// throw new Error('No workspace root path')
50+
// }
51+
// const rootWorkspace: vscode.WorkspaceFolder = workspaceRoots[0]
52+
// const absoluteFilePath = join(rootWorkspace.uri.path, relativeFilePath)
53+
constworkspaceRoot=vscode.workspace.rootPath
54+
if(!workspaceRoot){
55+
thrownewError('No workspace root path')
56+
}
57+
constabsoluteFilePath=join(workspaceRoot,filePath)
58+
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
59+
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
60+
// there are times when initialization leave the panel behind any files opened
61+
// ensure the panel is redrawn on the right side first
62+
// webview.createOrShow(vscode.ViewColumn.Two)
63+
}catch(error){
64+
console.log(`Failed to open file${filePath}`,error)
65+
}
66+
}
67+
}
68+
69+
exportdefaultsetupActions

‎src/actions/solutionActions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// import * as CR from 'typings'
2+
import*asGfrom'typings/graphql'
3+
// import {TutorialModel} from '../services/tutorial'
4+
// import {gitLoadCommits, gitClear} from '../services/git'
5+
6+
constsolutionActions=async(stepActions:G.StepActions):Promise<void>=>{
7+
// TODO: should load same as commits
8+
9+
// const step: G.Step = tutorialModel.step()
10+
// const solution = step.solution
11+
12+
// await gitClear()
13+
// await gitLoadCommits(solution, dispatch)
14+
15+
}
16+
17+
exportdefaultsolutionActions

‎src/actions/tutorialConfig.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import*asGfrom'typings/graphql'
2+
import*asvscodefrom'vscode'
3+
import*asgitfrom'../services/git'
4+
5+
consttutorialConfig=async(tutorial:G.Tutorial)=>{
6+
7+
// setup git, add remote
8+
awaitgit.initIfNotExists()
9+
awaitgit.setupRemote(tutorial.repo.uri)
10+
11+
// TODO: allow multiple coding languages in a tutorial
12+
13+
// setup onSave hook
14+
// console.log(`languageIds: ${languageIds.join(', ')}`)
15+
vscode.workspace.onDidSaveTextDocument((document:vscode.TextDocument)=>{
16+
if(document.uri.scheme==='file'&&tutorial.codingLanguage===document.languageId){
17+
// do work
18+
// TODO: resolve issue if client unaware or out of sync with running test
19+
vscode.commands.executeCommand('coderoad.run_test')
20+
}
21+
})
22+
}
23+
24+
exportdefaulttutorialConfig

‎src/editor/ReactWebView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*aspathfrom'path'
22
import*asvscodefrom'vscode'
3-
importChannel,*aschannelfrom'./channel'
3+
importChannelfrom'../Channel'
44

55
constgetNonce=():string=>{
66
lettext=''
@@ -33,7 +33,7 @@ class ReactWebView {
3333
this.panel.webview.html=this.getHtmlForWebview()
3434

3535
// Listen for when the panel is disposed
36-
// This happens when the user closes the panel or when the panel is closedprogramatically
36+
// This happens when the user closes the panel or when the panel is closedprogrammatically
3737
this.panel.onDidDispose(this.dispose,this,this.disposables)
3838

3939
this.channel=newChannel(this.panel.webview)

‎src/editor/commands.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import*asvscodefrom'vscode'
2+
importReactWebViewfrom'./ReactWebView'
3+
importrunTestfrom'../actions/runTest'
4+
import{isEmptyWorkspace}from'./workspace'
5+
6+
constCOMMANDS={
7+
START:'coderoad.start',
8+
OPEN_WEBVIEW:'coderoad.open_webview',
9+
RUN_TEST:'coderoad.run_test',
10+
}
11+
12+
interfaceCreateCommandProps{
13+
vscodeExt:vscode.ExtensionContext
14+
}
15+
16+
constresetLayout=()=>{
17+
vscode.commands.executeCommand('vscode.setEditorLayout',{
18+
orientation:0,
19+
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
20+
})
21+
}
22+
23+
exportconstcreateCommands=({vscodeExt}:CreateCommandProps)=>{
24+
// React panel webview
25+
letwebview:any
26+
27+
return{
28+
// initialize
29+
[COMMANDS.START]:async()=>{
30+
console.log('start')
31+
32+
// TODO: replace with a prompt to open a workspace
33+
awaitisEmptyWorkspace()
34+
35+
letwebviewState:'INITIALIZING'|'RESTARTING'
36+
if(!webview){
37+
webviewState='INITIALIZING'
38+
}elseif(webview.loaded){
39+
// already loaded
40+
vscode.window.showInformationMessage('CodeRoad already open')
41+
return
42+
}else{
43+
webviewState='RESTARTING'
44+
}
45+
46+
// activate machine
47+
webview=newReactWebView(vscodeExt.extensionPath)
48+
},
49+
// open React webview
50+
[COMMANDS.OPEN_WEBVIEW]:(column:number=vscode.ViewColumn.Two)=>{
51+
console.log('open webview')
52+
// setup 1x1 horizontal layout
53+
resetLayout()
54+
webview.createOrShow(column)
55+
},
56+
[COMMANDS.RUN_TEST]:()=>{
57+
runTest({
58+
onSuccess:()=>{
59+
console.log('TEST_PASS')
60+
vscode.window.showInformationMessage('PASS')
61+
},
62+
onFail:()=>{
63+
console.log('TEST_FAIL')
64+
vscode.window.showWarningMessage('FAIL')
65+
}
66+
})
67+
},
68+
}
69+
}

‎src/editor/commands/index.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.

‎src/editor/commands/loadSolution.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp