Skip to content

Commit 8a6671e

Browse files
committed
Use enum in provideDebugConfigurations
1 parent 709376e commit 8a6671e

File tree

1 file changed

+50
-51
lines changed

1 file changed

+50
-51
lines changed

src/features/DebugSession.ts

+50-51
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,31 @@ export class DebugSessionFeature extends LanguageClientConsumer
7575
folder: WorkspaceFolder | undefined,
7676
token?: CancellationToken): Promise<DebugConfiguration[]> {
7777

78-
const launchCurrentFileId = 0;
79-
const launchScriptId = 1;
80-
const interactiveSessionId = 2;
81-
const attachHostProcessId = 3;
78+
enum DebugConfig {
79+
LaunchCurrentFile,
80+
LaunchScript,
81+
InteractiveSession,
82+
AttachHostProcess,
83+
}
8284

8385
const debugConfigPickItems = [
8486
{
85-
id: launchCurrentFileId,
87+
id: DebugConfig.LaunchCurrentFile,
8688
label: "Launch Current File",
8789
description: "Launch and debug the file in the currently active editor window",
8890
},
8991
{
90-
id: launchScriptId,
92+
id: DebugConfig.LaunchScript,
9193
label: "Launch Script",
9294
description: "Launch and debug the specified file or command",
9395
},
9496
{
95-
id: interactiveSessionId,
97+
id: DebugConfig.InteractiveSession,
9698
label: "Interactive Session",
9799
description: "Debug commands executed from the Integrated Console",
98100
},
99101
{
100-
id: attachHostProcessId,
102+
id: DebugConfig.AttachHostProcess,
101103
label: "Attach",
102104
description: "Attach the debugger to a running PowerShell Host Process",
103105
},
@@ -108,50 +110,46 @@ export class DebugSessionFeature extends LanguageClientConsumer
108110
debugConfigPickItems,
109111
{ placeHolder: "Select a PowerShell debug configuration" });
110112

111-
if (launchSelection.id === launchCurrentFileId) {
112-
return [
113-
{
114-
name: "PowerShell: Launch Current File",
115-
type: "PowerShell",
116-
request: "launch",
117-
script: "${file}",
118-
cwd: "${file}",
119-
},
120-
];
121-
}
122-
123-
if (launchSelection.id === launchScriptId) {
124-
return [
125-
{
126-
name: "PowerShell: Launch Script",
127-
type: "PowerShell",
128-
request: "launch",
129-
script: "enter path or command to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester",
130-
cwd: "${workspaceFolder}",
131-
},
132-
];
133-
}
134-
135-
if (launchSelection.id === interactiveSessionId) {
136-
return [
137-
{
138-
name: "PowerShell: Interactive Session",
139-
type: "PowerShell",
140-
request: "launch",
141-
cwd: "",
142-
},
143-
];
113+
switch (launchSelection.id) {
114+
case DebugConfig.LaunchCurrentFile:
115+
return [
116+
{
117+
name: "PowerShell: Launch Current File",
118+
type: "PowerShell",
119+
request: "launch",
120+
script: "${file}",
121+
cwd: "${file}",
122+
},
123+
];
124+
case DebugConfig.LaunchScript:
125+
return [
126+
{
127+
name: "PowerShell: Launch Script",
128+
type: "PowerShell",
129+
request: "launch",
130+
script: "enter path or command to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester",
131+
cwd: "${workspaceFolder}",
132+
},
133+
];
134+
case DebugConfig.InteractiveSession:
135+
return [
136+
{
137+
name: "PowerShell: Interactive Session",
138+
type: "PowerShell",
139+
request: "launch",
140+
cwd: "",
141+
},
142+
];
143+
case DebugConfig.AttachHostProcess:
144+
return [
145+
{
146+
name: "PowerShell: Attach to PowerShell Host Process",
147+
type: "PowerShell",
148+
request: "attach",
149+
runspaceId: 1,
150+
},
151+
];
144152
}
145-
146-
// Last remaining possibility is attach to host process
147-
return [
148-
{
149-
name: "PowerShell: Attach to PowerShell Host Process",
150-
type: "PowerShell",
151-
request: "attach",
152-
runspaceId: 1,
153-
},
154-
];
155153
}
156154

157155
// DebugConfigurationProvider method
@@ -161,6 +159,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
161159
token?: CancellationToken): Promise<DebugConfiguration> {
162160

163161
// Make sure there is a session running before attempting to debug/run a program
162+
// TODO: Perhaps this should just wait until it's running or aborted.
164163
if (this.sessionManager.getSessionStatus() !== SessionStatus.Running) {
165164
const msg = "Cannot debug or run a PowerShell script until the PowerShell session has started. " +
166165
"Wait for the PowerShell session to finish starting and try again.";

0 commit comments

Comments
 (0)