@@ -64,11 +64,11 @@ export class SessionManager {
6464 private hostVersion : string ;
6565 private isWindowsOS : boolean ;
6666 private sessionStatus : SessionStatus ;
67- private powerShellProcess : cp . ChildProcess ;
6867 private statusBarItem : vscode . StatusBarItem ;
6968 private sessionConfiguration : SessionConfiguration ;
7069 private versionDetails : PowerShellVersionDetails ;
7170 private registeredCommands : vscode . Disposable [ ] = [ ] ;
71+ private consoleTerminal : vscode . Terminal = undefined ;
7272 private languageServerClient : LanguageClient = undefined ;
7373 private sessionSettings : Settings . ISettings = undefined ;
7474
@@ -136,7 +136,8 @@ export class SessionManager {
136136 "-HostName 'Visual Studio Code Host' " +
137137 "-HostProfileId 'Microsoft.VSCode' " +
138138 "-HostVersion '" + this . hostVersion + "' " +
139- "-BundledModulesPath '" + bundledModulesPath + "' " ;
139+ "-BundledModulesPath '" + bundledModulesPath + "' " +
140+ "-EnableConsoleRepl " ;
140141
141142 if ( this . sessionSettings . developer . editorServicesWaitForDebugger ) {
142143 startArgs += '-WaitForDebugger ' ;
@@ -169,7 +170,7 @@ export class SessionManager {
169170 // Before moving further, clear out the client and process if
170171 // the process is already dead (i.e. it crashed)
171172 this . languageServerClient = undefined ;
172- this . powerShellProcess = undefined ;
173+ this . consoleTerminal = undefined ;
173174 }
174175
175176 this . sessionStatus = SessionStatus . Stopping ;
@@ -184,10 +185,10 @@ export class SessionManager {
184185 utils . deleteSessionFile ( ) ;
185186
186187 // Kill the PowerShell process we spawned via the console
187- if ( this . powerShellProcess !== undefined ) {
188+ if ( this . consoleTerminal !== undefined ) {
188189 this . log . write ( os . EOL + "Terminating PowerShell process..." ) ;
189- this . powerShellProcess . kill ( ) ;
190- this . powerShellProcess = undefined ;
190+ this . consoleTerminal . dispose ( ) ;
191+ this . consoleTerminal = undefined ;
191192 }
192193
193194 this . sessionStatus = SessionStatus . NotStarted ;
@@ -242,7 +243,8 @@ export class SessionManager {
242243 this . registeredCommands = [
243244 vscode . commands . registerCommand ( 'PowerShell.RestartSession' , ( ) => { this . restartSession ( ) ; } ) ,
244245 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 ( ) ; } )
246248 ]
247249 }
248250
@@ -264,7 +266,9 @@ export class SessionManager {
264266
265267 var editorServicesLogPath = this . log . getLogFilePath ( "EditorServices" ) ;
266268
267- startArgs += "-LogPath '" + editorServicesLogPath + "' " ;
269+ startArgs +=
270+ "-LogPath '" + editorServicesLogPath + "' " +
271+ "-SessionDetailsPath '" + utils . getSessionFilePath ( ) + "' " ;
268272
269273 var powerShellArgs = [
270274 "-NoProfile" ,
@@ -291,57 +295,63 @@ export class SessionManager {
291295 delete process . env . DEVPATH ;
292296 }
293297
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" ,
297305 powerShellExePath ,
298- powerShellArgs ,
299- { env : process . env } ) ;
306+ powerShellArgs ) ;
300307
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 ( ) ;
307309
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 ) ;
310317
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+ }
318329 }
319330 else {
320- this . setSessionFailure ( `PowerShell could not be started for an unknown reason ' ${ response [ "reason" ] } '` )
331+ // TODO: Handle other response cases
321332 }
322333 }
323334 else {
324- // TODO: Handle other response cases
335+ this . setSessionFailure ( "Could not start language service: " , error ) ;
325336 }
326337 } ) ;
327338
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);
332343
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+ // });
340351
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 ) ;
345355
346356 if ( this . languageServerClient != undefined ) {
347357 this . languageServerClient . stop ( ) ;
@@ -353,13 +363,15 @@ export class SessionManager {
353363 }
354364 } ) ;
355365
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+ } ) ;
363375 }
364376 catch ( e )
365377 {
@@ -595,6 +607,12 @@ export class SessionManager {
595607 return resolvedPath ;
596608 }
597609
610+ private showSessionConsole ( ) {
611+ if ( this . consoleTerminal ) {
612+ this . consoleTerminal . show ( ) ;
613+ }
614+ }
615+
598616 private showSessionMenu ( ) {
599617 var menuItems : SessionMenuItem [ ] = [ ] ;
600618
0 commit comments