@@ -34,11 +34,11 @@ export class RunCodeFeature implements vscode.Disposable {
3434 args : string [ ] ) {
3535
3636 const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
37- const launchConfig = createLaunchConfig ( launchType , scriptToRun , args ) ;
38- this . launch ( launchConfig ) ;
37+ const launchConfig = await createLaunchConfig ( launchType , scriptToRun , args ) ;
38+ return this . launch ( launchConfig ) ;
3939 }
4040
41- private launch ( launchConfig ) {
41+ private async launch ( launchConfig : string | vscode . DebugConfiguration ) {
4242 // Create or show the interactive console
4343 // TODO #367: Check if "newSession" mode is configured
4444 vscode . commands . executeCommand ( "PowerShell.ShowSessionConsole" , true ) ;
@@ -48,19 +48,25 @@ export class RunCodeFeature implements vscode.Disposable {
4848 utils . getDebugSessionFilePath ( ) ,
4949 this . sessionManager . getSessionDetails ( ) ) ;
5050
51- // TODO: Update to handle multiple root workspaces.
52- vscode . debug . startDebugging ( vscode . workspace . workspaceFolders ?. [ 0 ] , launchConfig ) ;
51+ vscode . debug . startDebugging ( await vscode . window . showWorkspaceFolderPick ( ) , launchConfig ) ;
5352 }
5453}
5554
56- function createLaunchConfig ( launchType : LaunchType , commandToRun : string , args : string [ ] ) {
55+ async function createLaunchConfig ( launchType : LaunchType , commandToRun : string , args : string [ ] ) {
5756 const settings = Settings . load ( ) ;
5857
59- let cwd : string = vscode . workspace . rootPath ;
58+ let cwd : string ;
6059 if ( vscode . window . activeTextEditor
6160 && vscode . window . activeTextEditor . document
6261 && ! vscode . window . activeTextEditor . document . isUntitled ) {
63- cwd = path . dirname ( vscode . window . activeTextEditor . document . fileName ) ;
62+ cwd = vscode . workspace . getWorkspaceFolder ( vscode . window . activeTextEditor . document . uri ) ?. uri . fsPath ;
63+ }
64+ if ( cwd === undefined ) {
65+ if ( vscode . workspace . workspaceFolders ?. length > 1 ) {
66+ cwd = ( await vscode . window . showWorkspaceFolderPick ( ) ) ?. uri . fsPath ;
67+ } else {
68+ cwd = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
69+ }
6470 }
6571
6672 const launchConfig = {
0 commit comments