@@ -34,11 +34,11 @@ export class RunCodeFeature implements vscode.Disposable {
34
34
args : string [ ] ) {
35
35
36
36
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 ) ;
39
39
}
40
40
41
- private launch ( launchConfig ) {
41
+ private async launch ( launchConfig : string | vscode . DebugConfiguration ) {
42
42
// Create or show the interactive console
43
43
// TODO #367: Check if "newSession" mode is configured
44
44
vscode . commands . executeCommand ( "PowerShell.ShowSessionConsole" , true ) ;
@@ -48,19 +48,25 @@ export class RunCodeFeature implements vscode.Disposable {
48
48
utils . getDebugSessionFilePath ( ) ,
49
49
this . sessionManager . getSessionDetails ( ) ) ;
50
50
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 ) ;
53
52
}
54
53
}
55
54
56
- function createLaunchConfig ( launchType : LaunchType , commandToRun : string , args : string [ ] ) {
55
+ async function createLaunchConfig ( launchType : LaunchType , commandToRun : string , args : string [ ] ) {
57
56
const settings = Settings . load ( ) ;
58
57
59
- let cwd : string = vscode . workspace . rootPath ;
58
+ let cwd : string ;
60
59
if ( vscode . window . activeTextEditor
61
60
&& vscode . window . activeTextEditor . document
62
61
&& ! 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
+ }
64
70
}
65
71
66
72
const launchConfig = {
0 commit comments