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

Fix/issues#19

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 7 commits intomasterfromfix/issues
Jul 21, 2019
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
17 changes: 7 additions & 10 deletionssrc/editor/ReactWebView.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class ReactWebView {

// Listen for when the panel is disposed
// This happens when the user closes the panel or when the panel is closed programatically
this.panel.onDidDispose(() =>this.dispose(), null, this.disposables)
this.panel.onDidDispose(this.dispose, this, this.disposables)

// Handle messages from the webview
const onReceive = (action: string | CR.Action) => {
Expand DownExpand Up@@ -75,6 +75,7 @@ class ReactWebView {
// unfortunately there is no easy way of doing this
const webPanelListener = setInterval(() => {
if (this.loaded) {
// callback tells editor the webview has loaded
setTimeout(callback)
clearInterval(webPanelListener)
}
Expand All@@ -91,16 +92,11 @@ class ReactWebView {
}
}

publicdispose(): void {
private asyncdispose():Promise<void> {
// Clean up our resources
this.loaded = false
this.panel.dispose()

while (this.disposables.length) {
const x = this.disposables.pop()
if (x) {
x.dispose()
}
}
Promise.all(this.disposables.map((x) => x.dispose()))
}

private createWebviewPanel(column: number): vscode.WebviewPanel {
Expand DownExpand Up@@ -153,14 +149,15 @@ class ReactWebView {
<meta name='theme-color' content='#000000'>
<title>React App</title>
<link rel='manifest' href='./manifest.json' />

<!-- TODO: load styles through package -->
<link rel='stylesheet' href='https://unpkg.com/@alifd/next/dist/next.css' />
<link rel='stylesheet' type='text/css' href='${styleUri}'>

<meta http-equiv='Content-Security-Policy' content="font-src *; img-src vscode-resource: https:; script-src 'nonce-${n1}' 'nonce-${n2}' 'nonce-${n3}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
<base href='${vscode.Uri.file(path.join(this.extensionPath, 'build')).with({
scheme: 'vscode-resource',
})}/'>
<style></style>
</head>

<body>
Expand Down
216 changes: 117 additions & 99 deletionssrc/editor/commands/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,110 +29,128 @@ interface CreateCommandProps {
position: any
}

// React panel webview
let webview: any
export const createCommands = ({ context, machine, storage, git, position }: CreateCommandProps) => {
// React panel webview
let webview: any

export const createCommands = ({ context, machine, storage, git, position }: CreateCommandProps) => ({
// initialize
[COMMANDS.START]: () => {
if (webview) {
console.log('CodeRoad already loaded')
return
}
// set local storage workspace
setStorage(context.workspaceState)
return {
// initialize
[COMMANDS.START]: () => {
let webviewState: 'INITIALIZING' | 'RESTARTING'
if (!webview) {
webviewState = 'INITIALIZING'
} else if (webview.loaded) {
// already loaded
vscode.window.showInformationMessage('CodeRoad already open')
return
} else {
webviewState = 'RESTARTING'
}

setStorage(context.workspaceState)

// activate machine
webview = new ReactWebView(context.extensionPath)
machine.activate()
},
// open React webview
[COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.Two) => {
// setup 1x1 horizontal layout
vscode.commands.executeCommand('vscode.setEditorLayout', {
orientation: 0,
groups: [{ groups: [{}], size: 0.6 }, { groups: [{}], size: 0.4 }],
})
const callback = () => machine.send('WEBVIEW_INITIALIZED')
webview.createOrShow(column, callback)
},
// launch a new tutorial
// NOTE: may be better to move into action as logic is primarily non-vscode
[COMMANDS.TUTORIAL_LAUNCH]: async (tutorial: CR.Tutorial) => {
console.log('launch tutorial')
// activate machine
webview = new ReactWebView(context.extensionPath)
if (webviewState === 'INITIALIZING') {
machine.activate()
} else if (webviewState === 'RESTARTING') {
setTimeout(() => {
// timeout hack to make data update on new windows
// @ts-ignore
machine.refresh()
}, 1000)
}
},
// open React webview
[COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.Two) => {
// setup 1x1 horizontal layout
vscode.commands.executeCommand('vscode.setEditorLayout', {
orientation: 0,
groups: [{ groups: [{}], size: 0.6 }, { groups: [{}], size: 0.4 }],
})
const callback = () => {
machine.send('WEBVIEW_INITIALIZED')
}
webview.createOrShow(column, callback)
},
// launch a new tutorial
// NOTE: may be better to move into action as logic is primarily non-vscode
[COMMANDS.TUTORIAL_LAUNCH]: async ({ tutorial, dispatch }: any) => {
console.log('launch tutorial')

await isEmptyWorkspace()
await isEmptyWorkspace()

await git.gitInitIfNotExists()
await git.gitInitIfNotExists()

// TODO: use actual tutorial repo
await Promise.all([git.gitSetupRemote(tutorial.meta.repo), storage.setTutorial(tutorial), storage.resetProgress()])
// TODO: use actual tutorial repo
await Promise.all([git.gitSetupRemote(tutorial.meta.repo), storage.setTutorial(tutorial), storage.resetProgress()])

// TODO: refactor to allow client to call initialization
const pos: CR.Position = await position.getInitial(tutorial)
// TODO: refactor to allow client to call initialization
const pos: CR.Position = await position.getInitial(tutorial)

// eslint-disable-next-line
const { steps } = tutorial.data
const { setup } = steps[pos.stepId].actions
await git.gitLoadCommits(setup)
machine.send('TUTORIAL_LOADED')
},
[COMMANDS.TUTORIAL_SETUP]: async (tutorial: CR.Tutorial) => {
console.log('tutorial setup', tutorial)
// setup onSave hook
const languageIds = tutorial.meta.languages
console.log(`languageIds: ${languageIds.join(', ')}`)
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
console.log('save document', document)
if (languageIds.includes(document.languageId) && document.uri.scheme === 'file') {
// do work
machine.send('TEST_RUN')
}
})
},
// open a file
[COMMANDS.OPEN_FILE]: async (relativeFilePath: string) => {
console.log(`OPEN_FILE ${JSON.stringify(relativeFilePath)}`)
try {
const workspaceRoot = vscode.workspace.rootPath
if (!workspaceRoot) {
throw new Error('No workspace root path')
// eslint-disable-next-line
const { steps } = tutorial.data
const { setup } = steps[pos.stepId].actions
await git.gitLoadCommits(setup, dispatch)
machine.send('TUTORIAL_LOADED')
},
[COMMANDS.TUTORIAL_SETUP]: async (tutorial: CR.Tutorial) => {
console.log('tutorial setup', tutorial)
// setup onSave hook
const languageIds = tutorial.meta.languages
console.log(`languageIds: ${languageIds.join(', ')}`)
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
console.log('save document', document)
if (languageIds.includes(document.languageId) && document.uri.scheme === 'file') {
// do work
machine.send('TEST_RUN')
}
})
},
// open a file
[COMMANDS.OPEN_FILE]: async (relativeFilePath: string) => {
console.log(`OPEN_FILE ${JSON.stringify(relativeFilePath)}`)
try {
const workspaceRoot = vscode.workspace.rootPath
if (!workspaceRoot) {
throw new Error('No workspace root path')
}
const absoluteFilePath = join(workspaceRoot, relativeFilePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
} catch (error) {
console.log(`Failed to open file ${relativeFilePath}`, error)
}
const absoluteFilePath = join(workspaceRoot, relativeFilePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
} catch (error) {
console.log(`Failed to open file ${relativeFilePath}`, error)
}
},
// send messages to webview
[COMMANDS.SEND_STATE]: (payload: { data: any; state: any }) => {
webview.postMessage({ type: 'SET_STATE', payload })
},
[COMMANDS.SEND_DATA]: (payload: { data: any }) => {
webview.postMessage({ type: 'SET_DATA', payload })
},
[COMMANDS.RECEIVE_ACTION]: (action: string | CR.Action) => {
// send received actions from web-app into state machine
machine.send(action)
},
[COMMANDS.RUN_TEST]: () => {
runTest({
onSuccess: () => machine.send('TEST_PASS'),
onFail: () => machine.send('TEST_FAIL'),
})
},
[COMMANDS.TEST_PASS]: () => {
vscode.window.showInformationMessage('PASS')
},
[COMMANDS.TEST_FAIL]: () => {
vscode.window.showWarningMessage('FAIL')
},
[COMMANDS.SET_LAYOUT]: () => {
console.log('setLayout')
vscode.commands.executeCommand('vscode.setEditorLayout', {
orientation: 0,
groups: [{ groups: [{}], size: 0.6 }, { groups: [{}], size: 0.4 }],
})
},
})
},
// send messages to webview
[COMMANDS.SEND_STATE]: (payload: { data: any; state: any }) => {
webview.postMessage({ type: 'SET_STATE', payload })
},
[COMMANDS.SEND_DATA]: (payload: { data: any }) => {
webview.postMessage({ type: 'SET_DATA', payload })
},
[COMMANDS.RECEIVE_ACTION]: (action: string | CR.Action) => {
// send received actions from web-app into state machine
machine.send(action)
},
[COMMANDS.RUN_TEST]: () => {
runTest({
onSuccess: () => machine.send('TEST_PASS'),
onFail: () => machine.send('TEST_FAIL'),
})
},
[COMMANDS.TEST_PASS]: () => {
vscode.window.showInformationMessage('PASS')
},
[COMMANDS.TEST_FAIL]: () => {
vscode.window.showWarningMessage('FAIL')
},
[COMMANDS.SET_LAYOUT]: () => {
console.log('setLayout')
vscode.commands.executeCommand('vscode.setEditorLayout', {
orientation: 0,
groups: [{ groups: [{}], size: 0.6 }, { groups: [{}], size: 0.4 }],
})
},
}
}
29 changes: 15 additions & 14 deletionssrc/editor/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,20 +27,6 @@ class Editor {
}
setWorkspaceRoot(rootPath)
}

privateactivateCommands=():void=>{
constcommands=createCommands({
context:this.context,
machine:this.machine,
storage,
git,
position,
})
for(constcmdincommands){
constcommand:vscode.Disposable=vscode.commands.registerCommand(cmd,commands[cmd])
this.context.subscriptions.push(command)
}
}
publicactivate=(context:vscode.ExtensionContext):void=>{
console.log('ACTIVATE!')
this.context=context
Expand All@@ -56,13 +42,28 @@ class Editor {
disposable.dispose()
}
// shut down state machine
console.log('deactivate machine')
this.machine.deactivate()
}

// execute vscode command
publicdispatch=(type:string,payload?:any)=>{
vscode.commands.executeCommand(type,payload)
}

privateactivateCommands=():void=>{
constcommands=createCommands({
context:this.context,
machine:this.machine,
storage,
git,
position,
})
for(constcmdincommands){
constcommand:vscode.Disposable=vscode.commands.registerCommand(cmd,commands[cmd])
this.context.subscriptions.push(command)
}
}
}

exportdefaultEditor
2 changes: 1 addition & 1 deletionsrc/editor/storage.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,6 @@ export function get<T>(key: string): T | undefined {
returnstorage.get(key)
}

exportfunctionupdate<T>(key:string,value:string|Object):Thenable<void>{
exportfunctionupdate<T>(key:string,value:string|object):Thenable<void>{
returnstorage.update(key,value)
}
1 change: 0 additions & 1 deletionsrc/services/git/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -128,7 +128,6 @@ export async function gitCheckRemoteExists(): Promise<boolean> {
// TODO: improve the specificity of this regex
return!!stdout.match(gitOrigin)
}catch(error){
console.warn(error)
returnfalse
}
}
Expand Down
2 changes: 1 addition & 1 deletionsrc/services/position.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,4 +62,4 @@ export async function loadProgressPosition() {
storage.setPosition(position)
}

exportasyncfunctiongetPrev():Promise<void>{}
exportasyncfunctiongetPrev():Promise<void>{}
5 changes: 3 additions & 2 deletionssrc/state/actions/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,11 +43,10 @@ export default (dispatch: CR.EditorDispatch) => ({
currentTutorial = tutorial
console.log('api')
console.log(tutorial)
dispatch('coderoad.tutorial_launch', tutorial)
dispatch('coderoad.tutorial_launch',{tutorial, dispatch })
},
tutorialSetup() {
dispatch('coderoad.tutorial_setup', currentTutorial)
dispatch('coderoad.open_webview', 2)
},
initializeNewTutorial: assign({
position: (context: any): CR.Position => {
Expand DownExpand Up@@ -88,6 +87,8 @@ export default (dispatch: CR.EditorDispatch) => ({
const levelId = levelList.find((id: string) => !currentProgress.levels[id]) || levelList[levelList.length - 1]
const { stageList } = data.levels[levelId]
const stageId = stageList.find((id: string) => !currentProgress.stages[id]) || stageList[stageList.length - 1]
console.log('position stepList')
console.log(data.stages[stageId])
const { stepList } = data.stages[stageId]
const stepId = stepList.find((id: string) => !currentProgress.steps[id]) || stepList[stepList.length - 1]

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp