Skip to content

Commit

Permalink
add reloadActiveEditorForProfile and related logic
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Dec 20, 2024
1 parent 167977a commit 18d485a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/zowe-explorer-api/src/profiles/AuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import { Gui } from "../globals";
import { CorrelatedError, refreshActiveEditorForProfile, refreshWorkspacesForProfile } from "../utils";
import { CorrelatedError, reloadActiveEditorForProfile, reloadWorkspacesForProfile } from "../utils";
import * as imperative from "@zowe/imperative";
import { IZoweTree, IZoweTreeNode } from "../tree";
import { commands } from "vscode";
Expand Down Expand Up @@ -59,10 +59,10 @@ export class AuthHandler {
if (deferred) {
deferred.unlock();
if (refreshResources) {
// refresh an active, unsaved editor if it contains the profile
refreshActiveEditorForProfile(profileName);
// refresh an active, unsaved editor if it uses the profile
reloadActiveEditorForProfile(profileName);
// refresh virtual workspaces for the profile
refreshWorkspacesForProfile(profileName);
reloadWorkspacesForProfile(profileName);
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions packages/zowe-explorer-api/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*
*/

import { ZoweScheme } from "../fs";
import { IFileSystemEntry, ZoweScheme } from "../fs";
import { IZoweTreeNode } from "../tree";
import { workspace } from "vscode";
import { window, workspace } from "vscode";

export * from "./DeferredPromise";
export * from "./ErrorCorrelator";
Expand All @@ -28,6 +28,18 @@ export function isNodeInEditor(node: IZoweTreeNode): boolean {
return workspace.textDocuments.some(({ uri, isDirty }) => uri.path === node.resourceUri?.path && isDirty);
}

export async function reloadActiveEditorForProfile(profileName: string): Promise<void> {
if (
(Object.values(ZoweScheme) as string[]).includes(window.activeTextEditor.document.uri.scheme) &&
window.activeTextEditor.document.uri.path.startsWith(`/${profileName}/`) &&
!window.activeTextEditor.document.isDirty
) {
const fsEntry = (await workspace.fs.stat(window.activeTextEditor.document.uri)) as IFileSystemEntry;
fsEntry.wasAccessed = false;
await workspace.fs.readFile(window.activeTextEditor.document.uri);
}
}

export async function reloadWorkspacesForProfile(profileName: string): Promise<void> {
const foldersWithProfile = (workspace.workspaceFolders ?? []).filter(
(f) => (f.uri.scheme === ZoweScheme.DS || f.uri.scheme === ZoweScheme.USS) && f.uri.path.startsWith(`/${profileName}/`)
Expand Down

0 comments on commit 18d485a

Please sign in to comment.