From 18d485a9de042421c3022841c872d41474dae668 Mon Sep 17 00:00:00 2001 From: Trae Yelovich Date: Thu, 19 Dec 2024 19:38:10 -0500 Subject: [PATCH] add reloadActiveEditorForProfile and related logic Signed-off-by: Trae Yelovich --- .../src/profiles/AuthHandler.ts | 8 ++++---- packages/zowe-explorer-api/src/utils/index.ts | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/zowe-explorer-api/src/profiles/AuthHandler.ts b/packages/zowe-explorer-api/src/profiles/AuthHandler.ts index 290bf7418..12701f3fb 100644 --- a/packages/zowe-explorer-api/src/profiles/AuthHandler.ts +++ b/packages/zowe-explorer-api/src/profiles/AuthHandler.ts @@ -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"; @@ -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); } } } diff --git a/packages/zowe-explorer-api/src/utils/index.ts b/packages/zowe-explorer-api/src/utils/index.ts index 443084087..920019d2b 100644 --- a/packages/zowe-explorer-api/src/utils/index.ts +++ b/packages/zowe-explorer-api/src/utils/index.ts @@ -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"; @@ -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 { + 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 { const foldersWithProfile = (workspace.workspaceFolders ?? []).filter( (f) => (f.uri.scheme === ZoweScheme.DS || f.uri.scheme === ZoweScheme.USS) && f.uri.path.startsWith(`/${profileName}/`)