11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4- import { Disposable , EventEmitter , Event , Uri } from 'vscode' ;
4+ import { Disposable , EventEmitter , Event , Uri , LogOutputChannel } from 'vscode' ;
55import * as ch from 'child_process' ;
66import * as path from 'path' ;
77import * as rpc from 'vscode-jsonrpc/node' ;
@@ -29,7 +29,7 @@ export interface NativeEnvInfo {
2929 displayName ?: string ;
3030 name ?: string ;
3131 executable ?: string ;
32- kind : string ;
32+ kind ? : string ;
3333 version ?: string ;
3434 prefix ?: string ;
3535 manager ?: NativeEnvManagerInfo ;
@@ -57,10 +57,11 @@ export type NativeCondaInfo = {
5757 environmentsFromTxt : string [ ] ;
5858} ;
5959
60- export interface NativeGlobalPythonFinder extends Disposable {
60+ export interface NativePythonFinder extends Disposable {
6161 resolve ( executable : string ) : Promise < NativeEnvInfo > ;
6262 refresh ( ) : AsyncIterable < NativeEnvInfo > ;
6363 categoryToKind ( category ?: string ) : PythonEnvKind ;
64+ logger ( ) : LogOutputChannel ;
6465 getCondaInfo ( ) : Promise < NativeCondaInfo > ;
6566 find ( searchPath : string ) : Promise < NativeEnvInfo [ ] > ;
6667}
@@ -70,7 +71,7 @@ interface NativeLog {
7071 message : string ;
7172}
7273
73- class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGlobalPythonFinder {
74+ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativePythonFinder {
7475 private readonly connection : rpc . MessageConnection ;
7576
7677 private firstRefreshResults : undefined | ( ( ) => AsyncGenerator < NativeEnvInfo , void , unknown > ) ;
@@ -172,6 +173,10 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
172173 }
173174 }
174175
176+ logger ( ) : LogOutputChannel {
177+ return this . outputChannel ;
178+ }
179+
175180 refreshFirstTime ( ) {
176181 const result = this . doRefresh ( ) ;
177182 const completed = createDeferredFrom ( result . completed ) ;
@@ -304,7 +309,6 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
304309 disposable . add (
305310 this . connection . onNotification ( 'environment' , ( data : NativeEnvInfo ) => {
306311 this . outputChannel . info ( `Discovered env: ${ data . executable || data . prefix } ` ) ;
307- this . outputChannel . trace ( `Discovered env info:\n ${ JSON . stringify ( data , undefined , 4 ) } ` ) ;
308312 // We know that in the Python extension if either Version of Prefix is not provided by locator
309313 // Then we end up resolving the information.
310314 // Lets do that here,
@@ -321,7 +325,6 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
321325 } )
322326 . then ( ( environment ) => {
323327 this . outputChannel . info ( `Resolved ${ environment . executable } ` ) ;
324- this . outputChannel . trace ( `Environment resolved:\n ${ JSON . stringify ( data , undefined , 4 ) } ` ) ;
325328 discovered . fire ( environment ) ;
326329 } )
327330 . 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
419422 return value ;
420423}
421424
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 ;
424431}
0 commit comments