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

Commit6d8b993

Browse files
committed
further editor refactoring
1 parent3261c33 commit6d8b993

File tree

8 files changed

+71
-104
lines changed

8 files changed

+71
-104
lines changed

‎src/editor/commands/index.ts

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
// import * as vscode from 'vscode'
2-
// import start from './start'
3-
// // import ReactPanel from '../views/createWebview'
1+
import*asvscodefrom'vscode'
2+
import{join}from'path'
3+
import{setStorage}from'../storage'
4+
importReactWebViewfrom'../ReactWebView'
5+
import*asCRfrom'../../typings'
46

5-
// import runTest from './runTest'
6-
// // import loadSolution from './loadSolution'
7-
// // import quit from './quit'
7+
constCOMMANDS={
8+
START:'coderoad.start',
9+
OPEN_WEBVIEW:'coderoad.open_webview',
10+
OPEN_FILE:'coderoad.open_file',
11+
RUN_TEST:'coderoad.test_run',
12+
}
813

9-
// const COMMANDS = {
10-
// // TUTORIAL_SETUP: 'coderoad.tutorial_setup',
11-
// START: 'coderoad.start',
12-
// OPEN_WEBVIEW: 'coderoad.open_webview',
13-
// RUN_TEST: 'coderoad.test_run',
14-
// // LOAD_SOLUTION: 'coderoad.solution_load',
15-
// // QUIT: 'coderoad.quit',
16-
// }
14+
interfaceCreateCommandProps{
15+
context:vscode.ExtensionContext,
16+
machine:CR.StateMachine
17+
}
1718

19+
// React panel webview
20+
letwebview:any;
1821

19-
// export default (context: vscode.ExtensionContext): void => {
20-
// const commands = {
21-
// [COMMANDS.START]: () => {
22-
// start(context)
23-
// },
24-
// [COMMANDS.OPEN_WEBVIEW]: () => {
25-
// // ReactPanel.createOrShow(context.extensionPath);
26-
// },
27-
// [COMMANDS.RUN_TEST]: () => {
28-
// runTest()
29-
// },
30-
// // [COMMANDS.LOAD_SOLUTION]: loadSolution,
31-
// // [COMMANDS.QUIT]: () => quit(context.subscriptions),
32-
// }
22+
exportconstcreateCommands=({ context, machine}:CreateCommandProps)=>({
23+
[COMMANDS.START]:()=>{
24+
// set local storage workspace
25+
setStorage(context.workspaceState)
3326

34-
// for (const cmd in commands) {
35-
// const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd])
36-
// context.subscriptions.push(command)
37-
// }
38-
// }
27+
// activate machine
28+
webview=newReactWebView(context.extensionPath,machine.onReceive)
29+
machine.activate()
30+
},
31+
[COMMANDS.OPEN_WEBVIEW]:()=>{
32+
webview.createOrShow();
33+
},
34+
[COMMANDS.OPEN_FILE]:async(relativeFilePath:string)=>{
35+
try{
36+
constworkspaceRoot=vscode.workspace.rootPath
37+
if(!workspaceRoot){
38+
thrownewError('No workspace root path')
39+
}
40+
constabsoluteFilePath=join(workspaceRoot,relativeFilePath)
41+
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
42+
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
43+
}catch(error){
44+
console.log(`Failed to open file${relativeFilePath}`,error)
45+
}
46+
}
47+
})

‎src/editor/commands/quit.ts

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

‎src/editor/index.ts

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,35 @@
11
import*asvscodefrom'vscode'
22
import*asCRfrom'../typings'
3-
import{setStorage}from'./storage'
4-
importReactWebViewfrom'./ReactWebView'
3+
import{createCommands}from'./commands'
4+
5+
interfaceProps{
6+
machine:CR.StateMachine,
7+
setWorkspaceRoot(rootPath:string):void
8+
}
59

610
classEditor{
711
// extension context set on activation
812
//@ts-ignore
913
privatecontext:vscode.ExtensionContext
10-
privateworkspaceRoot:string|undefined
1114
privatemachine:CR.StateMachine
12-
privatewebview:any
1315

14-
privateCOMMANDS={
15-
START:'coderoad.start',
16-
OPEN_WEBVIEW:'coderoad.open_webview',
17-
RUN_TEST:'coderoad.test_run',
18-
}
19-
20-
constructor(machine:CR.StateMachine){
16+
constructor({ machine, setWorkspaceRoot}:Props){
2117
this.machine=machine
22-
}
2318

24-
privatecommandStart=():void=>{
25-
// set workspaceroot
26-
const{ rootPath}=vscode.workspace
19+
// set workspace root for node executions
20+
const{ workspace}=vscode
21+
const{ rootPath}=workspace
2722
if(!rootPath){
2823
thrownewError('Requires a workspace. Please open a folder')
2924
}
30-
this.workspaceRoot=rootPath
31-
32-
// set local storage workspace
33-
setStorage(this.context.workspaceState)
34-
35-
// activate machine
36-
this.webview=newReactWebView(this.context.extensionPath,this.machine.onReceive)
37-
this.machine.activate()
38-
39-
console.log('command start webview')
40-
console.log(this.webview)
25+
setWorkspaceRoot(rootPath)
4126
}
4227

4328
privateactivateCommands=():void=>{
44-
console.log('this.COMMANDS',this.COMMANDS)
45-
constcommands={
46-
[this.COMMANDS.START]:()=>{
47-
console.log('start')
48-
this.commandStart()
49-
},
50-
[this.COMMANDS.OPEN_WEBVIEW]:()=>{
51-
console.log('open webview')
52-
console.log(this.webview)
53-
this.webview.createOrShow();
54-
},
55-
}
29+
constcommands=createCommands({
30+
context:this.context,
31+
machine:this.machine,
32+
})
5633
for(constcmdincommands){
5734
constcommand:vscode.Disposable=vscode.commands.registerCommand(cmd,commands[cmd])
5835
this.context.subscriptions.push(command)

‎src/extension.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import{setWorkspaceRoot}from'./services/node'
12
importStateMachinefrom'./state'
23
importEditorfrom'./editor'
34

45
// state machine that governs application logic
5-
constMachine=newStateMachine()
6-
// vscode editor
7-
constVSCodeEditor=newEditor(Machine)
6+
exportconstmachine=newStateMachine()
87

9-
exportconstactivate=VSCodeEditor.activate
10-
exportconstdeactivate=VSCodeEditor.deactivate
8+
// vscode editor
9+
exportconsteditor=newEditor({
10+
machine,
11+
setWorkspaceRoot,
12+
})
1113

14+
exportconstactivate=editor.activate
15+
exportconstdeactivate=editor.deactivate

‎src/services/git/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import*asvscodefrom'vscode'
12
import*asCRfrom'typings'
2-
import{exec,exists,openFile}from'../node'
3+
import{exec,exists}from'../node'
34

45
constgitOrigin='coderoad'
56

@@ -40,7 +41,7 @@ export async function gitLoadCommits(actions: CR.TutorialAction): Promise<void>
4041

4142
if(files){
4243
for(constfilePathoffiles){
43-
openFile(filePath)
44+
vscode.commands.executeCommand('coderoad.open_webview',filePath)
4445
}
4546
}
4647
}

‎src/services/node/index.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import{workspace}from'vscode'
21
import*asfsfrom'fs'
3-
import*asvscodefrom'vscode'
42
import{join}from'path'
53
import{execascpExec}from'child_process'
64
import{promisify}from'util'
@@ -11,11 +9,7 @@ let workspaceRoot: string
119

1210
// set workspace root
1311
// other function will use this to target the correct cwd
14-
exportasyncfunctionsetWorkspaceRoot():Promise<void>{
15-
const{ rootPath}=workspace
16-
if(!rootPath){
17-
thrownewError('Requires a workspace. Please open a folder')
18-
}
12+
exportfunctionsetWorkspaceRoot(rootPath:string):void{
1913
workspaceRoot=rootPath
2014
}
2115

@@ -28,17 +22,6 @@ export const exec = (cmd: string): Promise<{ stdout: string; stderr: string }> =
2822
// collect all paths together
2923
exportconstexists=(...paths:string[]):boolean=>fs.existsSync(join(workspaceRoot, ...paths))
3024

31-
exportconstopenFile=async(relativeFilePath:string):Promise<void>=>{
32-
try{
33-
constabsoluteFilePath=join(workspaceRoot,relativeFilePath)
34-
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
35-
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
36-
}catch(error){
37-
console.log(`Failed to open file${relativeFilePath}`,error)
38-
}
39-
}
40-
41-
4225
// export async function clear(): Promise<void> {
4326
// // remove all files including ignored
4427
// // NOTE: Linux only

‎src/services/testResult.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as CR from 'typings'
22
import*asvscodefrom'vscode'
33
import*asstoragefrom'./storage'
44

5-
65
exportasyncfunctiononSuccess(position:CR.Position){
76
console.log('onSuccess',position)
87
vscode.window.showInformationMessage('SUCCESS')

‎src/state/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ class StateMachine {
1717
this.service=interpret(machine,this.machineOptions)
1818
// logging
1919
.onTransition(state=>{
20-
console.log('state',state)
2120
if(state.changed){
22-
console.log('transition')
21+
console.log('next state')
2322
console.log(state.value)
2423
}
2524
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp