Skip to content

Commit 303c570

Browse files
Show jobs config name in the attach to process debug menu (intersystems-community#1089)
* Show jobs config name in the attach to process debug menu * Ignore error when namespace is not interoperability-enabled * Update src/extension.ts Co-authored-by: John Murray <[email protected]> --------- Co-authored-by: Olli Tanskanen <[email protected]> Co-authored-by: John Murray <[email protected]>
1 parent ff51947 commit 303c570

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/extension.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,45 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
842842
vscode.commands.registerCommand("vscode-objectscript.pickProcess", async (config) => {
843843
const system = config.system;
844844
const api = new AtelierAPI(vscode.window.activeTextEditor?.document.uri);
845-
const convert = (data) =>
846-
data.result.content.map(
847-
(process: AtelierJob): vscode.QuickPickItem => ({
848-
label: process.pid.toString(),
849-
description: `Namespace: ${process.namespace}, Routine: ${process.routine}`,
850-
})
851-
);
845+
const convert = async (jobData) => {
846+
// NOTE: We do not know if the current user has permissions to other namespaces, so lets only fetch the job infos
847+
// for the current namespace.
848+
const currNamespaceJobs: { [k: string]: string } = await api
849+
.actionQuery("SELECT Job, ConfigName FROM Ens.Job_Enumerate() where State = 'Alive'", [])
850+
.then((data) => Object.fromEntries(data.result.content.map((x) => [x.Job, x.ConfigName])))
851+
.catch((error) => {
852+
// Current namespace is not Interoperability-enabled, there is no Ens.Job_Enumerate procedure
853+
if (error && error.errorText.includes("'ENS.JOB_ENUMERATE'(...)")) {
854+
return {};
855+
}
856+
857+
let message = `Failed to fetch namespace '${api.ns}' job config names.`;
858+
if (error && error.errorText && error.errorText !== "") {
859+
outputChannel.appendLine("\n" + error.errorText);
860+
outputChannel.show(true);
861+
message += " Check 'ObjectScript' output channel for details.";
862+
}
863+
vscode.window.showErrorMessage(message, "Dismiss");
864+
return {};
865+
});
866+
867+
return jobData.result.content.map((process: AtelierJob): vscode.QuickPickItem => {
868+
if (!currNamespaceJobs[process.pid.toString()]) {
869+
return {
870+
label: process.pid.toString(),
871+
description: `Namespace: ${process.namespace}, Routine: ${process.routine}`,
872+
};
873+
} else {
874+
return {
875+
label: process.pid.toString(),
876+
description: `Namespace: ${process.namespace}, Routine: ${process.routine}, Config Name: ${
877+
currNamespaceJobs[process.pid.toString()]
878+
}`,
879+
};
880+
}
881+
});
882+
};
883+
852884
const list = await api.getJobs(system).then(convert);
853885
if (!list.length) {
854886
vscode.window.showInformationMessage(`No attachable processes are running in ${api.ns}.`, {
@@ -859,6 +891,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
859891
return vscode.window
860892
.showQuickPick<vscode.QuickPickItem>(list, {
861893
placeHolder: "Pick the process to attach to",
894+
matchOnDescription: true,
862895
})
863896
.then((value) => {
864897
if (value) return value.label;

0 commit comments

Comments
 (0)