From 60ff77177be57f018f744cb8f24555c5d37c2661 Mon Sep 17 00:00:00 2001 From: Trae Yelovich Date: Fri, 30 Aug 2024 12:58:19 -0400 Subject: [PATCH] fix(fsp): Do not fetch changes during conflict; use custom context val Signed-off-by: Trae Yelovich --- packages/zowe-explorer-api/src/fs/BaseProvider.ts | 13 ++++++++++--- packages/zowe-explorer/package.json | 4 ++-- .../src/trees/dataset/DatasetFSProvider.ts | 4 +++- .../zowe-explorer/src/trees/uss/UssFSProvider.ts | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/zowe-explorer-api/src/fs/BaseProvider.ts b/packages/zowe-explorer-api/src/fs/BaseProvider.ts index 4ff2bf7872..504ad3bc4c 100644 --- a/packages/zowe-explorer-api/src/fs/BaseProvider.ts +++ b/packages/zowe-explorer-api/src/fs/BaseProvider.ts @@ -27,6 +27,7 @@ export class BaseProvider { public onDidChangeFile: vscode.Event = this._onDidChangeFileEmitter.event; protected root: DirEntry; public openedUris: vscode.Uri[] = []; + public onDocClosedEventDisposable: vscode.Disposable = null; protected constructor() {} @@ -296,14 +297,19 @@ export class BaseProvider { // This event removes the "diff view" flag from the local file, // so that API calls can continue after the conflict dialog is closed. - private static onCloseEvent(provider: BaseProvider, e: vscode.TextDocument): void { + private static onCloseEvent(this: BaseProvider, e: vscode.TextDocument): void { if (e.uri.query && e.uri.scheme.startsWith("zowe-")) { const queryParams = new URLSearchParams(e.uri.query); if (queryParams.has("conflict")) { - const fsEntry = provider._lookupAsFile(e.uri, { silent: true }); + const fsEntry = this._lookupAsFile(e.uri, { silent: true }); if (fsEntry) { fsEntry.inDiffView = false; } + + if (vscode.window.visibleTextEditors.every((editor) => !editor.document.uri.query.includes("conflict=true"))) { + vscode.commands.executeCommand("setContext", "zowe.vscode-extension-for-zowe.inConflict", false); + this.onDocClosedEventDisposable.dispose(); + } } } } @@ -332,13 +338,14 @@ export class BaseProvider { // User selected "Compare", show diff with local contents and LPAR contents if (userSelection === conflictOptions[0]) { - vscode.workspace.onDidCloseTextDocument(BaseProvider.onCloseEvent.bind(this)); + await vscode.commands.executeCommand("setContext", "zowe.vscode-extension-for-zowe.inConflict", true); await vscode.commands.executeCommand( "vscode.diff", uri.with({ query: "conflict=true" }), uri.with({ query: "inDiff=true" }), `${entry.name} (Remote) ↔ ${entry.name}` ); + this.onDocClosedEventDisposable = vscode.workspace.onDidCloseTextDocument(BaseProvider.onCloseEvent.bind(this)); return ConflictViewSelection.Compare; } diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index 48a652fb21..071c68f431 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -684,12 +684,12 @@ { "command": "zowe.diff.useLocalContent", "group": "navigation@0", - "when": "resourceScheme =~ /zowe-.*/ && isInDiffEditor" + "when": "resourceScheme =~ /zowe-.*/ && isInDiffEditor && zowe.vscode-extension-for-zowe.inConflict" }, { "command": "zowe.diff.useRemoteContent", "group": "navigation@1", - "when": "resourceScheme =~ /zowe-.*/ && isInDiffEditor" + "when": "resourceScheme =~ /zowe-.*/ && isInDiffEditor && zowe.vscode-extension-for-zowe.inConflict" } ], "view/title": [ diff --git a/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts b/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts index 13f50186e3..31054f041a 100644 --- a/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts +++ b/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts @@ -95,6 +95,8 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem const queryParams = new URLSearchParams(uri.query); if (queryParams.has("conflict")) { return { ...this.lookup(uri, false), permissions: vscode.FilePermission.Readonly }; + } else if (queryParams.has("inDiff")) { + return this.lookup(uri, false); } isFetching = queryParams.has("fetch") && queryParams.get("fetch") === "true"; } @@ -389,7 +391,7 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem const isConflict = urlQuery.has("conflict"); // we need to fetch the contents from the mainframe if the file hasn't been accessed yet - if (!file.wasAccessed || isConflict) { + if ((!file.wasAccessed && !urlQuery.has("inDiff")) || isConflict) { await this.fetchDatasetAtUri(uri, { isConflict }); if (!isConflict) { file.wasAccessed = true; diff --git a/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts b/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts index 001b709c4f..40c48eee2b 100644 --- a/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts +++ b/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts @@ -67,6 +67,8 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv const queryParams = new URLSearchParams(uri.query); if (queryParams.has("conflict")) { return { ...this.lookup(uri, false), permissions: vscode.FilePermission.Readonly }; + } else if (queryParams.has("inDiff")) { + return this.lookup(uri, false); } isFetching = queryParams.has("fetch") && queryParams.get("fetch") === "true"; } @@ -315,7 +317,7 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv // Fetch contents from the mainframe if: // - the file hasn't been accessed yet // - fetching a conflict from the remote FS - if (!file.wasAccessed || isConflict) { + if ((!file.wasAccessed && !urlQuery.has("inDiff")) || isConflict) { await this.fetchFileAtUri(uri, { isConflict }); if (!isConflict) { file.wasAccessed = true;