Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize activation function #2611

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -244,6 +242,7 @@ async function createGlobalMocks() {
"zowe.jobs.stopPolling",
"zowe.jobs.cancelJob",
"zowe.jobs.sortBy",
"zowe.updateSecureCredentials",
"zowe.manualPoll",
"zowe.editHistory",
"zowe.promptCredentials",
Expand All @@ -261,6 +260,7 @@ async function createGlobalMocks() {
"zowe.compareWithSelected",
"zowe.compareWithSelectedReadOnly",
"zowe.compareFileStarted",
"zowe.extRefresh",
],
};

Expand Down Expand Up @@ -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);
});

Expand Down
26 changes: 8 additions & 18 deletions packages/zowe-explorer/__tests__/__unit__/shared/init.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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));
});
});
});
27 changes: 6 additions & 21 deletions packages/zowe-explorer/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -37,33 +34,21 @@ import { initJobsProvider } from "./job/init";
* @returns {Promise<ZoweExplorerApiRegister>}
*/
export async function activate(context: vscode.ExtensionContext): Promise<ZoweExplorerApiRegister> {
// 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();
}
/**
Expand Down
62 changes: 52 additions & 10 deletions packages/zowe-explorer/src/shared/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { HistoryView } from "./HistoryView";
import { ProfileManagement } from "../utils/ProfileManagement";
import { LocalFileManagement } from "../utils/LocalFileManagement";
import { TreeProviders } from "./TreeProviders";

// Set up localization
nls.config({
Expand Down Expand Up @@ -70,6 +71,15 @@

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) {
Expand Down Expand Up @@ -243,16 +253,6 @@
}
}

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[] = [];
Expand Down Expand Up @@ -310,3 +310,45 @@
});
}
}

/**
* 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<void>
*/
export async function watchForZoweButtonClick(): Promise<void> {
const availableTreeProviders: string[] = Object.keys(TreeProviders.providers).filter(
(provider) => (TreeProviders.providers[provider] as IZoweTree<IZoweTreeNode>).getTreeView() !== undefined
);
if (!availableTreeProviders.length) {
return;

Check warning on line 324 in packages/zowe-explorer/src/shared/init.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/shared/init.ts#L324

Added line #L324 was not covered by tests
}
for (const availableTreeProvider of availableTreeProviders) {
const treeView: vscode.TreeView<IZoweTreeNode> = 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();

Check warning on line 334 in packages/zowe-explorer/src/shared/init.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/shared/init.ts#L334

Added line #L334 was not covered by tests
});
}
}

/**
* Initialize Zowe Explorer UI functions
* Function can only run one time during runtime, otherwise it will immediately return
* @returns Promise<void>
*/
async function initZoweExplorerUI(): Promise<void> {
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);
}
Loading