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
57 changes: 50 additions & 7 deletions src/ui/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type ActionTarget = {
}

const actionUsed: Map<string, number> = new Map;
const PARM_REGEX = /(PNLGRP|OBJ|PGM|MODULE)\((?<object>.+?)\)/;
const PARM_REGEX = /(PNLGRP|OBJ|PGM|MODULE|FILE|MENU)\((?<object>.+?)\)/;

export function registerActionTools(context: vscode.ExtensionContext) {
context.subscriptions.push(
Expand Down Expand Up @@ -170,6 +170,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
extension: target.extension,
workspace: fromWorkspace
};
const evfeventInfos: EvfEventInfo[] = [];

let processedPath = "";
switch (chosenAction.type) {
Expand Down Expand Up @@ -382,12 +383,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) {
evfeventInfos.length = 0;
if (Array.isArray(possibleObjects)) {
for(const o of possibleObjects) {
evfeventInfos.push({
library: o.library || evfeventInfo.library,
object: o.object,
extension: evfeventInfo.extension,
asp: evfeventInfo.asp
})
};
} else {
evfeventInfo.library = possibleObjects.library ? possibleObjects.library : evfeventInfo.library;
evfeventInfo.object = possibleObjects.object;
evfeventInfos.push(evfeventInfo);
}
}

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

writeEmitter.fire(CompileTools.NEWLINE);
Expand All @@ -398,8 +413,8 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
}
else if (evfeventInfo.object && evfeventInfo.library) {
if (chosenAction.command.includes(`*EVENTF`)) {
writeEmitter.fire(`Fetching errors for ${evfeventInfo.library}/${evfeventInfo.object}.` + CompileTools.NEWLINE);
await refreshDiagnosticsFromServer(instance, evfeventInfo);
writeEmitter.fire(`Fetching errors for ` + (evfeventInfos.length > 1 ? `multiple objects` : `${evfeventInfo.library}/${evfeventInfo.object}.`) + CompileTools.NEWLINE);
await refreshDiagnosticsFromServer(instance, evfeventInfos);
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);
Expand Down Expand Up @@ -630,6 +645,34 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st
return availableActions;
}

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

// Filter lines with EVFEVENT info from server.
const joblogLines = stderr.split(`\n`).filter(line => line.match(/: EVFEVENT:/i));

for(const joblogLine of joblogLines) {
const evfevent = joblogLine.match(/: EVFEVENT:(.*)/i) || '';
if (evfevent.length) {
const object = evfevent[1].trim().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