-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathRunCode.ts
62 lines (51 loc) · 2.02 KB
/
RunCode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import vscode = require("vscode");
import { SessionManager } from "../session";
import { ILogger } from "../logging";
import { getSettings, getChosenWorkspace } from "../settings";
enum LaunchType {
Debug,
Run,
}
export class RunCodeFeature implements vscode.Disposable {
private command: vscode.Disposable;
constructor(private sessionManager: SessionManager, private logger: ILogger) {
this.command = vscode.commands.registerCommand(
"PowerShell.RunCode",
async (runInDebugger: boolean, scriptToRun: string, args: string[]) => {
await this.launchTask(runInDebugger, scriptToRun, args);
});
}
public dispose(): void {
this.command.dispose();
}
private async launchTask(
runInDebugger: boolean,
scriptToRun: string,
args: string[]): Promise<void> {
const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
const launchConfig = createLaunchConfig(launchType, scriptToRun, args);
await this.launch(launchConfig);
}
private async launch(launchConfig: string | vscode.DebugConfiguration): Promise<void> {
// Create or show the interactive console
// TODO: #367: Check if "newSession" mode is configured
this.sessionManager.showDebugTerminal(true);
await vscode.debug.startDebugging(await getChosenWorkspace(this.logger), launchConfig);
}
}
function createLaunchConfig(launchType: LaunchType, commandToRun: string, args: string[]): vscode.DebugConfiguration {
const settings = getSettings();
const launchConfig = {
request: "launch",
type: "PowerShell",
name: "PowerShell: Run Code",
internalConsoleOptions: "neverOpen",
noDebug: (launchType === LaunchType.Run),
createTemporaryIntegratedConsole: settings.debugging.createTemporaryIntegratedConsole,
script: commandToRun,
args,
};
return launchConfig;
}