Skip to content

Commit

Permalink
Updated to add SEP support + debugger version
Browse files Browse the repository at this point in the history
Signed-off-by: Seb Julliand <[email protected]>
  • Loading branch information
sebjulliand committed Apr 4, 2024
1 parent 17d37ca commit de6f6ba
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
37 changes: 21 additions & 16 deletions src/api/debug/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ interface DebugServiceDetails {
java: string;
}


export type DebugJob = {
name: string
ports: number[]
}

let debugServiceDetails: DebugServiceDetails | undefined;
export function resetDebugServiceDetails() {
debugServiceDetails = undefined;
Expand All @@ -39,7 +45,7 @@ export async function getDebugServiceDetails(): Promise<DebugServiceDetails> {

const detailFilePath = path.posix.join(directory, detailFile);
const detailExists = await content.testStreamFile(detailFile, "r");
if (detailExists) {
if (detailExists) {
try {
const fileContents = (await content.downloadStreamfileRaw(detailFilePath)).toString("utf-8");
debugServiceDetails = JSON.parse(fileContents);
Expand All @@ -53,11 +59,6 @@ export async function getDebugServiceDetails(): Promise<DebugServiceDetails> {
return debugServiceDetails!;
}

export type DebugJob = {
name: string
port: number
}

export async function startService(connection: IBMi) {
const config = connection.config!;

Expand Down Expand Up @@ -128,25 +129,29 @@ export async function stopService(connection: IBMi) {
export async function getDebugServiceJob() {
const content = instance.getContent();
if (content) {
return rowToDebugJob(
(await content.runSQL(`select job_name, local_port from qsys2.netstat_job_info j where local_port = ${content.ibmi.config?.debugPort || 8005} fetch first row only`)).at(0)
);
const rows = await content.runSQL(`select distinct job_name, local_port from qsys2.netstat_job_info j where job_name = (select job_name from qsys2.netstat_job_info j where local_port = ${content.ibmi.config?.debugPort || 8005} fetch first row only)`);
if (rows && rows.length) {
return {
name: String(rows[0].JOB_NAME),
ports: rows.map(row => Number(row.LOCAL_PORT)).sort()
} as DebugJob;
}
}
}

export async function getDebugServerJob() {
const content = instance.getContent();
if (content) {
return rowToDebugJob(
(await content.runSQL(`select job_name, local_port from qsys2.netstat_job_info where cast(local_port_name as VarChar(14) CCSID 37) = 'is-debug-ile' fetch first row only`)).at(0)
);
const [row] = await content.runSQL(`select job_name, local_port from qsys2.netstat_job_info where cast(local_port_name as VarChar(14) CCSID 37) = 'is-debug-ile' fetch first row only`);
if (row) {
return {
name: String(row.JOB_NAME),
ports: [Number(row.LOCAL_PORT)]
} as DebugJob;
}
}
}

function rowToDebugJob(row?: Tools.DB2Row): DebugJob | undefined {
return row?.JOB_NAME ? { name: String(row.JOB_NAME), port: Number(row.LOCAL_PORT) } : undefined;
}

/**
* Gets a list of debug jobs stuck at MSGW in QSYSWRK
*/
Expand Down
4 changes: 2 additions & 2 deletions src/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConnectionConfiguration, DefaultOpenMode, GlobalConfiguration, onCodeFo
import Instance from "./api/Instance";
import { Search } from "./api/Search";
import { Terminal } from './api/Terminal';
import { isDebugEngineRunning } from './api/debug/server';
import { getDebugServiceDetails, isDebugEngineRunning } from './api/debug/server';
import { refreshDiagnosticsFromServer } from './api/errors/diagnostics';
import { setupGitEventHandler } from './api/local/git';
import { QSysFS, getUriFromPath, parseFSOptions } from "./filesystems/qsys/QSysFs";
Expand Down Expand Up @@ -745,7 +745,7 @@ async function updateConnectedBar() {
`[$(settings-gear) Settings](command:code-for-ibmi.showAdditionalSettings)`,
`[$(file-binary) Actions](command:code-for-ibmi.showActionsMaintenance)`,
`[$(terminal) Terminals](command:code-for-ibmi.launchTerminalPicker)`,
`[$(${debugRunning ? "bug" : "debug"}) Debugger (${debugRunning ? "on" : "off"})](command:code-for-ibmi.openDebugStatus)`,
`[$(${debugRunning ? "bug" : "debug"}) Debugger ${((await getDebugServiceDetails()).version)} (${debugRunning ? "on" : "off"})](command:code-for-ibmi.openDebugStatus)`,
].join(`\n\n---\n\n`), true);
connectedBarItem.tooltip.isTrusted = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/locale/ids/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const da: Locale = {
'restart': 'Restart',
'stop': 'Stop',
'listening.on.port': 'Listening on port',
'listening.on.ports': 'Listening on ports',
'overview': 'Overview',
'JOB_NAME_SHORT': 'Job name',
'JOB_USER': 'Job user',
Expand Down Expand Up @@ -360,7 +361,7 @@ export const da: Locale = {
'actions.workAction.runOnProtected': 'Må afvikles på sikret/skrive-beskyttet',
'actions.workAction.runOnProtected.description': 'Tillader afvikling af denne aktion på sikrede eller skrive-beskyttede mål',
//Debugger
'debugger.status': 'Debugger Status',
'debugger.status': 'Debugger {0} Status',
'loading.debugger.info': 'Loading debugger information...',
'debug.server': 'Debug Server',
'debug.service': 'Debug Service',
Expand Down
3 changes: 2 additions & 1 deletion src/locale/ids/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const en: Locale = {
'restart': 'Restart',
'stop': 'Stop',
'listening.on.port': 'Listening on port',
'listening.on.ports': 'Listening on ports',
'overview': 'Overview',
'JOB_NAME_SHORT': 'Job name',
'JOB_USER': 'Job user',
Expand Down Expand Up @@ -360,7 +361,7 @@ export const en: Locale = {
'actions.workAction.runOnProtected': 'Run on protected/read only',
'actions.workAction.runOnProtected.description': 'Allows the execution of this Action on protected or read only targets',
//Debugger
'debugger.status': 'Debugger Status',
'debugger.status': 'Debugger {0} Status',
'loading.debugger.info': 'Loading debugger information...',
'debug.server': 'Debug Server',
'debug.service': 'Debug Service',
Expand Down
3 changes: 2 additions & 1 deletion src/locale/ids/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const fr: Locale = {
'restart': 'Redémarrer',
'stop': 'Arrêter',
'listening.on.port': 'Écoute sur le port',
'listening.on.ports': 'Écoute sur les ports',
'overview': 'Aperçu',
'JOB_NAME_SHORT': 'Nom du job',
'JOB_USER': 'Utilisateur',
Expand Down Expand Up @@ -360,7 +361,7 @@ export const fr: Locale = {
'actions.workAction.runOnProtected': 'Exécuter en mode protégé/lecture seule',
'actions.workAction.runOnProtected.description': `Autorise l'exécution de cette action sur des cibles protégés ou en lecture seule`,
//Debugger
'debugger.status': 'Status du débogueur',
'debugger.status': 'Status du débogueur {0}',
'loading.debugger.info': 'Chargement du status du débogueur...',
'debug.server': 'Serveur de débogage',
'debug.service': 'Service de débogage',
Expand Down
9 changes: 5 additions & 4 deletions src/webviews/debugger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import IBMiContent from "../../api/IBMiContent";
import { Tools } from "../../api/Tools";
import { isManaged } from "../../api/debug";
import { getLocalCertPath, getRemoteCertificateDirectory, localClientCertExists, readRemoteCertificate, remoteServerCertificateExists, setup } from "../../api/debug/certificates";
import { DebugJob, getDebugServerJob, getDebugServiceJob, getServiceConfigurationFile, startServer, startService, stopServer, stopService } from "../../api/debug/server";
import { DebugJob, getDebugServerJob, getDebugServiceDetails, getDebugServiceJob, getServiceConfigurationFile, startServer, startService, stopServer, stopService } from "../../api/debug/server";
import { instance } from "../../instantiate";
import { t } from "../../locale";

Expand All @@ -19,6 +19,7 @@ export async function openDebugStatusPanel() {
const config = instance.getConfig()
const connection = instance.getConnection();
if (content && config && connection) {
const debuggerDetails =await getDebugServiceDetails();
const debbuggerInfo = await vscode.window.withProgress({ title: t("loading.debugger.info"), location: vscode.ProgressLocation.Notification }, async () => {
const serverJob = await getDebugServerJob();
const activeServerJob = serverJob ? await readActiveJob(content, serverJob) : undefined;
Expand Down Expand Up @@ -66,7 +67,7 @@ export async function openDebugStatusPanel() {
<li>${t("status")}: ${debbuggerInfo.server ? t("online") : t("offline")}</li>
${debbuggerInfo.server ? /* html */ `
<li>${t("job")}: ${debbuggerInfo.server.job.name}</li>
<li>${t("listening.on.port")}: ${debbuggerInfo.server.job.port}</li>`
<li>${t("listening.on.port")}: ${debbuggerInfo.server.job.ports[0]}</li>`
: ""
}
</ul>`)
Expand All @@ -80,7 +81,7 @@ export async function openDebugStatusPanel() {
<li>${t("status")}: ${debbuggerInfo.service ? t("online") : t("offline")} </li>
${debbuggerInfo.service ? /* html */ `
<li>${t("job")}: ${debbuggerInfo.service.job.name}</li>
<li>${t("listening.on.port")}: ${debbuggerInfo.service.job.port}</li>
<li>${t("listening.on.ports")}: ${debbuggerInfo.service.job.ports.join(", ")}</li>
`
: ""
}
Expand Down Expand Up @@ -135,7 +136,7 @@ export async function openDebugStatusPanel() {

new CustomUI()
.addComplexTabs(tabs)
.loadPage<DebuggerPage>(t('debugger.status'), handleAction);
.loadPage<DebuggerPage>(t('debugger.status', debuggerDetails.version), handleAction);
}
}

Expand Down

0 comments on commit de6f6ba

Please sign in to comment.