From 81fbeeae92290d40eef4e0914b57b683b2207f40 Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:08:55 -0500 Subject: [PATCH 1/2] Minimize activation function for Zowe Explorer Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- .../__tests__/__unit__/extension.unit.test.ts | 6 +- .../__unit__/shared/init.unit.test.ts | 26 +++----- packages/zowe-explorer/src/extension.ts | 27 ++------ packages/zowe-explorer/src/shared/init.ts | 63 ++++++++++++++++--- 4 files changed, 70 insertions(+), 52 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts index 205c65fdef..e89c54df1a 100644 --- a/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts @@ -141,8 +141,6 @@ async function createGlobalMocks() { appName: vscode.env.appName, uriScheme: vscode.env.uriScheme, expectedCommands: [ - "zowe.updateSecureCredentials", - "zowe.extRefresh", "zowe.all.config.init", "zowe.ds.addSession", "zowe.ds.addFavorite", @@ -244,6 +242,7 @@ async function createGlobalMocks() { "zowe.jobs.stopPolling", "zowe.jobs.cancelJob", "zowe.jobs.sortBy", + "zowe.updateSecureCredentials", "zowe.manualPoll", "zowe.editHistory", "zowe.promptCredentials", @@ -261,6 +260,7 @@ async function createGlobalMocks() { "zowe.compareWithSelected", "zowe.compareWithSelectedReadOnly", "zowe.compareFileStarted", + "zowe.extRefresh", ], }; @@ -502,7 +502,7 @@ describe("Extension Unit Tests", () => { }); }); - it("Testing that activate correctly executes", async () => { + it("Testing that activate correctly executes", () => { expect(allCommands.map((c) => c.cmd)).toEqual(globalMocks.expectedCommands); }); diff --git a/packages/zowe-explorer/__tests__/__unit__/shared/init.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/shared/init.unit.test.ts index 34a04ce416..c9b35809ca 100644 --- a/packages/zowe-explorer/__tests__/__unit__/shared/init.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/shared/init.unit.test.ts @@ -52,6 +52,14 @@ describe("Test src/shared/extension", () => { _: { _: "_" }, }; const commands: IJestIt[] = [ + { + name: "zowe.updateSecureCredentials", + parm: ["@zowe/cli"], + mock: [ + { spy: jest.spyOn(globals, "setGlobalSecurityValue"), arg: ["@zowe/cli"] }, + { spy: jest.spyOn(profUtils.ProfilesUtils, "writeOverridesFile"), arg: [] }, + ], + }, { name: "zowe.manualPoll", mock: [], @@ -397,22 +405,4 @@ describe("Test src/shared/extension", () => { expect(spyExpand).not.toHaveBeenCalled(); }); }); - - describe("registerCredentialManager", () => { - let context: any; - - beforeEach(() => { - context = { subscriptions: [] }; - jest.clearAllMocks(); - }); - afterAll(() => { - jest.restoreAllMocks(); - }); - - it("should register command for updating credentials", () => { - const registerCommandSpy = jest.spyOn(vscode.commands, "registerCommand"); - sharedExtension.registerCredentialManager(context); - expect(registerCommandSpy).toBeCalledWith("zowe.updateSecureCredentials", expect.any(Function)); - }); - }); }); diff --git a/packages/zowe-explorer/src/extension.ts b/packages/zowe-explorer/src/extension.ts index 5018b889f3..8f5d93b2f1 100644 --- a/packages/zowe-explorer/src/extension.ts +++ b/packages/zowe-explorer/src/extension.ts @@ -11,18 +11,15 @@ import * as globals from "./globals"; import * as vscode from "vscode"; -import { getZoweDir } from "@zowe/zowe-explorer-api"; import { ZoweExplorerApiRegister } from "./ZoweExplorerApiRegister"; import { ZoweExplorerExtender } from "./ZoweExplorerExtender"; import { Profiles } from "./Profiles"; import { ProfilesUtils } from "./utils/ProfilesUtils"; import { initializeSpoolProvider } from "./SpoolProvider"; -import { cleanTempDir, hideTempFolder } from "./utils/TempFolder"; -import { SettingsConfig } from "./utils/SettingsConfig"; -import { registerCommonCommands, registerCredentialManager, registerRefreshCommand, watchConfigProfile } from "./shared/init"; +import { cleanTempDir } from "./utils/TempFolder"; +import { registerCommonCommands, registerRefreshCommand, watchConfigProfile, watchForZoweButtonClick } from "./shared/init"; import { ZoweLogger } from "./utils/LoggerUtils"; import { ZoweSaveQueue } from "./abstract/ZoweSaveQueue"; -import { PollDecorator } from "./utils/DecorationProviders"; import { ZoweLocalStorage } from "./utils/ZoweLocalStorage"; import { TreeProviders } from "./shared/TreeProviders"; import { initDatasetProvider } from "./dataset/init"; @@ -37,33 +34,21 @@ import { initJobsProvider } from "./job/init"; * @returns {Promise} */ export async function activate(context: vscode.ExtensionContext): Promise { - // Initialize LocalStorage for persistent Zowe Settings ZoweLocalStorage.initializeZoweLocalStorage(context.globalState); await ZoweLogger.initializeZoweLogger(context); - // Get temp folder location from settings - const tempPath: string = SettingsConfig.getDirectValue(globals.SETTINGS_TEMP_FOLDER_PATH); - // Determine the runtime framework to support special behavior for Theia - globals.defineGlobals(tempPath); - await hideTempFolder(getZoweDir()); - registerCredentialManager(context); await ProfilesUtils.initializeZoweProfiles((msg) => ZoweExplorerExtender.showZoweConfigError(msg)); - ProfilesUtils.initializeZoweTempFolder(); - - // Initialize profile manager await Profiles.createInstance(ZoweLogger.imperativeLogger); - registerRefreshCommand(context, activate, deactivate); initializeSpoolProvider(context); - PollDecorator.register(); - const providers = await TreeProviders.initializeProviders(context, { ds: initDatasetProvider, uss: initUSSProvider, job: initJobsProvider }); - registerCommonCommands(context, providers); + registerRefreshCommand(context, activate, deactivate); ZoweExplorerExtender.createInstance(providers.ds, providers.uss, providers.job); - await SettingsConfig.standardizeSettings(); + await watchConfigProfile(context, providers); - globals.setActivated(true); + await watchForZoweButtonClick(); + return ZoweExplorerApiRegister.getInstance(); } /** diff --git a/packages/zowe-explorer/src/shared/init.ts b/packages/zowe-explorer/src/shared/init.ts index dfb1995e26..80d24f1824 100644 --- a/packages/zowe-explorer/src/shared/init.ts +++ b/packages/zowe-explorer/src/shared/init.ts @@ -31,6 +31,7 @@ import { spoolFilePollEvent } from "../job/actions"; import { HistoryView } from "./HistoryView"; import { ProfileManagement } from "../utils/ProfileManagement"; import { LocalFileManagement } from "../utils/LocalFileManagement"; +import { TreeProviders } from "./TreeProviders"; // Set up localization nls.config({ @@ -70,6 +71,15 @@ export function registerRefreshCommand( export function registerCommonCommands(context: vscode.ExtensionContext, providers: IZoweProviders): void { ZoweLogger.trace("shared.init.registerCommonCommands called."); + + // Update imperative.json to false only when VS Code setting is set to false + context.subscriptions.push( + vscode.commands.registerCommand("zowe.updateSecureCredentials", async (customCredentialManager?: string) => { + await globals.setGlobalSecurityValue(customCredentialManager); + ProfilesUtils.writeOverridesFile(); + }) + ); + context.subscriptions.push( vscode.commands.registerCommand("zowe.manualPoll", async (_args) => { if (vscode.window.activeTextEditor) { @@ -243,16 +253,6 @@ export function registerCommonCommands(context: vscode.ExtensionContext, provide } } -export function registerCredentialManager(context: vscode.ExtensionContext): void { - // Update imperative.json to false only when VS Code setting is set to false - context.subscriptions.push( - vscode.commands.registerCommand("zowe.updateSecureCredentials", async (customCredentialManager?: string) => { - await globals.setGlobalSecurityValue(customCredentialManager); - ProfilesUtils.writeOverridesFile(); - }) - ); -} - export function watchConfigProfile(context: vscode.ExtensionContext, providers: IZoweProviders): void { ZoweLogger.trace("shared.init.watchConfigProfile called."); const watchers: vscode.FileSystemWatcher[] = []; @@ -310,3 +310,46 @@ export function initSubscribers(context: vscode.ExtensionContext, theProvider: I }); } } + +/** + * Listener for when Zowe button is clicked on activity bar, + * this event only fires one time upon clicking the Zowe button the first time. + * @returns Promise + */ +export async function watchForZoweButtonClick(): Promise { + const availableTreeProviders: string[] = Object.keys(TreeProviders.providers).filter( + (provider) => (TreeProviders.providers[provider] as IZoweTree).getTreeView() !== undefined + ); + if (!availableTreeProviders.length) { + return; + } + for (const availableTreeProvider of availableTreeProviders) { + const treeView: vscode.TreeView = TreeProviders.providers[availableTreeProvider].getTreeView(); + // handle case where Zowe Explorer is already visible when loading VS Code + if (treeView.visible) { + await initZoweExplorerUI(); + } + // Wait for visible tree provider and activate UI + treeView.onDidChangeVisibility(async () => { + await initZoweExplorerUI(); + }); + } +} + +/** + * Initialize Zowe Explorer UI functions + * Function can only run one time during runtime, otherwise it will immediately return + * @returns Promise + */ +async function initZoweExplorerUI(): Promise { + if (globals.ACTIVATED) { + return; + } + const tempPath: string = SettingsConfig.getDirectValue(globals.SETTINGS_TEMP_FOLDER_PATH); + globals.defineGlobals(tempPath); + await hideTempFolder(getZoweDir()); + ProfilesUtils.initializeZoweTempFolder(); + await SettingsConfig.standardizeSettings(); + globals.setActivated(true); + vscode.window.showInformationMessage("Zowe Explorer UI initialized"); +} From 71bee5ead0de96bc74a3120b06ef7a29774a97af Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:19:23 -0500 Subject: [PATCH 2/2] add changelog Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- packages/zowe-explorer/CHANGELOG.md | 1 + packages/zowe-explorer/src/shared/init.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index 6081a844cc..1e39856961 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen ## TBD Release - Added the Issue UNIX Commands feature. [#1326](https://github.com/zowe/vscode-extension-for-zowe/issues/1326) +- Minimized activation function for Zowe Explorer to load only necessary items on activation. [#1985](https://github.com/zowe/vscode-extension-for-zowe/issues/1985) ### New features and enhancements diff --git a/packages/zowe-explorer/src/shared/init.ts b/packages/zowe-explorer/src/shared/init.ts index 80d24f1824..6e65167883 100644 --- a/packages/zowe-explorer/src/shared/init.ts +++ b/packages/zowe-explorer/src/shared/init.ts @@ -351,5 +351,4 @@ async function initZoweExplorerUI(): Promise { ProfilesUtils.initializeZoweTempFolder(); await SettingsConfig.standardizeSettings(); globals.setActivated(true); - vscode.window.showInformationMessage("Zowe Explorer UI initialized"); }