@@ -47,39 +47,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
47
47
restartOnExtensionFileChanges ( context ) ;
48
48
}
49
49
50
- // Register a command that waits for the Externsion Terminal to be active. Can be used by .NET Attach Tasks
51
- vscode . commands . registerCommand (
52
- "PowerShell.WaitForPsesActivationAndReturnProcessId" ,
53
- async ( ) => {
54
- const pidFileName = `PSES-${ vscode . env . sessionId } .pid` ;
55
- const pidFile = vscode . Uri . joinPath ( context . globalStorageUri , "sessions" , pidFileName ) ;
56
- const fs = vscode . workspace . fs ;
57
- // Wait for the file to be created
58
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
59
- while ( true ) {
60
- try {
61
- const pidContent = await fs . readFile ( pidFile ) ;
62
- const pid = parseInt ( pidContent . toString ( ) , 10 ) ;
63
- try {
64
- // Check if the process is still alive, delete the PID file if not and continue waiting.
65
- process . kill ( pid , 0 ) ;
66
- } catch {
67
- await fs . delete ( pidFile ) ;
68
- continue ;
69
- }
70
- return pidContent . toString ( ) ;
71
- } catch {
72
- // File doesn't exist yet, wait and try again
73
- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
74
- }
75
- }
76
- }
77
- ) ;
78
50
79
- vscode . commands . registerCommand (
80
- "GetVsCodeSessionId" ,
81
- ( ) => vscode . env . sessionId
82
- ) ;
51
+
83
52
84
53
telemetryReporter = new TelemetryReporter ( TELEMETRY_KEY ) ;
85
54
@@ -187,7 +156,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
187
156
vscode . commands . registerCommand (
188
157
"PowerShell.ShowLogs" ,
189
158
( ) => { logger . showLogPanel ( ) ; }
190
- )
159
+ ) ,
160
+ vscode . commands . registerCommand (
161
+ "GetVsCodeSessionId" ,
162
+ ( ) => vscode . env . sessionId
163
+ ) ,
164
+ // Register a command that waits for the Externsion Terminal to be active. Can be used by .NET Attach Tasks
165
+ registerWaitForPsesActivationCommand ( context )
191
166
] ;
192
167
193
168
const externalApi = new ExternalApiFeature ( context , sessionManager , logger ) ;
@@ -220,6 +195,37 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
220
195
} ;
221
196
}
222
197
198
+ /** Registers a command that waits for PSES Activation and returns the PID, used to auto-attach the PSES debugger */
199
+ function registerWaitForPsesActivationCommand ( context : vscode . ExtensionContext ) {
200
+ return vscode . commands . registerCommand (
201
+ "PowerShell.WaitForPsesActivationAndReturnProcessId" ,
202
+ async ( ) => {
203
+ const pidFileName = `PSES-${ vscode . env . sessionId } .pid` ;
204
+ const pidFile = vscode . Uri . joinPath ( context . globalStorageUri , "sessions" , pidFileName ) ;
205
+ const fs = vscode . workspace . fs ;
206
+ // Wait for the file to be created
207
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
208
+ while ( true ) {
209
+ try {
210
+ const pidContent = await fs . readFile ( pidFile ) ;
211
+ const pid = parseInt ( pidContent . toString ( ) , 10 ) ;
212
+ try {
213
+ // Check if the process is still alive, delete the PID file if not and continue waiting.
214
+ process . kill ( pid , 0 ) ;
215
+ } catch {
216
+ await fs . delete ( pidFile ) ;
217
+ continue ;
218
+ }
219
+ return pidContent . toString ( ) ;
220
+ } catch {
221
+ // File doesn't exist yet, wait and try again
222
+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
223
+ }
224
+ }
225
+ }
226
+ ) ;
227
+ }
228
+
223
229
/** Restarts the extension host when extension file changes are detected. Useful for development.. */
224
230
function restartOnExtensionFileChanges ( context : vscode . ExtensionContext ) : void {
225
231
const watcher = vscode . workspace . createFileSystemWatcher (
0 commit comments