Skip to content

fix workspaceRoot deprecation warnings #35

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 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix workspaceRoot deprecation warnings
  • Loading branch information
ShMcK committed Sep 24, 2019
commit 0d6b5b51412a9e2c7941229935adba34d22dfb4d
15 changes: 2 additions & 13 deletions src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const runCommands = async (commands: string[], language: string) => {
}


const setupActions = async ({commands, commits, files}: G.StepActions): Promise<void> => {
const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files}: G.StepActions): Promise<void> => {
// run commits
for (const commit of commits) {
await git.loadCommit(commit)
Expand All @@ -49,18 +49,7 @@ const setupActions = async ({commands, commits, files}: G.StepActions): Promise<
for (const filePath of files) {
console.log(`OPEN_FILE ${filePath}`)
try {
// TODO: re-enable after testing
// const workspaceRoots: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders
// if (!workspaceRoots || !workspaceRoots.length) {
// throw new Error('No workspace root path')
// }
// const rootWorkspace: vscode.WorkspaceFolder = workspaceRoots[0]
// const absoluteFilePath = join(rootWorkspace.uri.path, relativeFilePath)
const workspaceRoot = vscode.workspace.rootPath
if (!workspaceRoot) {
throw new Error('No workspace root path')
}
const absoluteFilePath = join(workspaceRoot, filePath)
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
Expand Down
7 changes: 5 additions & 2 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ interface Channel {
interface ChannelProps {
postMessage: (action: CR.Action) => Thenable<boolean>
workspaceState: vscode.Memento
workspaceRoot: vscode.WorkspaceFolder
}


class Channel implements Channel {
private postMessage: (action: CR.Action) => Thenable<boolean>
private workspaceState: vscode.Memento
private workspaceRoot: vscode.WorkspaceFolder
private context: Context
constructor({postMessage, workspaceState}: ChannelProps) {
constructor({postMessage, workspaceState, workspaceRoot}: ChannelProps) {
// workspaceState used for local storage
this.workspaceState = workspaceState
this.workspaceRoot = workspaceRoot
this.postMessage = postMessage
this.context = new Context(workspaceState)
}
Expand Down Expand Up @@ -96,7 +99,7 @@ class Channel implements Channel {
// load step actions (git commits, commands, open files)
case 'SETUP_ACTIONS':
vscode.commands.executeCommand('coderoad.set_current_step', action.payload)
setupActions(action.payload)
setupActions(this.workspaceRoot, action.payload)
return
// load solution step actions (git commits, commands, open files)
case 'SOLUTION_ACTIONS':
Expand Down
4 changes: 3 additions & 1 deletion src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const getNonce = (): string => {
interface ReactWebViewProps {
extensionPath: string
workspaceState: vscode.Memento
workspaceRoot: vscode.WorkspaceFolder
}


Expand All @@ -30,7 +31,7 @@ class ReactWebView {
private disposables: vscode.Disposable[] = []
private channel: Channel

public constructor({extensionPath, workspaceState}: ReactWebViewProps) {
public constructor({extensionPath, workspaceState, workspaceRoot}: ReactWebViewProps) {
this.extensionPath = extensionPath

// Create and show a new webview panel
Expand Down Expand Up @@ -71,6 +72,7 @@ class ReactWebView {
// channel connects webview to the editor
this.channel = new Channel({
workspaceState,
workspaceRoot,
postMessage: (action: Action): Thenable<boolean> => {
// console.log(`postMessage ${JSON.stringify(action)}`)
return this.panel.webview.postMessage(action)
Expand Down
7 changes: 4 additions & 3 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as vscode from 'vscode'
import ReactWebView from './ReactWebView'
import runTest from '../actions/runTest'
import {isEmptyWorkspace} from './workspace'

const COMMANDS = {
START: 'coderoad.start',
Expand All @@ -13,9 +12,10 @@ const COMMANDS = {
interface CreateCommandProps {
extensionPath: string
workspaceState: vscode.Memento
workspaceRoot: vscode.WorkspaceFolder
}

export const createCommands = ({extensionPath, workspaceState}: CreateCommandProps) => {
export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: CreateCommandProps) => {
// React panel webview
let webview: any
let currentStepId = ''
Expand All @@ -26,7 +26,7 @@ export const createCommands = ({extensionPath, workspaceState}: CreateCommandPro
console.log('start')

// TODO: replace with a prompt to open a workspace
await isEmptyWorkspace()
// await isEmptyWorkspace()

let webviewState: 'INITIALIZING' | 'RESTARTING'
if (!webview) {
Expand All @@ -43,6 +43,7 @@ export const createCommands = ({extensionPath, workspaceState}: CreateCommandPro
webview = new ReactWebView({
extensionPath,
workspaceState,
workspaceRoot,
})
},
// open React webview
Expand Down
26 changes: 9 additions & 17 deletions src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ class Editor {
// @ts-ignore
private vscodeExt: vscode.ExtensionContext

constructor() {
// set workspace root for node executions
const rootPath = vscode.workspace.rootPath
if (!rootPath) {
throw new Error('Requires a workspace. Please open a folder')
}
}
public activate = (vscodeExt: vscode.ExtensionContext): void => {

console.log('ACTIVATE!')
this.vscodeExt = vscodeExt

Expand All @@ -31,21 +25,19 @@ class Editor {
}

private activateCommands = (): void => {
// NOTE: local storage must be bound to the vscodeExt.workspaceState

// store current tutorial id & version


// store step progress for current tutorial
// const stepProgress = new Storage<{[stepId: string]: boolean}>({
// key: 'coderoad:progress',
// storage: this.vscodeExt.workspaceState,
// defaultValue: {},
// })
// set workspace root for node executions
const workspaceRoots: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders
if (!workspaceRoots || !workspaceRoots.length) {
throw new Error('No workspace root path')
}
const workspaceRoot: vscode.WorkspaceFolder = workspaceRoots[0]

const commands = createCommands({
extensionPath: this.vscodeExt.extensionPath,
// NOTE: local storage must be bound to the vscodeExt.workspaceState
workspaceState: this.vscodeExt.workspaceState,
workspaceRoot,
})

// register commands
Expand Down
43 changes: 0 additions & 43 deletions src/editor/workspace.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/services/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as CR from 'typings'
import node from '../node'


Expand Down
16 changes: 9 additions & 7 deletions src/services/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import * as vscode from 'vscode'
const asyncExec = promisify(cpExec)

class Node {
private workspaceRoot: string
private workspaceRootPath: string
constructor() {
this.workspaceRoot = vscode.workspace.rootPath || ''
if (!this.workspaceRoot.length) {
throw new Error('Invalid workspaceRoot')
// set workspace root for node executions
const workspaceRoots: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders
if (!workspaceRoots || !workspaceRoots.length) {
throw new Error('No workspace root path')
}
console.log(`workspaceRoot: ${this.workspaceRoot}`)
const workspaceRoot: vscode.WorkspaceFolder = workspaceRoots[0]
this.workspaceRootPath = workspaceRoot.uri.path
}
public exec = (cmd: string): Promise<{stdout: string; stderr: string}> => asyncExec(cmd, {
cwd: this.workspaceRoot,
cwd: this.workspaceRootPath,
})

public exists = (...paths: string[]): boolean => fs.existsSync(join(this.workspaceRoot, ...paths))
public exists = (...paths: string[]): boolean => fs.existsSync(join(this.workspaceRootPath, ...paths))
}

export default new Node()