1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- import { Disposable , EventEmitter , Event , Uri } from 'vscode' ;
4
+ import { Disposable , EventEmitter , Event , Uri , LogOutputChannel } 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' ;
@@ -29,7 +29,7 @@ export interface NativeEnvInfo {
29
29
displayName ?: string ;
30
30
name ?: string ;
31
31
executable ?: string ;
32
- kind : string ;
32
+ kind ? : string ;
33
33
version ?: string ;
34
34
prefix ?: string ;
35
35
manager ?: NativeEnvManagerInfo ;
@@ -57,10 +57,11 @@ export type NativeCondaInfo = {
57
57
environmentsFromTxt : string [ ] ;
58
58
} ;
59
59
60
- export interface NativeGlobalPythonFinder extends Disposable {
60
+ export interface NativePythonFinder extends Disposable {
61
61
resolve ( executable : string ) : Promise < NativeEnvInfo > ;
62
62
refresh ( ) : AsyncIterable < NativeEnvInfo > ;
63
63
categoryToKind ( category ?: string ) : PythonEnvKind ;
64
+ logger ( ) : LogOutputChannel ;
64
65
getCondaInfo ( ) : Promise < NativeCondaInfo > ;
65
66
find ( searchPath : string ) : Promise < NativeEnvInfo [ ] > ;
66
67
}
@@ -70,7 +71,7 @@ interface NativeLog {
70
71
message : string ;
71
72
}
72
73
73
- class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGlobalPythonFinder {
74
+ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePythonFinder {
74
75
private readonly connection : rpc . MessageConnection ;
75
76
76
77
private firstRefreshResults : undefined | ( ( ) => AsyncGenerator < NativeEnvInfo , void , unknown > ) ;
@@ -172,6 +173,10 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
172
173
}
173
174
}
174
175
176
+ logger ( ) : LogOutputChannel {
177
+ return this . outputChannel ;
178
+ }
179
+
175
180
refreshFirstTime ( ) {
176
181
const result = this . doRefresh ( ) ;
177
182
const completed = createDeferredFrom ( result . completed ) ;
@@ -304,7 +309,6 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
304
309
disposable . add (
305
310
this . connection . onNotification ( 'environment' , ( data : NativeEnvInfo ) => {
306
311
this . outputChannel . info ( `Discovered env: ${ data . executable || data . prefix } ` ) ;
307
- this . outputChannel . trace ( `Discovered env info:\n ${ JSON . stringify ( data , undefined , 4 ) } ` ) ;
308
312
// We know that in the Python extension if either Version of Prefix is not provided by locator
309
313
// Then we end up resolving the information.
310
314
// Lets do that here,
@@ -321,7 +325,6 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
321
325
} )
322
326
. then ( ( environment ) => {
323
327
this . outputChannel . info ( `Resolved ${ environment . executable } ` ) ;
324
- this . outputChannel . trace ( `Environment resolved:\n ${ JSON . stringify ( data , undefined , 4 ) } ` ) ;
325
328
discovered . fire ( environment ) ;
326
329
} )
327
330
. catch ( ( ex ) => this . outputChannel . error ( `Error in Resolving ${ JSON . stringify ( data ) } ` , ex ) ) ;
@@ -419,6 +422,10 @@ function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefin
419
422
return value ;
420
423
}
421
424
422
- export function createNativeGlobalPythonFinder ( ) : NativeGlobalPythonFinder {
423
- return new NativeGlobalPythonFinderImpl ( ) ;
425
+ let _finder : NativePythonFinder | undefined ;
426
+ export function getNativePythonFinder ( ) : NativePythonFinder {
427
+ if ( ! _finder ) {
428
+ _finder = new NativeGlobalPythonFinderImpl ( ) ;
429
+ }
430
+ return _finder ;
424
431
}
0 commit comments