@@ -5,6 +5,7 @@ import { CancellationToken, Disposable, Event, EventEmitter } from 'vscode';
5
5
import * as ch from 'child_process' ;
6
6
import * as path from 'path' ;
7
7
import * as rpc from 'vscode-jsonrpc/node' ;
8
+ import { PassThrough } from 'stream' ;
8
9
import { isWindows } from '../../../../common/platform/platformService' ;
9
10
import { EXTENSION_ROOT_DIR } from '../../../../constants' ;
10
11
import { traceError , traceInfo , traceLog , traceVerbose , traceWarn } from '../../../../logging' ;
@@ -56,24 +57,43 @@ class NativeGlobalPythonFinderImpl implements NativeGlobalPythonFinder {
56
57
57
58
public startSearch ( token ?: CancellationToken ) : Promise < void > {
58
59
const deferred = createDeferred < void > ( ) ;
59
- const proc = ch . spawn ( NATIVE_LOCATOR , [ ] , { stdio : 'pipe' } ) ;
60
+ const proc = ch . spawn ( NATIVE_LOCATOR , [ ] , { env : process . env } ) ;
60
61
const disposables : Disposable [ ] = [ ] ;
61
62
63
+ // jsonrpc package cannot handle messages coming through too quicly.
64
+ // Lets handle the messages and close the stream only when
65
+ // we have got the exit event.
66
+ const readable = new PassThrough ( ) ;
67
+ proc . stdout . pipe ( readable , { end : false } ) ;
68
+ const writable = new PassThrough ( ) ;
69
+ writable . pipe ( proc . stdin , { end : false } ) ;
70
+ const disposeStreams = new Disposable ( ( ) => {
71
+ readable . end ( ) ;
72
+ readable . destroy ( ) ;
73
+ writable . end ( ) ;
74
+ writable . destroy ( ) ;
75
+ } ) ;
62
76
const connection = rpc . createMessageConnection (
63
- new rpc . StreamMessageReader ( proc . stdout ) ,
64
- new rpc . StreamMessageWriter ( proc . stdin ) ,
77
+ new rpc . StreamMessageReader ( readable ) ,
78
+ new rpc . StreamMessageWriter ( writable ) ,
65
79
) ;
66
80
67
81
disposables . push (
68
82
connection ,
83
+ disposeStreams ,
84
+ connection . onError ( ( ex ) => {
85
+ disposeStreams . dispose ( ) ;
86
+ traceError ( 'Error in Native Python Finder' , ex ) ;
87
+ } ) ,
69
88
connection . onNotification ( 'pythonEnvironment' , ( data : NativeEnvInfo ) => {
70
89
this . _onDidFindPythonEnvironment . fire ( data ) ;
71
90
} ) ,
72
91
connection . onNotification ( 'envManager' , ( data : NativeEnvManagerInfo ) => {
73
92
this . _onDidFindEnvironmentManager . fire ( data ) ;
74
93
} ) ,
75
94
connection . onNotification ( 'exit' , ( ) => {
76
- traceVerbose ( 'Native Python Finder exited' ) ;
95
+ traceInfo ( 'Native Python Finder exited' ) ;
96
+ disposeStreams . dispose ( ) ;
77
97
} ) ,
78
98
connection . onNotification ( 'log' , ( data : NativeLog ) => {
79
99
switch ( data . level ) {
0 commit comments