Skip to content

Commit

Permalink
feat(jobs): CodeLens link to load more spool content
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Dec 27, 2024
1 parent 9eb1853 commit e05b7d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/zowe-explorer/src/trees/job/JobFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,15 @@ export class JobFSProvider extends BaseProvider implements vscode.FileSystemProv
const jesApi = ZoweExplorerApiRegister.getJesApi(spoolEntry.metadata.profile);

const queryParams = new URLSearchParams(uri.query);
const startRecord = Number(queryParams.get("startRecord"));
const startRecord = queryParams.has("startRecord") ? Number(queryParams.get("startRecord")) : undefined;

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

// Handle encoding and binary options
Expand Down
30 changes: 8 additions & 22 deletions packages/zowe-explorer/src/trees/job/JobInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
*/

import * as vscode from "vscode";
import { IZoweJobTreeNode, IZoweTreeNode, ZoweScheme, imperative, Gui, FsJobsUtils } from "@zowe/zowe-explorer-api";
import { IZoweJobTreeNode, IZoweTreeNode, ZoweScheme, imperative, Gui } from "@zowe/zowe-explorer-api";
import { JobTree } from "./JobTree";
import { JobActions } from "./JobActions";
import { ZoweJobNode } from "./ZoweJobNode";
import { ZoweLogger } from "../../tools/ZoweLogger";
import { SharedActions } from "../shared/SharedActions";
import { SharedContext } from "../shared/SharedContext";
import { SharedInit } from "../shared/SharedInit";
import { SharedUtils } from "../shared/SharedUtils";
import { FetchMoreCodeLens, SharedUtils } from "../shared/SharedUtils";
import { JobFSProvider } from "./JobFSProvider";
import { PollProvider } from "./JobPollProvider";
import { JobTableView } from "./JobTableView";
Expand Down Expand Up @@ -163,28 +163,14 @@ export class JobInit {
})
);
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}` }));
}
}
vscode.commands.registerCommand("zowe.jobs.fetchMore", async (document: vscode.TextDocument) => {
await JobFSProvider.instance.fetchSpoolAtUri(document.uri.with({ query: `?startRecord=${document.lineCount - 1}` }));
})
);
const codeLensProvider = new FetchMoreCodeLens("zowe.jobs.fetchMore");
const disposableCodeLens = vscode.languages.registerCodeLensProvider({ scheme: ZoweScheme.Jobs }, codeLensProvider);
context.subscriptions.push(disposableCodeLens);

SharedInit.initSubscribers(context, jobsProvider);
return jobsProvider;
}
Expand Down
26 changes: 26 additions & 0 deletions packages/zowe-explorer/src/trees/shared/SharedUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ import { ZoweLogger } from "../../tools/ZoweLogger";
import { SharedContext } from "./SharedContext";
import { Definitions } from "../../configuration/Definitions";

export class FetchMoreCodeLens implements vscode.CodeLensProvider {
private commandId: string;

constructor(commandId: string) {
this.commandId = commandId;
}

provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.ProviderResult<vscode.CodeLens[]> {
const lineCount = document.lineCount;
const lastLine = lineCount - 1;
const lastLineRange = new vscode.Range(lastLine, 0, lastLine, 0);

const codelens = new vscode.CodeLens(lastLineRange, {
title: vscode.l10n.t("Load more content..."),
command: this.commandId,
arguments: [document],
});

return [codelens];
}

resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken): vscode.ProviderResult<vscode.CodeLens> {
return codeLens;
}
}

export class SharedUtils {
public static async copyExternalLink(this: void, context: vscode.ExtensionContext, node: IZoweTreeNode): Promise<void> {
if (node?.resourceUri != null) {
Expand Down

0 comments on commit e05b7d4

Please sign in to comment.