1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- import { Disposable , EventEmitter , Event , workspace , Uri } from 'vscode' ;
4
+ import { Disposable , EventEmitter , Event , workspace , window , Uri } 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
8
import { PassThrough } from 'stream' ;
9
9
import { isWindows } from '../../../../common/platform/platformService' ;
10
10
import { EXTENSION_ROOT_DIR } from '../../../../constants' ;
11
- import { traceError , traceInfo , traceLog , traceVerbose , traceWarn } from '../../../../logging' ;
12
11
import { createDeferred , createDeferredFrom } from '../../../../common/utils/async' ;
13
12
import { DisposableBase , DisposableStore } from '../../../../common/utils/resourceLifecycle' ;
14
13
import { DEFAULT_INTERPRETER_PATH_SETTING_KEY } from '../lowLevel/customWorkspaceLocator' ;
@@ -61,6 +60,8 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
61
60
62
61
private firstRefreshResults : undefined | ( ( ) => AsyncGenerator < NativeEnvInfo , void , unknown > ) ;
63
62
63
+ private readonly outputChannel = this . _register ( window . createOutputChannel ( 'Python Locator' , { log : true } ) ) ;
64
+
64
65
constructor ( ) {
65
66
super ( ) ;
66
67
this . connection = this . start ( ) ;
@@ -75,7 +76,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
75
76
executable,
76
77
} ) ;
77
78
78
- traceInfo ( `Resolved Python Environment ${ environment . executable } in ${ duration } ms` ) ;
79
+ this . outputChannel . info ( `Resolved Python Environment ${ environment . executable } in ${ duration } ms` ) ;
79
80
return environment ;
80
81
}
81
82
@@ -152,17 +153,15 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
152
153
153
154
// eslint-disable-next-line class-methods-use-this
154
155
private start ( ) : rpc . MessageConnection {
156
+ this . outputChannel . info ( `Starting Python Locator ${ NATIVE_LOCATOR } server` ) ;
155
157
const proc = ch . spawn ( NATIVE_LOCATOR , [ 'server' ] , { env : process . env } ) ;
156
158
const disposables : Disposable [ ] = [ ] ;
157
159
// jsonrpc package cannot handle messages coming through too quickly.
158
160
// Lets handle the messages and close the stream only when
159
161
// we have got the exit event.
160
162
const readable = new PassThrough ( ) ;
161
163
proc . stdout . pipe ( readable , { end : false } ) ;
162
- proc . stderr . on ( 'data' , ( data ) => {
163
- const err = data . toString ( ) ;
164
- traceError ( 'Native Python Finder' , err ) ;
165
- } ) ;
164
+ proc . stderr . on ( 'data' , ( data ) => this . outputChannel . error ( data . toString ( ) ) ) ;
166
165
const writable = new PassThrough ( ) ;
167
166
writable . pipe ( proc . stdin , { end : false } ) ;
168
167
const disposeStreams = new Disposable ( ( ) => {
@@ -178,24 +177,24 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
178
177
disposeStreams ,
179
178
connection . onError ( ( ex ) => {
180
179
disposeStreams . dispose ( ) ;
181
- traceError ( 'Error in Native Python Finder ', ex ) ;
180
+ this . outputChannel . error ( 'Connection Error: ', ex ) ;
182
181
} ) ,
183
182
connection . onNotification ( 'log' , ( data : NativeLog ) => {
184
183
switch ( data . level ) {
185
184
case 'info' :
186
- traceInfo ( `Native Python Finder: ${ data . message } ` ) ;
185
+ this . outputChannel . info ( data . message ) ;
187
186
break ;
188
187
case 'warning' :
189
- traceWarn ( `Native Python Finder: ${ data . message } ` ) ;
188
+ this . outputChannel . warn ( data . message ) ;
190
189
break ;
191
190
case 'error' :
192
- traceError ( `Native Python Finder: ${ data . message } ` ) ;
191
+ this . outputChannel . error ( data . message ) ;
193
192
break ;
194
193
case 'debug' :
195
- traceVerbose ( `Native Python Finder: ${ data . message } ` ) ;
194
+ this . outputChannel . debug ( data . message ) ;
196
195
break ;
197
196
default :
198
- traceLog ( `Native Python Finder: ${ data . message } ` ) ;
197
+ this . outputChannel . trace ( data . message ) ;
199
198
}
200
199
} ) ,
201
200
connection . onClose ( ( ) => {
@@ -208,7 +207,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
208
207
proc . kill ( ) ;
209
208
}
210
209
} catch ( ex ) {
211
- traceVerbose ( 'Error while disposing Native Python Finder ' , ex ) ;
210
+ this . outputChannel . error ( 'Error disposing finder ' , ex ) ;
212
211
}
213
212
} ,
214
213
} ,
@@ -244,6 +243,8 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
244
243
245
244
disposable . add (
246
245
this . connection . onNotification ( 'environment' , ( data : NativeEnvInfo ) => {
246
+ this . outputChannel . info ( `Discovered env: ${ data . executable || data . executable } ` ) ;
247
+ this . outputChannel . trace ( `Discovered env info:\n ${ JSON . stringify ( data , undefined , 4 ) } ` ) ;
247
248
// We know that in the Python extension if either Version of Prefix is not provided by locator
248
249
// Then we end up resolving the information.
249
250
// Lets do that here,
@@ -259,10 +260,11 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
259
260
executable : data . executable ,
260
261
} )
261
262
. then ( ( { environment, duration } ) => {
262
- traceInfo ( `Resolved Python Environment ${ environment . executable } in ${ duration } ms` ) ;
263
+ this . outputChannel . info ( `Resolved ${ environment . executable } in ${ duration } ms` ) ;
264
+ this . outputChannel . trace ( `Environment resolved:\n ${ JSON . stringify ( data , undefined , 4 ) } ` ) ;
263
265
discovered . fire ( environment ) ;
264
266
} )
265
- . catch ( ( ex ) => traceError ( `Error in Resolving Python Environment ${ JSON . stringify ( data ) } ` , ex ) ) ;
267
+ . catch ( ( ex ) => this . outputChannel . error ( `Error in Resolving ${ JSON . stringify ( data ) } ` , ex ) ) ;
266
268
trackPromiseAndNotifyOnCompletion ( promise ) ;
267
269
} else {
268
270
discovered . fire ( data ) ;
@@ -272,8 +274,8 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
272
274
273
275
trackPromiseAndNotifyOnCompletion (
274
276
this . sendRefreshRequest ( )
275
- . then ( ( { duration } ) => traceInfo ( `Native Python Finder completed in ${ duration } ms`) )
276
- . catch ( ( ex ) => traceError ( 'Error in Native Python Finder ', ex ) ) ,
277
+ . then ( ( { duration } ) => this . outputChannel . info ( `Refresh completed in ${ duration } ms`) )
278
+ . catch ( ( ex ) => this . outputChannel . error ( 'Refresh error ', ex ) ) ,
277
279
) ;
278
280
279
281
completed . promise . finally ( ( ) => disposable . dispose ( ) ) ;
0 commit comments