Skip to content

Fix/update to api #43

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"prettier": "^1.18.2",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.6.4",
"typescript": "^3.7.0-beta",
"vscode": "^1.1.36",
"vscode-test": "^1.2.0"
},
Expand Down
14 changes: 2 additions & 12 deletions src/actions/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as vscode from 'vscode'
import node from '../services/node'

// TODO: use tap parser to make it easier to support other test runners

// ensure only latest run_test action is taken
let currentId = 0

Expand Down Expand Up @@ -35,12 +37,6 @@ async function runTest({onSuccess, onFail, onRun, onError}: Props): Promise<void

const outputChannelName = 'Test Output'

// TODO: validate test directory from package.json exists
// let testFile = path.join('test');
// if (!await exists(testFile)) {
// return emptyTasks;
// }

// TODO: verify test runner for args
// jest CLI docs https://jestjs.io/docs/en/cli
const testArgs = [
Expand All @@ -51,12 +47,6 @@ async function runTest({onSuccess, onFail, onRun, onError}: Props): Promise<void
'--maxWorkers=4'
]

// if .git repo, use --onlyChanged
// const hasGit = path.join('.git');
// if (await exists(hasGit)) {
// testArgs.push('--onlyChanged')
// }

const commandLine = `npm test -- ${testArgs.join(' ')}`

try {
Expand Down
60 changes: 33 additions & 27 deletions src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,45 @@ const runCommands = async (commands: string[], language: string = 'JAVASCRIPT')

const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files}: G.StepActions): Promise<void> => {
// run commits
for (const commit of commits) {
await git.loadCommit(commit)
if (commits) {
for (const commit of commits) {
await git.loadCommit(commit)
}
}

// run command
await runCommands(commands)
if (commands) {
await runCommands(commands)
}

// open files
for (const filePath of files) {
try {
// TODO: figure out why this does not work
// try {
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// // there are times when initialization leave the panel behind any files opened
// // ensure the panel is redrawn on the right side first
// // webview.createOrShow()
// } catch (error) {
// console.log(`Failed to open file ${filePath}`, error)
// }
const wr = vscode.workspace.rootPath
if (!wr) {
throw new Error('No workspace root path')
if (files) {
for (const filePath of files) {
try {
// TODO: figure out why this does not work
// try {
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// // there are times when initialization leave the panel behind any files opened
// // ensure the panel is redrawn on the right side first
// // webview.createOrShow()
// } catch (error) {
// console.log(`Failed to open file ${filePath}`, error)
// }
const wr = vscode.workspace.rootPath
if (!wr) {
throw new Error('No workspace root path')
}
const absoluteFilePath = join(wr, filePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// there are times when initialization leave the panel behind any files opened
// ensure the panel is redrawn on the right side first
vscode.commands.executeCommand('coderoad.open_webview')
} catch (error) {
console.log(`Failed to open file ${filePath}`, error)
}
const absoluteFilePath = join(wr, filePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// there are times when initialization leave the panel behind any files opened
// ensure the panel is redrawn on the right side first
vscode.commands.executeCommand('coderoad.open_webview')
} catch (error) {
console.log(`Failed to open file ${filePath}`, error)
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/actions/tutorialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ import * as vscode from 'vscode'
import * as git from '../services/git'

interface TutorialConfigParams {
tutorial: G.Tutorial,
config: G.TutorialConfig,
alreadyConfigured?: boolean
onComplete?(): void
}

const tutorialConfig = async ({tutorial, alreadyConfigured, onComplete}: TutorialConfigParams) => {
console.log('---------- tutorialConfig -----------')
const tutorialConfig = async ({config, alreadyConfigured, }: TutorialConfigParams) => {
if (!alreadyConfigured) {
// setup git, add remote
await git.initIfNotExists()

// TODO: if remote not already set
await git.setupRemote(tutorial.repo.uri)
if (onComplete) {onComplete()}
await git.setupRemote(config.repo.uri)
}

// TODO: allow multiple coding languages in a tutorial
const language = tutorial.codingLanguage.toLowerCase()
// allow multiple coding languages in a tutorial
const languages: string[] = config.codingLanguages.map((lang: G.CodingLanguage) => lang.toLowerCase())

// setup onSave hook
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
if (document.uri.scheme === 'file' && language === document.languageId) {
// @ts-ignore // issue with GQL enums in TS
if (document.uri.scheme === 'file' && languages.includes(document.languageId)) {
vscode.commands.executeCommand('coderoad.run_test')
}
})
Expand Down
26 changes: 19 additions & 7 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,33 @@ class Channel implements Channel {
return
// configure test runner, language, git
case 'EDITOR_TUTORIAL_CONFIG':
const tutorialData = action.payload.tutorial
const tutorialData: G.Tutorial = action.payload.tutorial
// setup tutorial config (save listener, test runner, etc)
this.context.setTutorial(this.workspaceState, tutorialData)
tutorialConfig({
tutorial: tutorialData,
// must await async git setup or commit loading fails
onComplete: () => this.send({type: 'TUTORIAL_CONFIGURED'})
})

const data: G.TutorialData = tutorialData.version.data

await tutorialConfig({config: data.config})

// run init setup actions
if (data.init) {
const setup: G.StepActions | null | undefined = data.init.setup
if (setup) {
setupActions(this.workspaceRoot, setup)
}
}

// report back to the webview that setup is complete
this.send({type: 'TUTORIAL_CONFIGURED'})
return
case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
const tutorialContinue: G.Tutorial | null = this.context.tutorial.get()
if (!tutorialContinue) {
throw new Error('Invalid tutorial to continue')
}
const continueConfig: G.TutorialConfig = tutorialContinue.version.data.config
tutorialConfig({
tutorial: tutorialContinue,
config: continueConfig,
alreadyConfigured: true
})
return
Expand Down
18 changes: 6 additions & 12 deletions src/channel/state/Position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as G from 'typings/graphql'

const defaultValue: CR.Position = {
levelId: '',
stageId: '',
stepId: '',
}

Expand Down Expand Up @@ -31,7 +30,11 @@ class Position {
return this.value
}

const {levels} = tutorial.version
if (!tutorial || !tutorial.version || !tutorial.version.data || !tutorial.version.data.levels) {
throw new Error('Error setting position from progress')
}

const {levels} = tutorial.version.data

const lastLevelIndex: number | undefined = levels.findIndex((l: G.Level) => !progress.levels[l.id])
// TODO: consider all levels complete as progress.complete
Expand All @@ -40,15 +43,7 @@ class Position {
}
const currentLevel: G.Level = levels[lastLevelIndex]

const {stages} = currentLevel

const lastStageIndex: number | undefined = stages.findIndex((s: G.Stage) => !progress.stages[s.id])
if (lastStageIndex >= stages.length) {
throw new Error('Error setting progress stage')
}
const currentStage: G.Stage = stages[lastStageIndex]

const {steps} = currentStage
const {steps} = currentLevel

const lastStepIndex: number | undefined = steps.findIndex((s: G.Step) => !progress.steps[s.id])
if (lastStepIndex >= steps.length) {
Expand All @@ -60,7 +55,6 @@ class Position {

this.value = {
levelId: currentLevel.id,
stageId: currentStage.id,
stepId: currentStep.id,
}
return this.value
Expand Down
1 change: 0 additions & 1 deletion src/channel/state/Progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Storage from '../../services/storage'

const defaultValue: CR.Progress = {
levels: {},
stages: {},
steps: {},
complete: false
}
Expand Down
2 changes: 0 additions & 2 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class ReactWebView {

// // // prevents moving coderoad panel on top of left panel
// vscode.window.onDidChangeVisibleTextEditors((textEditors: vscode.TextEditor[]) => {
// console.log('onDidChangeVisibleTextEditors')
// console.log(textEditors)
// // updateWindows()
// })

Expand Down
2 changes: 1 addition & 1 deletion src/services/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function loadCommit(commit: string): Promise<void> {

/*
save commit
git commit -am '${level}/${stage}/${step} complete'
git commit -am '${level}/${step} complete'
*/

export async function saveCommit(message: string): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions src/services/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class Storage<T> {
this.defaultValue = defaultValue
}
public get = async (): Promise<T> => {
const value: string | undefined = await this.storage.get(this.key)
if (value) {
return JSON.parse(value)
}
// const value: string | undefined = await this.storage.get(this.key)
// if (value) {
// return JSON.parse(value)
// }
return this.defaultValue
}
public set = (value: T): void => {
Expand Down
1 change: 0 additions & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from 'path'
import {runTests} from 'vscode-test'

async function main() {
console.log('__dirname', __dirname)
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath: string = path.resolve(__dirname, '../../')
Expand Down
1 change: 0 additions & 1 deletion src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ suite('Extension tests', () => {
await vscode.commands.executeCommand('coderoad.start')
await setTimeout(() => Promise.resolve(), 5000)
// const webview = vscode.window.activeTextEditor
// console.log(webview)
assert.equal(2, 2)
})

Expand Down
21 changes: 9 additions & 12 deletions typings/context.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import * as CR from './index'

export interface Step extends Exclude<CR.TutorialStep, 'actions'> {
status: {
complete: boolean
active: boolean
}
interface ProgressStatus {
active: boolean
complete: boolean
}

export interface ReceivedEvent {
data: CR.Action
export interface Step extends Exclude<CR.TutorialStep, 'actions'> {
status: ProgressStatus
}

export interface StageStepStatus {
active: boolean
complete: boolean
export interface ReceivedEvent {
data: CR.Action
}

export interface StageWithStatus extends CR.TutorialStage {
status: StageStepStatus
export interface LevelWithStatus extends CR.TutorialLevel {
status: ProgressStatus
}
Loading