1- import { window , commands , ExtensionContext , LogOutputChannel , TextEditor } from 'vscode' ;
1+ import { commands , ExtensionContext , LogOutputChannel } from 'vscode' ;
22
33import { PythonEnvironmentManagers } from './features/envManagers' ;
44import { registerLogger } from './common/logging' ;
@@ -28,9 +28,8 @@ import { PythonProjectManagerImpl } from './features/projectManager';
2828import { EnvironmentManagers , ProjectCreators , PythonProjectManager } from './internal.api' ;
2929import { getPythonApi , setPythonApi } from './features/pythonApi' ;
3030import { setPersistentState } from './common/persistentState' ;
31- import { isPythonProjectFile } from './common/utils/fileNameUtils' ;
3231import { createNativePythonFinder , NativePythonFinder } from './managers/common/nativePythonFinder' ;
33- import { PythonEnvironmentApi , PythonProject } from './api' ;
32+ import { PythonEnvironmentApi } from './api' ;
3433import {
3534 ProjectCreatorsImpl ,
3635 registerAutoProjectProvider ,
@@ -39,21 +38,31 @@ import {
3938import { WorkspaceView } from './features/views/projectView' ;
4039import { registerCompletionProvider } from './features/settings/settingCompletions' ;
4140import { TerminalManager , TerminalManagerImpl } from './features/terminal/terminalManager' ;
42- import { activeTerminal , onDidChangeActiveTerminal , onDidChangeActiveTextEditor } from './common/window.apis' ;
41+ import {
42+ activeTerminal ,
43+ createLogOutputChannel ,
44+ onDidChangeActiveTerminal ,
45+ onDidChangeActiveTextEditor ,
46+ } from './common/window.apis' ;
4347import {
4448 getEnvironmentForTerminal ,
4549 setActivateMenuButtonContext ,
4650 updateActivateMenuButtonContext ,
4751} from './features/terminal/activateMenuButton' ;
52+ import { PythonStatusBarImpl } from './features/views/pythonStatusBar' ;
53+ import { updateViewsAndStatus } from './features/views/revealHandler' ;
4854
4955export async function activate ( context : ExtensionContext ) : Promise < PythonEnvironmentApi > {
5056 // Logging should be set up before anything else.
51- const outputChannel : LogOutputChannel = window . createOutputChannel ( 'Python Environments' , { log : true } ) ;
57+ const outputChannel : LogOutputChannel = createLogOutputChannel ( 'Python Environments' ) ;
5258 context . subscriptions . push ( outputChannel , registerLogger ( outputChannel ) ) ;
5359
5460 // Setup the persistent state for the extension.
5561 setPersistentState ( context ) ;
5662
63+ const statusBar = new PythonStatusBarImpl ( ) ;
64+ context . subscriptions . push ( statusBar ) ;
65+
5766 const terminalManager : TerminalManager = new TerminalManagerImpl ( ) ;
5867 context . subscriptions . push ( terminalManager ) ;
5968
@@ -113,26 +122,14 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
113122 commands . registerCommand ( 'python-envs.set' , async ( item ) => {
114123 const result = await setEnvironmentCommand ( item , envManagers , projectManager ) ;
115124 if ( result ) {
116- const projects : PythonProject [ ] = [ ] ;
117- result . forEach ( ( r ) => {
118- if ( r . project ) {
119- projects . push ( r . project ) ;
120- }
121- } ) ;
122- workspaceView . updateProject ( projects ) ;
125+ workspaceView . updateProject ( ) ;
123126 await updateActivateMenuButtonContext ( terminalManager , projectManager , envManagers ) ;
124127 }
125128 } ) ,
126129 commands . registerCommand ( 'python-envs.setEnv' , async ( item ) => {
127130 const result = await setEnvironmentCommand ( item , envManagers , projectManager ) ;
128131 if ( result ) {
129- const projects : PythonProject [ ] = [ ] ;
130- result . forEach ( ( r ) => {
131- if ( r . project ) {
132- projects . push ( r . project ) ;
133- }
134- } ) ;
135- workspaceView . updateProject ( projects ) ;
132+ workspaceView . updateProject ( ) ;
136133 await updateActivateMenuButtonContext ( terminalManager , projectManager , envManagers ) ;
137134 }
138135 } ) ,
@@ -193,38 +190,14 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
193190 onDidChangeActiveTerminal ( async ( t ) => {
194191 await updateActivateMenuButtonContext ( terminalManager , projectManager , envManagers , t ) ;
195192 } ) ,
196- onDidChangeActiveTextEditor ( async ( e : TextEditor | undefined ) => {
197- if ( e && ! e . document . isUntitled && e . document . uri . scheme === 'file' ) {
198- if (
199- e . document . languageId === 'python' ||
200- e . document . languageId === 'pip-requirements' ||
201- isPythonProjectFile ( e . document . uri . fsPath )
202- ) {
203- const env = await workspaceView . reveal ( e . document . uri ) ;
204- await managerView . reveal ( env ) ;
205- }
206- }
193+ onDidChangeActiveTextEditor ( async ( ) => {
194+ updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
207195 } ) ,
208- envManagers . onDidChangeEnvironment ( async ( e ) => {
209- const activeDocument = window . activeTextEditor ?. document ;
210- if ( ! activeDocument || activeDocument . isUntitled || activeDocument . uri . scheme !== 'file' ) {
211- return ;
212- }
213-
214- if (
215- activeDocument . languageId !== 'python' &&
216- activeDocument . languageId !== 'pip-requirements' &&
217- ! isPythonProjectFile ( activeDocument . uri . fsPath )
218- ) {
219- return ;
220- }
221-
222- const mgr1 = envManagers . getEnvironmentManager ( e . uri ) ;
223- const mgr2 = envManagers . getEnvironmentManager ( activeDocument . uri ) ;
224- if ( mgr1 === mgr2 && e . new ) {
225- const env = await workspaceView . reveal ( activeDocument . uri ) ;
226- await managerView . reveal ( env ) ;
227- }
196+ envManagers . onDidChangeEnvironment ( async ( ) => {
197+ updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
198+ } ) ,
199+ envManagers . onDidChangeEnvironments ( async ( ) => {
200+ updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
228201 } ) ,
229202 ) ;
230203
0 commit comments