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

Feature/tutorial setup#4

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 12 commits intomasterfromfeature/tutorial-setup
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
further editor refactoring
  • Loading branch information
@ShMcK
ShMcK committedJun 9, 2019
commit6d8b993d332134b8ab6b10ec364cc9ab86bf026d
75 changes: 42 additions & 33 deletionssrc/editor/commands/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
// import * as vscode from 'vscode'
// import start from './start'
// // import ReactPanel from '../views/createWebview'
import * as vscode from 'vscode'
import { join } from 'path'
import { setStorage } from '../storage'
import ReactWebView from '../ReactWebView'
import * as CR from '../../typings'

// import runTest from './runTest'
// // import loadSolution from './loadSolution'
// // import quit from './quit'
const COMMANDS = {
START: 'coderoad.start',
OPEN_WEBVIEW: 'coderoad.open_webview',
OPEN_FILE: 'coderoad.open_file',
RUN_TEST: 'coderoad.test_run',
}

// const COMMANDS = {
// // TUTORIAL_SETUP: 'coderoad.tutorial_setup',
// START: 'coderoad.start',
// OPEN_WEBVIEW: 'coderoad.open_webview',
// RUN_TEST: 'coderoad.test_run',
// // LOAD_SOLUTION: 'coderoad.solution_load',
// // QUIT: 'coderoad.quit',
// }
interface CreateCommandProps {
context: vscode.ExtensionContext,
machine: CR.StateMachine
}

// React panel webview
let webview: any;

// export default (context: vscode.ExtensionContext): void => {
// const commands = {
// [COMMANDS.START]: () => {
// start(context)
// },
// [COMMANDS.OPEN_WEBVIEW]: () => {
// // ReactPanel.createOrShow(context.extensionPath);
// },
// [COMMANDS.RUN_TEST]: () => {
// runTest()
// },
// // [COMMANDS.LOAD_SOLUTION]: loadSolution,
// // [COMMANDS.QUIT]: () => quit(context.subscriptions),
// }
export const createCommands = ({ context, machine }: CreateCommandProps) => ({
[COMMANDS.START]: () => {
// set local storage workspace
setStorage(context.workspaceState)

// for (const cmd in commands) {
// const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd])
// context.subscriptions.push(command)
// }
// }
// activate machine
webview = new ReactWebView(context.extensionPath, machine.onReceive)
machine.activate()
},
[COMMANDS.OPEN_WEBVIEW]: () => {
webview.createOrShow();
},
[COMMANDS.OPEN_FILE]: async (relativeFilePath: string) => {
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)
}
}
})
5 changes: 0 additions & 5 deletionssrc/editor/commands/quit.ts
View file
Open in desktop

This file was deleted.

53 changes: 15 additions & 38 deletionssrc/editor/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,35 @@
import * as vscode from 'vscode'
import * as CR from '../typings'
import { setStorage } from './storage'
import ReactWebView from './ReactWebView'
import { createCommands } from './commands'

interface Props {
machine: CR.StateMachine,
setWorkspaceRoot(rootPath: string): void
}

class Editor {
// extension context set on activation
// @ts-ignore
private context: vscode.ExtensionContext
private workspaceRoot: string | undefined
private machine: CR.StateMachine
private webview: any

private COMMANDS = {
START: 'coderoad.start',
OPEN_WEBVIEW: 'coderoad.open_webview',
RUN_TEST: 'coderoad.test_run',
}

constructor(machine: CR.StateMachine) {
constructor({ machine, setWorkspaceRoot }: Props) {
this.machine = machine
}

private commandStart = (): void => {
// set workspaceroot
const { rootPath } =vscode.workspace
// set workspace root for node executions
const { workspace} = vscode
const { rootPath } = workspace
if (!rootPath) {
throw new Error('Requires a workspace. Please open a folder')
}
this.workspaceRoot = rootPath

// set local storage workspace
setStorage(this.context.workspaceState)

// activate machine
this.webview = new ReactWebView(this.context.extensionPath, this.machine.onReceive)
this.machine.activate()

console.log('command start webview')
console.log(this.webview)
setWorkspaceRoot(rootPath)
}

private activateCommands = (): void => {
console.log('this.COMMANDS', this.COMMANDS)
const commands = {
[this.COMMANDS.START]: () => {
console.log('start')
this.commandStart()
},
[this.COMMANDS.OPEN_WEBVIEW]: () => {
console.log('open webview')
console.log(this.webview)
this.webview.createOrShow();
},
}
const commands = createCommands({
context: this.context,
machine: this.machine,
})
for (const cmd in commands) {
const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd])
this.context.subscriptions.push(command)
Expand Down
14 changes: 9 additions & 5 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import { setWorkspaceRoot } from './services/node'
import StateMachine from './state'
import Editor from './editor'

// state machine that governs application logic
const Machine = new StateMachine()
// vscode editor
const VSCodeEditor = new Editor(Machine)
export const machine = new StateMachine()

export const activate = VSCodeEditor.activate
export const deactivate = VSCodeEditor.deactivate
// vscode editor
export const editor = new Editor({
machine,
setWorkspaceRoot,
})

export const activate = editor.activate
export const deactivate = editor.deactivate
5 changes: 3 additions & 2 deletionssrc/services/git/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode'
import * as CR from 'typings'
import { exec, exists, openFile } from '../node'
import { exec, exists } from '../node'

const gitOrigin = 'coderoad'

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

if (files) {
for (const filePath of files) {
openFile(filePath)
vscode.commands.executeCommand('coderoad.open_webview',filePath)
}
}
}
Expand Down
19 changes: 1 addition & 18 deletionssrc/services/node/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
import { workspace } from 'vscode'
import * as fs from 'fs'
import * as vscode from 'vscode'
import { join } from 'path'
import { exec as cpExec } from 'child_process'
import { promisify } from 'util'
Expand All@@ -11,11 +9,7 @@ let workspaceRoot: string

// set workspace root
// other function will use this to target the correct cwd
export async function setWorkspaceRoot(): Promise<void> {
const { rootPath } = workspace
if (!rootPath) {
throw new Error('Requires a workspace. Please open a folder')
}
export function setWorkspaceRoot(rootPath: string): void {
workspaceRoot = rootPath
}

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

export const openFile = async (relativeFilePath: string): Promise<void> => {
try {
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)
}
}


// export async function clear(): Promise<void> {
// // remove all files including ignored
// // NOTE: Linux only
Expand Down
1 change: 0 additions & 1 deletionsrc/services/testResult.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ import * as CR from 'typings'
import * as vscode from 'vscode'
import * as storage from './storage'


export async function onSuccess(position: CR.Position) {
console.log('onSuccess', position)
vscode.window.showInformationMessage('SUCCESS')
Expand Down
3 changes: 1 addition & 2 deletionssrc/state/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,9 +17,8 @@ class StateMachine {
this.service = interpret(machine, this.machineOptions)
// logging
.onTransition(state => {
console.log('state', state)
if (state.changed) {
console.log('transition')
console.log('next state')
console.log(state.value)
}
})
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp