private void OnWorkspaceInitialized(object sender, PythonWorkspaceContextEventArgs e) { var workspace = e.Workspace; _infoBarCheckTriggered = false; _packageInstallInfoBar = new PackageInstallWorkspaceInfoBar(_serviceProvider, workspace); _condaEnvCreateInfoBar = new CondaEnvCreateWorkspaceInfoBar(_serviceProvider, workspace); _virtualEnvCreateInfoBar = new VirtualEnvCreateWorkspaceInfoBar(_serviceProvider, workspace); _testFrameworkInfoBar = new TestFrameworkWorkspaceInfoBar(_serviceProvider, workspace); _pythonVersionNotSupportedInfoBar = new PythonNotSupportedInfoBar(_serviceProvider, InfoBarContexts.Workspace, () => workspace.CurrentFactory); workspace.AddActionOnClose(_packageInstallInfoBar, (obj => ((PythonInfoBar)obj).Dispose())); workspace.AddActionOnClose(_condaEnvCreateInfoBar, (obj => ((PythonInfoBar)obj).Dispose())); workspace.AddActionOnClose(_virtualEnvCreateInfoBar, (obj => ((PythonInfoBar)obj).Dispose())); workspace.AddActionOnClose(_testFrameworkInfoBar, (obj => ((PythonInfoBar)obj).Dispose())); workspace.AddActionOnClose( _pythonVersionNotSupportedInfoBar, obj => { ((PythonInfoBar)obj).Dispose(); workspace.ActiveInterpreterChanged -= TriggerPythonNotSupportedInforBar; } ); workspace.AddActionOnClose( _untrustedWorkspaceInfoBar, obj => { ((PythonInfoBar)obj).Dispose(); workspace.IsTrustedQueried -= TriggerUntrustedWorkspaceInfoBar; } ); workspace.ActiveInterpreterChanged += TriggerPythonNotSupportedInforBar; // When we see a Python file opened in the workspace, we trigger info bar checks. // Python files may have already been opened by the time this runs, so we'll check // the already loaded files first. If there are no Python file that trigger info bar // checks, then we'll register to be notified when files are opened. if (ErrorHandler.Succeeded(_docTable.GetRunningDocumentsEnum(out var pEnumRdt))) { if (ErrorHandler.Succeeded(pEnumRdt.Reset())) { uint[] cookie = new uint[1]; while (VSConstants.S_OK == pEnumRdt.Next(1, cookie, out _)) { var docFilePath = GetDocumentFilePath(cookie[0]); if (IsWorkspacePythonFile(docFilePath)) { TriggerInfoBar(); break; } } } } if (!_infoBarCheckTriggered) { if (ErrorHandler.Succeeded(_docTable.AdviseRunningDocTableEvents(this, out uint eventCookie))) { workspace.AddActionOnClose(_docTable, obj => _docTable.UnadviseRunningDocTableEvents(eventCookie)); } } }