Skip to content

Commit 5aa078b

Browse files
committed
WIP: Starting to support multi-root workspaces
1 parent c598977 commit 5aa078b

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/features/RunCode.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -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 = {

test/features/RunCode.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum LaunchType {
2121
describe("RunCode feature", function () {
2222
before(utils.ensureEditorServicesIsConnected);
2323

24-
it("Creates the launch config", function () {
24+
it("Creates the launch config", async function () {
2525
const commandToRun: string = "Invoke-Build";
2626
const args: string[] = ["Clean"];
2727

@@ -34,10 +34,10 @@ describe("RunCode feature", function () {
3434
internalConsoleOptions: "neverOpen",
3535
noDebug: false,
3636
createTemporaryIntegratedConsole: false,
37-
cwd: vscode.workspace.rootPath,
37+
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
3838
};
3939

40-
const actual: object = createLaunchConfig(LaunchType.Debug, commandToRun, args);
40+
const actual: object = await createLaunchConfig(LaunchType.Debug, commandToRun, args);
4141

4242
assert.deepStrictEqual(actual, expected);
4343
});

0 commit comments

Comments
 (0)