@@ -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 {
2727 postMessage : ( action : T . Action ) => Thenable < boolean >
2828 workspaceState : vscode . Memento
29- workspaceRoot : vscode . WorkspaceFolder
3029}
3130
3231class Channel implements Channel {
3332 private postMessage : ( action : T . Action ) => Thenable < boolean >
3433 private workspaceState : vscode . Memento
35- private workspaceRoot : vscode . WorkspaceFolder
3634 private context : Context
37- constructor ( { postMessage, workspaceState, workspaceRoot } : ChannelProps ) {
35+ constructor ( { postMessage, workspaceState } : ChannelProps ) {
3836 // workspaceState used for local storage
3937 this . workspaceState = workspaceState
40- this . workspaceRoot = workspaceRoot
4138 this . postMessage = postMessage
4239 this . context = new Context ( workspaceState )
4340 }
@@ -52,6 +49,22 @@ class Channel implements Channel {
5249
5350 switch ( actionType ) {
5451 case '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+ }
5568 this . send ( {
5669 type : 'ENV_LOAD' ,
5770 payload : {
@@ -180,8 +193,8 @@ class Channel implements Channel {
180193 vscode . commands . executeCommand ( COMMANDS . SET_CURRENT_STEP , action . payload )
181194 return
182195 case '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 ( )
185198 if ( ! isEmptyWorkspace ) {
186199 const error : E . ErrorMessage = {
187200 type : 'WorkspaceNotEmpty' ,
@@ -200,7 +213,7 @@ class Channel implements Channel {
200213 this . send ( { type : 'VALIDATE_SETUP_FAILED' , payload : { error } } )
201214 return
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
205218 const isGitInstalled = await version ( 'git' )
206219 if ( ! isGitInstalled ) {
@@ -225,11 +238,11 @@ class Channel implements Channel {
225238 // load step actions (git commits, commands, open files)
226239 case 'SETUP_ACTIONS' :
227240 await vscode . commands . executeCommand ( COMMANDS . SET_CURRENT_STEP , action . payload )
228- setupActions ( this . workspaceRoot , action . payload , this . send )
241+ setupActions ( action . payload , this . send )
229242 return
230243 // load solution step actions (git commits, commands, open files)
231244 case '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
234247 vscode . commands . executeCommand ( COMMANDS . RUN_TEST , action . payload )
235248 return
0 commit comments