Skip to content

Commit

Permalink
feat: Parse the DefinitionList at source
Browse files Browse the repository at this point in the history
Ensure there are always "some" values for TimeLocalExecute

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Jan 19, 2024
1 parent 5e11e56 commit f83bb93
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions packages/comms/src/ecl/workunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function formatNum(num: number | string): string {
}
return num as string;
}
const DEFINITION_LIST = "DefinitionList";
const definitionRegex = /([a-zA-Z]:)?(.*[\\/])(.*)(\((\d+),(\d+)\))/;

const logger = scopedLogger("workunit.ts");

Expand Down Expand Up @@ -381,7 +383,7 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
abort() {
return this.WUAction("Abort");
}

protect() {
return this.WUAction("Protect");
}
Expand Down Expand Up @@ -589,16 +591,36 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
props[scopeProperty.Name] = scopeProperty.RawValue;
}
formattedProps[scopeProperty.Name] = formatNum(scopeProperty.Formatted ?? props[scopeProperty.Name]);

}
// Other properties ---
}
data.push({
const normalizedScope = {
id: scope.Id,
name: scope.ScopeName,
type: scope.ScopeType,
__formattedProps: formattedProps,
...props
});
...props,
TimeElapsed: props["TimeElapsed"] ?? props["TimeMaxElapsed"] ?? props["TimeAvgElapsed"],
TimeLocalExecute: props["TimeLocalExecute"] ?? props["TimeMaxLocalExecute"] ?? props["TimeAvgLocalExecute"]
};
if (normalizedScope[DEFINITION_LIST]) {
normalizedScope.__formattedProps[DEFINITION_LIST] = [];
try {
const definitionList = JSON.parse(normalizedScope[DEFINITION_LIST].split("\\").join("\\\\"));
definitionList.forEach((definition, idx) => {
const matches = definition.match(definitionRegex);
if (matches) {
const filePath = (matches[1] ?? "") + matches[2] + matches[3];
const line = parseInt(matches[5]);
const col = parseInt(matches[6]);
normalizedScope.__formattedProps[DEFINITION_LIST].push({ filePath, line, col });
}
});
} catch (e) {
logger.error(`Unexpected "DefinitionList": ${normalizedScope[DEFINITION_LIST]}`);
}
}
data.push(normalizedScope);
}
return {
meta,
Expand Down

0 comments on commit f83bb93

Please sign in to comment.