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

Commit0133ab8

Browse files
committed
migrate git into tutorial model
1 parent957d05b commit0133ab8

File tree

11 files changed

+224
-203
lines changed

11 files changed

+224
-203
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ const getNonce = (): string => {
1212
}
1313

1414

15-
/**
16-
* Manages React webview panels
17-
*/
15+
// Manages webview panel
1816
classReactWebView{
1917
//@ts-ignore
2018
publicloaded:boolean
@@ -28,7 +26,7 @@ class ReactWebView {
2826
// Create and show a new webview panel
2927
this.panel=this.createWebviewPanel(vscode.ViewColumn.Two)
3028

31-
// Set the webview's initial html content
29+
// Set the webview initial html content
3230
this.panel.webview.html=this.getHtmlForWebview()
3331

3432
// Listen for when the panel is disposed
@@ -37,12 +35,21 @@ class ReactWebView {
3735

3836
// Handle messages from the webview
3937
constonReceive=(action:string|CR.Action)=>{
40-
// await loading of webview in React before proceeding with loaded state
41-
if(action==='WEBVIEW_LOADED'){
42-
this.loaded=true
43-
}else{
44-
console.log('onReceive',action)
45-
vscode.commands.executeCommand('coderoad.receive_action',action)
38+
constactionType:string=typeofaction==='string' ?action :action.type
39+
switch(actionType){
40+
case'WEBVIEW_LOADED':
41+
// await loading of webview in React before proceeding with loaded state
42+
this.loaded=true
43+
break
44+
case'TUTORIAL_START':
45+
console.log('TUTORIAL_START called')
46+
console.log(action)
47+
break
48+
// add other cases
49+
default:
50+
// send to state machine
51+
console.log('onReceive',action)
52+
vscode.commands.executeCommand('coderoad.receive_machine_action',action)
4653
}
4754
}
4855
this.panel.webview.onDidReceiveMessage(onReceive,null,this.disposables)
@@ -55,7 +62,7 @@ class ReactWebView {
5562
})
5663
}
5764

58-
// prevents new panels from goingontop of coderoad panel
65+
// prevents new panels from goingon top of coderoad panel
5966
vscode.window.onDidChangeActiveTextEditor((textEditor?:vscode.TextEditor)=>{
6067
console.log('onDidChangeActiveTextEditor')
6168
console.log(textEditor)
@@ -115,7 +122,7 @@ class ReactWebView {
115122
constconfig={
116123
// Enable javascript in the webview
117124
enableScripts:true,
118-
// Andrestric the webview to only loading content from our extension's `media` directory.
125+
// Andrestrict the webview to only loading content from our extension's `media` directory.
119126
localResourceRoots:[vscode.Uri.file(path.join(this.extensionPath,'build'))],
120127
// prevents destroying the window when it is in the background
121128
retainContextWhenHidden:true,

‎src/editor/commands/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const COMMANDS = {
1313
OPEN_WEBVIEW:'coderoad.open_webview',
1414
SEND_STATE:'coderoad.send_state',
1515
SEND_DATA:'coderoad.send_data',
16-
RECEIVE_ACTION:'coderoad.receive_action',
16+
RECEIVE_MACHINE_ACTION:'coderoad.receive_machine_action',
1717
OPEN_FILE:'coderoad.open_file',
1818
RUN_TEST:'coderoad.run_test',
1919
TEST_PASS:'coderoad.test_pass',
@@ -102,7 +102,7 @@ export const createCommands = ({vscodeExt, machine}: CreateCommandProps) => {
102102
constabsoluteFilePath=join(workspaceRoot,relativeFilePath)
103103
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
104104
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
105-
// there are times whenintialization leave the panel behind any files opened
105+
// there are times wheninitialization leave the panel behind any files opened
106106
// ensure the panel is redrawn on the right side first
107107
webview.createOrShow(vscode.ViewColumn.Two)
108108
}catch(error){
@@ -116,7 +116,7 @@ export const createCommands = ({vscodeExt, machine}: CreateCommandProps) => {
116116
[COMMANDS.SEND_DATA]:(payload:{data:any})=>{
117117
webview.postMessage({type:'SET_DATA', payload})
118118
},
119-
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
119+
[COMMANDS.RECEIVE_MACHINE_ACTION]:(action:string|CR.Action)=>{
120120
// send received actions from web-app into state machine
121121
console.log('receive action',action)
122122
machine.send(action)

‎src/editor/commands/runTest.ts

Lines changed: 123 additions & 123 deletions
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
import*asstoragefrom'../../services/storage'
44

55
// ensure only latest run_test action is taken
@@ -8,135 +8,135 @@ let currentId = 0
88
// quick solution to prevent processing multiple results
99
// NOTE: may be possible to kill child process early
1010
constshouldExitEarly=(processId:number):boolean=>{
11-
returncurrentId!==processId
11+
returncurrentId!==processId
1212
}
1313

14-
let_channel:vscode.OutputChannel
14+
letchannel:vscode.OutputChannel
1515

1616
constgetOutputChannel=(name:string):vscode.OutputChannel=>{
17-
if(!_channel){
18-
_channel=vscode.window.createOutputChannel(name)
19-
}
20-
return_channel
17+
if(!channel){
18+
channel=vscode.window.createOutputChannel(name)
19+
}
20+
returnchannel
2121
}
2222

2323
interfaceProps{
24-
onSuccess():void
25-
onFail():void
24+
onSuccess():void
25+
onFail():void
2626
}
2727

28-
exportdefaultasyncfunctionrunTest({onSuccess, onFail}:Props):Promise<void>{
29-
// increment process id
30-
letprocessId=++currentId
31-
32-
constoutputChannelName='Test Output'
33-
34-
// TODO: validate test directory from package.json exists
35-
// let testFile = path.join('test');
36-
// if (!await exists(testFile)) {
37-
// return emptyTasks;
38-
// }
39-
40-
// TODO: verify test runner for args
41-
consttestArgs=['--json']
42-
43-
// if .git repo, use --onlyChanged
44-
// const hasGit = path.join('.git');
45-
// if (await exists(hasGit)) {
46-
// testArgs.push('--onlyChanged')
47-
// }
48-
49-
letcommandLine=`npm test --${testArgs.join(' ')}`
50-
51-
try{
52-
// capture position early on test start
53-
// in case position changes
54-
const[position,{stdout}]=awaitPromise.all([storage.getPosition(),exec(commandLine)])
55-
if(shouldExitEarly(processId)){
56-
// exit early
57-
return
58-
}
59-
60-
if(stdout){
61-
letlines=stdout.split(/\r{0,1}\n/)
62-
console.log('SUCCESS LINES',lines)
63-
for(letlineoflines){
64-
if(line.length===0){
65-
continue
66-
}
67-
68-
constregExp=/^{\"numFailedTestSuites/
69-
constmatches=regExp.exec(line)
70-
if(matches&&matches.length){
71-
console.log('MATCHES SUCCESS')
72-
constresult=JSON.parse(line)
73-
74-
if(result.success){
75-
console.log('SUCCESS')
76-
if(shouldExitEarly(processId)){
77-
// exit early
78-
return
79-
}
80-
console.log('call onSuccess')
81-
onSuccess()
82-
}else{
83-
console.log('NOT SUCCESS?')
84-
}
85-
}
86-
}
87-
}
88-
}catch(err){
89-
if(shouldExitEarly(processId)){
90-
// exit early
91-
return
92-
}
93-
// error contains output & error message
94-
// output can be parsed as json
95-
const{stdout, stderr}=err
96-
console.log('TEST FAILED',stdout)
97-
98-
if(!stdout){
99-
console.error('SOMETHING WENT WRONG WITH A PASSING TEST')
100-
}
101-
// test runner failed
102-
constchannel=getOutputChannel(outputChannelName)
103-
104-
if(stdout){
105-
letlines=stdout.split(/\r{0,1}\n/)
106-
107-
for(letlineoflines){
108-
if(line.length===0){
109-
continue
110-
}
111-
112-
constdataRegExp=/^{\"numFailedTestSuites"/
113-
constmatches=dataRegExp.exec(line)
114-
115-
if(matches&&matches.length){
116-
constresult=JSON.parse(line)
117-
constfirstError=result.testResults.find((t:any)=>t.status==='failed')
118-
119-
if(firstError){
120-
if(shouldExitEarly(processId)){
121-
// exit early
122-
return
123-
}
124-
console.log('ERROR',firstError.message)
125-
console.log('call onFail')
126-
onFail()
127-
}else{
128-
console.error('NOTE: PARSER DID NOT WORK FOR ',line)
129-
}
130-
}
131-
}
132-
}
133-
134-
if(stderr){
135-
channel.show(false)
136-
channel.appendLine(stderr)
137-
}
138-
// if (err.stdout) {
139-
// channel.appendLine(err.stdout);
140-
// }
141-
}
28+
exportdefaultasyncfunctionrunTest({onSuccess, onFail}:Props):Promise<void>{
29+
// increment process id
30+
constprocessId=++currentId
31+
32+
constoutputChannelName='Test Output'
33+
34+
// TODO: validate test directory from package.json exists
35+
// let testFile = path.join('test');
36+
// if (!await exists(testFile)) {
37+
// return emptyTasks;
38+
// }
39+
40+
// TODO: verify test runner for args
41+
consttestArgs=['--json']
42+
43+
// if .git repo, use --onlyChanged
44+
// const hasGit = path.join('.git');
45+
// if (await exists(hasGit)) {
46+
// testArgs.push('--onlyChanged')
47+
// }
48+
49+
constcommandLine=`npm test --${testArgs.join(' ')}`
50+
51+
try{
52+
// capture position early on test start
53+
// in case position changes
54+
const[position,{stdout}]=awaitPromise.all([storage.getPosition(),exec(commandLine)])
55+
if(shouldExitEarly(processId)){
56+
// exit early
57+
return
58+
}
59+
60+
if(stdout){
61+
constlines=stdout.split(/\r{0,1}\n/)
62+
console.log('SUCCESS LINES',lines)
63+
for(constlineoflines){
64+
if(line.length===0){
65+
continue
66+
}
67+
68+
constregExp=/^{\"numFailedTestSuites/
69+
constmatches=regExp.exec(line)
70+
if(matches&&matches.length){
71+
console.log('MATCHES SUCCESS')
72+
constresult=JSON.parse(line)
73+
74+
if(result.success){
75+
console.log('SUCCESS')
76+
if(shouldExitEarly(processId)){
77+
// exit early
78+
return
79+
}
80+
console.log('call onSuccess')
81+
onSuccess()
82+
}else{
83+
console.log('NOT SUCCESS?')
84+
}
85+
}
86+
}
87+
}
88+
}catch(err){
89+
if(shouldExitEarly(processId)){
90+
// exit early
91+
return
92+
}
93+
// error contains output & error message
94+
// output can be parsed as json
95+
const{stdout, stderr}=err
96+
console.log('TEST FAILED',stdout)
97+
98+
if(!stdout){
99+
console.error('SOMETHING WENT WRONG WITH A PASSING TEST')
100+
}
101+
// test runner failed
102+
constchannel=getOutputChannel(outputChannelName)
103+
104+
if(stdout){
105+
constlines=stdout.split(/\r{0,1}\n/)
106+
107+
for(constlineoflines){
108+
if(line.length===0){
109+
continue
110+
}
111+
112+
constdataRegExp=/^{\"numFailedTestSuites"/
113+
constmatches=dataRegExp.exec(line)
114+
115+
if(matches&&matches.length){
116+
constresult=JSON.parse(line)
117+
constfirstError=result.testResults.find((t:any)=>t.status==='failed')
118+
119+
if(firstError){
120+
if(shouldExitEarly(processId)){
121+
// exit early
122+
return
123+
}
124+
console.log('ERROR',firstError.message)
125+
console.log('call onFail')
126+
onFail()
127+
}else{
128+
console.error('NOTE: PARSER DID NOT WORK FOR ',line)
129+
}
130+
}
131+
}
132+
}
133+
134+
if(stderr){
135+
channel.show(false)
136+
channel.appendLine(stderr)
137+
}
138+
// if (err.stdout) {
139+
// channel.appendLine(err.stdout);
140+
// }
141+
}
142142
}

‎src/services/git/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<void> => {
3939
SINGLE git cherry-pick %COMMIT%
4040
if fails, will stash all and retry
4141
*/
42-
exportasyncfunctiongitLoadCommits(actions:G.StepActions,editorDispatch:CR.EditorDispatch):Promise<void>{
42+
exportasyncfunctiongitLoadCommits(actions:G.StepActions,openFile:(file:string)=>void):Promise<void>{
4343
const{commits, commands, files}=actions
4444

4545
console.log(`load commits:${commits.join(', ')}`)
@@ -72,7 +72,7 @@ export async function gitLoadCommits(actions: G.StepActions, editorDispatch: CR.
7272

7373
if(files){
7474
for(constfilePathoffiles){
75-
editorDispatch('coderoad.open_file',filePath)
75+
openFile(filePath)
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp