@@ -75,29 +75,31 @@ export class DebugSessionFeature extends LanguageClientConsumer
75
75
folder : WorkspaceFolder | undefined ,
76
76
token ?: CancellationToken ) : Promise < DebugConfiguration [ ] > {
77
77
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
+ }
82
84
83
85
const debugConfigPickItems = [
84
86
{
85
- id : launchCurrentFileId ,
87
+ id : DebugConfig . LaunchCurrentFile ,
86
88
label : "Launch Current File" ,
87
89
description : "Launch and debug the file in the currently active editor window" ,
88
90
} ,
89
91
{
90
- id : launchScriptId ,
92
+ id : DebugConfig . LaunchScript ,
91
93
label : "Launch Script" ,
92
94
description : "Launch and debug the specified file or command" ,
93
95
} ,
94
96
{
95
- id : interactiveSessionId ,
97
+ id : DebugConfig . InteractiveSession ,
96
98
label : "Interactive Session" ,
97
99
description : "Debug commands executed from the Integrated Console" ,
98
100
} ,
99
101
{
100
- id : attachHostProcessId ,
102
+ id : DebugConfig . AttachHostProcess ,
101
103
label : "Attach" ,
102
104
description : "Attach the debugger to a running PowerShell Host Process" ,
103
105
} ,
@@ -108,50 +110,46 @@ export class DebugSessionFeature extends LanguageClientConsumer
108
110
debugConfigPickItems ,
109
111
{ placeHolder : "Select a PowerShell debug configuration" } ) ;
110
112
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
+ ] ;
144
152
}
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
- ] ;
155
153
}
156
154
157
155
// DebugConfigurationProvider method
@@ -161,6 +159,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
161
159
token ?: CancellationToken ) : Promise < DebugConfiguration > {
162
160
163
161
// 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.
164
163
if ( this . sessionManager . getSessionStatus ( ) !== SessionStatus . Running ) {
165
164
const msg = "Cannot debug or run a PowerShell script until the PowerShell session has started. " +
166
165
"Wait for the PowerShell session to finish starting and try again." ;
0 commit comments