Skip to content

Commit

Permalink
wip: Support partial fetch for spools in editor
Browse files Browse the repository at this point in the history
[no ci]

Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Dec 27, 2024
1 parent aea6d92 commit 9eb1853
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
17 changes: 16 additions & 1 deletion packages/zowe-explorer/src/trees/job/JobFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,16 @@ export class JobFSProvider extends BaseProvider implements vscode.FileSystemProv
const bufBuilder = new BufferBuilder();

const jesApi = ZoweExplorerApiRegister.getJesApi(spoolEntry.metadata.profile);

const queryParams = new URLSearchParams(uri.query);
const startRecord = Number(queryParams.get("startRecord"));

try {
if (jesApi.downloadSingleSpool) {
const spoolDownloadObject: IDownloadSpoolContentParms = {
jobFile: spoolEntry.spool,
stream: bufBuilder,
startRecord,
};

// Handle encoding and binary options
Expand All @@ -232,7 +237,17 @@ export class JobFSProvider extends BaseProvider implements vscode.FileSystemProv
}

this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
spoolEntry.data = bufBuilder.read() ?? new Uint8Array();
if (startRecord > 0) {
const newContents: Uint8Array | null = bufBuilder.read();
if (newContents != null) {
const combined = new Uint8Array(spoolEntry.data.length + newContents.length);
combined.set(spoolEntry.data, 0);
combined.set(newContents, spoolEntry.data.length);
spoolEntry.data = combined;
}
} else {
spoolEntry.data = bufBuilder.read() ?? new Uint8Array();
}
spoolEntry.mtime = Date.now();
spoolEntry.size = spoolEntry.data.byteLength;
if (editor) {
Expand Down
25 changes: 24 additions & 1 deletion packages/zowe-explorer/src/trees/job/JobInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as vscode from "vscode";
import { IZoweJobTreeNode, IZoweTreeNode, ZoweScheme, imperative, Gui } from "@zowe/zowe-explorer-api";
import { IZoweJobTreeNode, IZoweTreeNode, ZoweScheme, imperative, Gui, FsJobsUtils } from "@zowe/zowe-explorer-api";
import { JobTree } from "./JobTree";
import { JobActions } from "./JobActions";
import { ZoweJobNode } from "./ZoweJobNode";
Expand Down Expand Up @@ -162,6 +162,29 @@ export class JobInit {
JobFSProvider.instance.cacheOpenedUri(doc.uri);
})
);
context.subscriptions.push(
vscode.window.onDidChangeTextEditorVisibleRanges(async (e) => {
const documentUri = e.textEditor.document.uri;
if (documentUri.scheme !== ZoweScheme.Jobs) {
return;
}
const spool = JobFSProvider.instance.lookup(documentUri, true);
if (spool == null || !FsJobsUtils.isSpoolEntry(spool)) {
return;
}

for (const range of e.visibleRanges) {
// if range contains line count of document the line count is
// less than the record count of the spool, attempt to fetch more records
if (
range.contains(new vscode.Position(e.textEditor.document.lineCount, 1)) &&
e.textEditor.document.lineCount < spool.spool?.["record-count"]
) {
await JobFSProvider.instance.fetchSpoolAtUri(documentUri.with({ query: `?startRecord=${e.textEditor.document.lineCount}` }));
}
}
})
);
SharedInit.initSubscribers(context, jobsProvider);
return jobsProvider;
}
Expand Down

0 comments on commit 9eb1853

Please sign in to comment.