Skip to content
2 changes: 1 addition & 1 deletion src/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function registerActionsCommands(instance: Instance): Disposable[] {
const [library, object] = inputPath.split(`/`);
if (library && object) {
const nameDetail = path.parse(object);
refreshDiagnosticsFromServer(instance, { library, object: nameDetail.name, extension: (nameDetail.ext.length > 1 ? nameDetail.ext.substring(1) : undefined), workspace: options.workspace }, options.keepDiagnostics);
refreshDiagnosticsFromServer(instance, [{ library, object: nameDetail.name, extension: (nameDetail.ext.length > 1 ? nameDetail.ext.substring(1) : undefined), workspace: options.workspace }], options.keepDiagnostics);
}
}
}),
Expand Down
93 changes: 67 additions & 26 deletions src/ui/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,21 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
}

Object.entries(envFileVars).forEach(([key, value]) => variables.set(`&${key}`, value));
const evfeventInfo: EvfEventInfo = {
let evfeventInfo: EvfEventInfo[] = [{
object: '',
library: '',
extension: target.extension,
workspace: fromWorkspace
};
}];

let processedPath = "";
switch (chosenAction.type) {
case `member`:
const memberDetail = connection.parserMemberPath(target.uri.path);
evfeventInfo.library = memberDetail.library;
evfeventInfo.object = memberDetail.name;
evfeventInfo.extension = memberDetail.extension;
evfeventInfo.asp = memberDetail.asp;
evfeventInfo[0].library = memberDetail.library;
evfeventInfo[0].object = memberDetail.name;
evfeventInfo[0].extension = memberDetail.extension;
evfeventInfo[0].asp = memberDetail.asp;

processedPath = `${memberDetail.library}/${memberDetail.file}/${memberDetail.basename}`;

Expand Down Expand Up @@ -214,14 +214,14 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
name = name.substring(0, name.indexOf(`-`));
}

evfeventInfo.library = connection.upperCaseName(variables.get(`&CURLIB`) || config.currentLibrary);
evfeventInfo.object = connection.upperCaseName(name);
evfeventInfo.extension = ext;
evfeventInfo[0].library = connection.upperCaseName(variables.get(`&CURLIB`) || config.currentLibrary);
evfeventInfo[0].object = connection.upperCaseName(name);
evfeventInfo[0].extension = ext;

if (chosenAction.command.includes(`&SRCFILE`)) {
variables.set(`&SRCLIB`, evfeventInfo.library)
variables.set(`&SRCLIB`, evfeventInfo[0].library)
.set(`&SRCPF`, `QTMPSRC`)
.set(`&SRCFILE`, `${evfeventInfo.library}/QTMPSRC`);
.set(`&SRCFILE`, `${evfeventInfo[0].library}/QTMPSRC`);
}

switch (chosenAction.type) {
Expand Down Expand Up @@ -270,8 +270,8 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
const [_, library, fullName] = connection.upperCaseName(target.uri.path).split(`/`);
const object = fullName.substring(0, fullName.lastIndexOf(`.`));

evfeventInfo.library = library;
evfeventInfo.object = object;
evfeventInfo[0].library = library;
evfeventInfo[0].object = object;

processedPath = `${library}/${object}.${target.extension}`;

Expand Down Expand Up @@ -330,7 +330,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
// If &SRCFILE is set, we need to copy the file to a temporary source file from the IFS
const fullPath = variables.get(`&FULLPATH`);
const srcFile = variables.get(`&SRCFILE`);
if (fullPath && srcFile && evfeventInfo.object) {
if (fullPath && srcFile && evfeventInfo[0].object) {
const [lib, srcpf] = srcFile.split(`/`);

const createSourceFile = content.toCl(`CRTSRCPF`, {
Expand All @@ -340,7 +340,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur

const copyFromStreamfile = content.toCl(`CPYFRMSTMF`, {
fromstmf: fullPath,
tombr: `'${Tools.qualifyPath(lib, srcpf, evfeventInfo.object)}'`,
tombr: `'${Tools.qualifyPath(lib, srcpf, evfeventInfo[0].object)}'`,
mbropt: `*REPLACE`,
dbfccsid: `*FILE`,
stmfccsid: 1208,
Expand Down Expand Up @@ -379,12 +379,26 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
fromWorkspace && chosenAction.postDownload &&
(chosenAction.postDownload.includes(`.evfevent`) || chosenAction.postDownload.includes(`.evfevent/`));

const possibleObject = getObjectFromCommand(commandResult.command);
if (isIleCommand && possibleObject) {
Object.assign(evfeventInfo, possibleObject);
const possibleObjects = getObjectsFromJoblog(commandResult.stderr) || getObjectFromCommand(commandResult.command);
if (isIleCommand && possibleObjects) {
if (Array.isArray(possibleObjects)) {
const tempEvfeventInfo = evfeventInfo[0];
evfeventInfo = [];
for(const o of possibleObjects) {
evfeventInfo.push({
library: o.library ? o.library : tempEvfeventInfo.library,
object: o.object,
extension: tempEvfeventInfo.extension,
asp: tempEvfeventInfo.asp
})
};
} else {
evfeventInfo[0].library = possibleObjects.library ? possibleObjects.library : evfeventInfo[0].library;
evfeventInfo[0].object = possibleObjects.object;
}
}

actionName = (isIleCommand && possibleObject ? `${chosenAction.name} for ${evfeventInfo.library}/${evfeventInfo.object}` : actionName);
actionName = (isIleCommand && possibleObjects ? `${chosenAction.name} for ${evfeventInfo[0].library}/${evfeventInfo[0].object}` : actionName);
successful = (commandResult.code === 0 || commandResult.code === null);

writeEmitter.fire(CompileTools.NEWLINE);
Expand All @@ -393,13 +407,13 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
writeEmitter.fire(`Fetching errors from .evfevent.${CompileTools.NEWLINE}`);

}
else if (evfeventInfo.object && evfeventInfo.library) {
else if (evfeventInfo[0].object && evfeventInfo[0].library) {
if (chosenAction.command.includes(`*EVENTF`)) {
writeEmitter.fire(`Fetching errors for ${evfeventInfo.library}/${evfeventInfo.object}.` + CompileTools.NEWLINE);
writeEmitter.fire(`Fetching errors for ` + (evfeventInfo.length > 1 ? `multiple objects` : `${evfeventInfo[0].library}/${evfeventInfo[0].object}.`) + CompileTools.NEWLINE);
await refreshDiagnosticsFromServer(instance, evfeventInfo);
problemsFetched = true;
} else if (chosenAction.command.trimStart().toUpperCase().startsWith(`CRT`)) {
writeEmitter.fire(`*EVENTF not found in command string. Not fetching errors for ${evfeventInfo.library}/${evfeventInfo.object}.` + CompileTools.NEWLINE);
writeEmitter.fire(`*EVENTF not found in command string. Not fetching errors for ${evfeventInfo[0].library}/${evfeventInfo[0].object}.` + CompileTools.NEWLINE);
}
}

Expand Down Expand Up @@ -481,7 +495,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur

// Process locally downloaded evfevent files:
if (useLocalEvfevent) {
await refreshDiagnosticsFromLocal(instance, evfeventInfo);
await refreshDiagnosticsFromLocal(instance, evfeventInfo[0]);
problemsFetched = true;
}
})
Expand All @@ -502,7 +516,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur

} catch (e) {
writeEmitter.fire(`${e}\n`);
vscode.window.showErrorMessage(`Action ${chosenAction} for ${evfeventInfo.library}/${evfeventInfo.object} failed. (internal error).`);
vscode.window.showErrorMessage(`Action ${chosenAction} for ${evfeventInfo[0].library}/${evfeventInfo[0].object} failed. (internal error).`);
successful = false;
}

Expand Down Expand Up @@ -544,7 +558,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
resultsPanel.addParagraph(`<pre>${targets[0].output.join("")}</pre>`)
.setOptions({ fullPage: true ,
css: /* css */ `
pre{
pre{
background-color: transparent;
}
`
Expand All @@ -564,7 +578,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
pre {
margin: 1em;
background-color: transparent;
}
}
`
});
}
Expand Down Expand Up @@ -624,6 +638,33 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st
return availableActions;
}

function getObjectsFromJoblog(stderr: string): CommandObject[] | undefined {
const objects: CommandObject[] = [];

const joblogLines = stderr.split(`\n`).filter(line => line.slice(7, 19).toUpperCase() === `: EVFEVENT:`);

for(const joblogLine of joblogLines) {
const evfevent = joblogLine.slice(19).trim();
if (evfevent.length) {
const object = evfevent.split(/[,\|/]/);
if (object) {
if (object.length >= 2) {
objects.push({
library: object[0].trim(),
object: object[1].trim()
});
} else {
objects.push({
object: object[0].trim()
});
}
}
}
}

return objects.length > 0 ? objects : undefined;
}

function getObjectFromCommand(baseCommand?: string): CommandObject | undefined {
if (baseCommand) {
const regex = PARM_REGEX.exec(baseCommand.toUpperCase());
Expand Down
12 changes: 7 additions & 5 deletions src/ui/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ export function clearDiagnostic(uri: vscode.Uri, changeRange: vscode.Range) {
}
}

export async function refreshDiagnosticsFromServer(instance: Instance, evfeventInfo: EvfEventInfo, keepDiagnostics?: boolean) {
export async function refreshDiagnosticsFromServer(instance: Instance, evfeventInfo: EvfEventInfo[], keepDiagnostics?: boolean) {
const connection = instance.getConnection();

if (connection) {
const content = connection.getContent();
const tableData = await content.getTable(evfeventInfo.library, `EVFEVENT`, evfeventInfo.object);
const lines = tableData.map(row => String(row.EVFEVENT));

if (IBMi.connectionManager.get(`clearErrorsBeforeBuild`) && !keepDiagnostics) {
// Clear all errors if the user has this setting enabled
clearDiagnostics();
}

handleEvfeventLines(lines, instance, evfeventInfo);
evfeventInfo.forEach(async e => {
const tableData = await content.getTable(e.library, `EVFEVENT`, e.object);
const lines = tableData.map(row => String(row.EVFEVENT));
handleEvfeventLines(lines, instance, e);
});
} else {
throw new Error('Please connect to an IBM i');
}
Expand Down Expand Up @@ -153,7 +155,7 @@ export function handleEvfeventLines(lines: string[], instance: Instance, evfeven
if (connection) {
// Belive it or not, sometimes if the deploy directory is symlinked into as ASP, this can be a problem
const aspNames = connection.getAllIAsps().map(asp => asp.name);

for (const aspName of aspNames) {
const aspRoot = `/${aspName}`;
if (relativeCompilePath.startsWith(aspRoot)) {
Expand Down
Loading