@@ -64,11 +64,11 @@ export class SessionManager {
64
64
private hostVersion : string ;
65
65
private isWindowsOS : boolean ;
66
66
private sessionStatus : SessionStatus ;
67
- private powerShellProcess : cp . ChildProcess ;
68
67
private statusBarItem : vscode . StatusBarItem ;
69
68
private sessionConfiguration : SessionConfiguration ;
70
69
private versionDetails : PowerShellVersionDetails ;
71
70
private registeredCommands : vscode . Disposable [ ] = [ ] ;
71
+ private consoleTerminal : vscode . Terminal = undefined ;
72
72
private languageServerClient : LanguageClient = undefined ;
73
73
private sessionSettings : Settings . ISettings = undefined ;
74
74
@@ -136,7 +136,8 @@ export class SessionManager {
136
136
"-HostName 'Visual Studio Code Host' " +
137
137
"-HostProfileId 'Microsoft.VSCode' " +
138
138
"-HostVersion '" + this . hostVersion + "' " +
139
- "-BundledModulesPath '" + bundledModulesPath + "' " ;
139
+ "-BundledModulesPath '" + bundledModulesPath + "' " +
140
+ "-EnableConsoleRepl " ;
140
141
141
142
if ( this . sessionSettings . developer . editorServicesWaitForDebugger ) {
142
143
startArgs += '-WaitForDebugger ' ;
@@ -169,7 +170,7 @@ export class SessionManager {
169
170
// Before moving further, clear out the client and process if
170
171
// the process is already dead (i.e. it crashed)
171
172
this . languageServerClient = undefined ;
172
- this . powerShellProcess = undefined ;
173
+ this . consoleTerminal = undefined ;
173
174
}
174
175
175
176
this . sessionStatus = SessionStatus . Stopping ;
@@ -184,10 +185,10 @@ export class SessionManager {
184
185
utils . deleteSessionFile ( ) ;
185
186
186
187
// Kill the PowerShell process we spawned via the console
187
- if ( this . powerShellProcess !== undefined ) {
188
+ if ( this . consoleTerminal !== undefined ) {
188
189
this . log . write ( os . EOL + "Terminating PowerShell process..." ) ;
189
- this . powerShellProcess . kill ( ) ;
190
- this . powerShellProcess = undefined ;
190
+ this . consoleTerminal . dispose ( ) ;
191
+ this . consoleTerminal = undefined ;
191
192
}
192
193
193
194
this . sessionStatus = SessionStatus . NotStarted ;
@@ -242,7 +243,8 @@ export class SessionManager {
242
243
this . registeredCommands = [
243
244
vscode . commands . registerCommand ( 'PowerShell.RestartSession' , ( ) => { this . restartSession ( ) ; } ) ,
244
245
vscode . commands . registerCommand ( this . ShowSessionMenuCommandName , ( ) => { this . showSessionMenu ( ) ; } ) ,
245
- vscode . workspace . onDidChangeConfiguration ( ( ) => this . onConfigurationUpdated ( ) )
246
+ vscode . workspace . onDidChangeConfiguration ( ( ) => this . onConfigurationUpdated ( ) ) ,
247
+ vscode . commands . registerCommand ( 'PowerShell.ShowSessionConsole' , ( ) => { this . showSessionConsole ( ) ; } )
246
248
]
247
249
}
248
250
@@ -264,7 +266,9 @@ export class SessionManager {
264
266
265
267
var editorServicesLogPath = this . log . getLogFilePath ( "EditorServices" ) ;
266
268
267
- startArgs += "-LogPath '" + editorServicesLogPath + "' " ;
269
+ startArgs +=
270
+ "-LogPath '" + editorServicesLogPath + "' " +
271
+ "-SessionDetailsPath '" + utils . getSessionFilePath ( ) + "' " ;
268
272
269
273
var powerShellArgs = [
270
274
"-NoProfile" ,
@@ -291,57 +295,63 @@ export class SessionManager {
291
295
delete process . env . DEVPATH ;
292
296
}
293
297
294
- // Launch PowerShell as child process
295
- this . powerShellProcess =
296
- cp . spawn (
298
+ // Make sure no old session file exists
299
+ utils . deleteSessionFile ( ) ;
300
+
301
+ // Launch PowerShell in the integrated terminal
302
+ this . consoleTerminal =
303
+ vscode . window . createTerminal (
304
+ "PowerShell Integrated Console" ,
297
305
powerShellExePath ,
298
- powerShellArgs ,
299
- { env : process . env } ) ;
306
+ powerShellArgs ) ;
300
307
301
- var decoder = new StringDecoder ( 'utf8' ) ;
302
- this . powerShellProcess . stdout . on (
303
- 'data' ,
304
- ( data : Buffer ) => {
305
- this . log . write ( "OUTPUT: " + data ) ;
306
- var response = JSON . parse ( decoder . write ( data ) . trim ( ) ) ;
308
+ this . consoleTerminal . show ( ) ;
307
309
308
- if ( response [ "status" ] === "started" ) {
309
- let sessionDetails : utils . EditorServicesSessionDetails = response ;
310
+ // Start the language client
311
+ utils . waitForSessionFile (
312
+ ( sessionDetails , error ) => {
313
+ if ( sessionDetails ) {
314
+ if ( sessionDetails . status === "started" ) {
315
+ // Write out the session configuration file
316
+ utils . writeSessionFile ( sessionDetails ) ;
310
317
311
- // Start the language service client
312
- this . startLanguageClient ( sessionDetails ) ;
313
- }
314
- else if ( response [ "status" ] === "failed" ) {
315
- if ( response [ "reason" ] === "unsupported" ) {
316
- this . setSessionFailure (
317
- `PowerShell language features are only supported on PowerShell version 3 and above. The current version is ${ response [ "powerShellVersion" ] } .` )
318
+ // Start the language service client
319
+ this . startLanguageClient ( sessionDetails ) ;
320
+ }
321
+ else if ( sessionDetails . status === "failed" ) {
322
+ if ( sessionDetails . reason === "unsupported" ) {
323
+ this . setSessionFailure (
324
+ `PowerShell language features are only supported on PowerShell version 3 and above. The current version is ${ sessionDetails . powerShellVersion } .` )
325
+ }
326
+ else {
327
+ this . setSessionFailure ( `PowerShell could not be started for an unknown reason '${ sessionDetails . reason } '` )
328
+ }
318
329
}
319
330
else {
320
- this . setSessionFailure ( `PowerShell could not be started for an unknown reason ' ${ response [ "reason" ] } '` )
331
+ // TODO: Handle other response cases
321
332
}
322
333
}
323
334
else {
324
- // TODO: Handle other response cases
335
+ this . setSessionFailure ( "Could not start language service: " , error ) ;
325
336
}
326
337
} ) ;
327
338
328
- this . powerShellProcess . stderr . on (
329
- 'data' ,
330
- ( data ) => {
331
- this . log . writeError ( "ERROR: " + data ) ;
339
+ // this.powerShellProcess.stderr.on(
340
+ // 'data',
341
+ // (data) => {
342
+ // this.log.writeError("ERROR: " + data);
332
343
333
- if ( this . sessionStatus === SessionStatus . Initializing ) {
334
- this . setSessionFailure ( "PowerShell could not be started, click 'Show Logs' for more details." ) ;
335
- }
336
- else if ( this . sessionStatus === SessionStatus . Running ) {
337
- this . promptForRestart ( ) ;
338
- }
339
- } ) ;
344
+ // if (this.sessionStatus === SessionStatus.Initializing) {
345
+ // this.setSessionFailure("PowerShell could not be started, click 'Show Logs' for more details.");
346
+ // }
347
+ // else if (this.sessionStatus === SessionStatus.Running) {
348
+ // this.promptForRestart();
349
+ // }
350
+ // });
340
351
341
- this . powerShellProcess . on (
342
- 'close' ,
343
- ( exitCode ) => {
344
- this . log . write ( os . EOL + "powershell.exe terminated with exit code: " + exitCode + os . EOL ) ;
352
+ vscode . window . onDidCloseTerminal (
353
+ terminal => {
354
+ this . log . write ( os . EOL + "powershell.exe terminated or terminal UI was closed" + os . EOL ) ;
345
355
346
356
if ( this . languageServerClient != undefined ) {
347
357
this . languageServerClient . stop ( ) ;
@@ -353,13 +363,15 @@ export class SessionManager {
353
363
}
354
364
} ) ;
355
365
356
- console . log ( "powershell.exe started, pid: " + this . powerShellProcess . pid + ", exe: " + powerShellExePath ) ;
357
- this . log . write (
358
- "powershell.exe started --" ,
359
- " pid: " + this . powerShellProcess . pid ,
360
- " exe: " + powerShellExePath ,
361
- " bundledModulesPath: " + bundledModulesPath ,
362
- " args: " + startScriptPath + ' ' + startArgs + os . EOL + os . EOL ) ;
366
+ this . consoleTerminal . processId . then (
367
+ pid => {
368
+ console . log ( "powershell.exe started, pid: " + pid + ", exe: " + powerShellExePath ) ;
369
+ this . log . write (
370
+ "powershell.exe started --" ,
371
+ " pid: " + pid ,
372
+ " exe: " + powerShellExePath ,
373
+ " args: " + startScriptPath + ' ' + startArgs + os . EOL + os . EOL ) ;
374
+ } ) ;
363
375
}
364
376
catch ( e )
365
377
{
@@ -595,6 +607,12 @@ export class SessionManager {
595
607
return resolvedPath ;
596
608
}
597
609
610
+ private showSessionConsole ( ) {
611
+ if ( this . consoleTerminal ) {
612
+ this . consoleTerminal . show ( ) ;
613
+ }
614
+ }
615
+
598
616
private showSessionMenu ( ) {
599
617
var menuItems : SessionMenuItem [ ] = [ ] ;
600
618
0 commit comments