@@ -14,7 +14,7 @@ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
1414import { readFile } from 'fs'
1515import { join } from 'path'
1616import { promisify } from 'util'
17- import { compare } from 'semver '
17+ import environment from '../environment '
1818
1919const readFileAsync = promisify ( readFile )
2020
@@ -26,18 +26,15 @@ interface Channel {
2626interface ChannelProps {
2727postMessage :( action :T . Action ) => Thenable < boolean >
2828workspaceState :vscode . Memento
29- workspaceRoot :vscode . WorkspaceFolder
3029}
3130
3231class Channel implements Channel {
3332private postMessage :( action :T . Action ) => Thenable < boolean >
3433private workspaceState :vscode . Memento
35- private workspaceRoot :vscode . WorkspaceFolder
3634private context :Context
37- constructor ( { postMessage, workspaceState, workspaceRoot } :ChannelProps ) {
35+ constructor ( { postMessage, workspaceState} :ChannelProps ) {
3836// workspaceState used for local storage
3937this . workspaceState = workspaceState
40- this . workspaceRoot = workspaceRoot
4138this . postMessage = postMessage
4239this . context = new Context ( workspaceState )
4340}
@@ -52,6 +49,22 @@ class Channel implements Channel {
5249
5350switch ( actionType ) {
5451case 'EDITOR_ENV_GET' :
52+ // check if a workspace is open, otherwise nothing works
53+ const noActiveWorksapce = ! environment . WORKSPACE_ROOT . length
54+ if ( noActiveWorksapce ) {
55+ const error :E . ErrorMessage = {
56+ type :'NoWorkspaceFound' ,
57+ message :'' ,
58+ actions :[
59+ {
60+ label :'Open Workspace' ,
61+ transition :'REQUEST_WORKSPACE' ,
62+ } ,
63+ ] ,
64+ }
65+ this . send ( { type :'NO_WORKSPACE' , payload :{ error} } )
66+ return
67+ }
5568this . send ( {
5669type :'ENV_LOAD' ,
5770payload :{
@@ -180,8 +193,8 @@ class Channel implements Channel {
180193vscode . commands . executeCommand ( COMMANDS . SET_CURRENT_STEP , action . payload )
181194return
182195case 'EDITOR_VALIDATE_SETUP' :
183- //1. check workspace is selected
184- const isEmptyWorkspace = await checkWorkspaceEmpty ( this . workspaceRoot . uri . path )
196+ // check workspace is selected
197+ const isEmptyWorkspace = await checkWorkspaceEmpty ( )
185198if ( ! isEmptyWorkspace ) {
186199const error :E . ErrorMessage = {
187200type :'WorkspaceNotEmpty' ,
@@ -200,7 +213,7 @@ class Channel implements Channel {
200213this . send ( { type :'VALIDATE_SETUP_FAILED' , payload :{ error} } )
201214return
202215}
203- //2. check Git is installed.
216+ // check Git is installed.
204217// Should wait for workspace before running otherwise requires access to root folder
205218const isGitInstalled = await version ( 'git' )
206219if ( ! isGitInstalled ) {
@@ -225,11 +238,11 @@ class Channel implements Channel {
225238// load step actions (git commits, commands, open files)
226239case 'SETUP_ACTIONS' :
227240await vscode . commands . executeCommand ( COMMANDS . SET_CURRENT_STEP , action . payload )
228- setupActions ( this . workspaceRoot , action . payload , this . send )
241+ setupActions ( action . payload , this . send )
229242return
230243// load solution step actions (git commits, commands, open files)
231244case 'SOLUTION_ACTIONS' :
232- await solutionActions ( this . workspaceRoot , action . payload , this . send )
245+ await solutionActions ( action . payload , this . send )
233246// run test following solution to update position
234247vscode . commands . executeCommand ( COMMANDS . RUN_TEST , action . payload )
235248return