Highligting for Recipe now working. Discovered bug when highlighting on a test case

master
d98762625 2019-02-08 14:28:53 +00:00
parent 9af5e40071
commit 58a8af20a6
3 changed files with 45 additions and 28 deletions

View File

@ -157,9 +157,9 @@ class Chef {
* @param {number} pos.end - The end offset. * @param {number} pos.end - The end offset.
* @returns {Object} * @returns {Object}
*/ */
calculateHighlights(recipeConfig, direction, pos) { async calculateHighlights(recipeConfig, direction, pos) {
const recipe = new Recipe(recipeConfig); const recipe = new Recipe(recipeConfig);
const highlights = recipe.generateHighlightList(); const highlights = await recipe.generateHighlightList();
if (!highlights) return false; if (!highlights) return false;

View File

@ -157,8 +157,8 @@ async function getDishAs(data) {
* @param {number} pos.start - The start offset. * @param {number} pos.start - The start offset.
* @param {number} pos.end - The end offset. * @param {number} pos.end - The end offset.
*/ */
function calculateHighlights(recipeConfig, direction, pos) { async function calculateHighlights(recipeConfig, direction, pos) {
pos = self.chef.calculateHighlights(recipeConfig, direction, pos); pos = await self.chef.calculateHighlights(recipeConfig, direction, pos);
self.postMessage({ self.postMessage({
action: "highlightsCalculated", action: "highlightsCalculated",

View File

@ -22,7 +22,6 @@ class Recipe {
*/ */
constructor(recipeConfig) { constructor(recipeConfig) {
this.opList = []; this.opList = [];
this.opList = [];
if (recipeConfig) { if (recipeConfig) {
this._parseConfig(recipeConfig); this._parseConfig(recipeConfig);
@ -49,6 +48,31 @@ class Recipe {
} }
/**
* Populate elements of opList with operation instances.
* Dynamic import here removes top-level cyclic dependency issue.For
*
* @private
*/
async _hydrateOpList() {
let modules = await import("./config/modules/OpModules");
modules = modules.default;
this.opList = this.opList.map((o) => {
if (o instanceof Operation) {
return o;
} else {
const op = new modules[o.module][o.name]();
op.ingValues = o.ingValues;
op.breakpoint = o.breakpoint;
op.disabled = o.disabled;
return op;
}
});
}
/** /**
* Returns the value of the Recipe as it should be displayed in a recipe config. * Returns the value of the Recipe as it should be displayed in a recipe config.
* *
@ -80,19 +104,21 @@ class Recipe {
addOperations(operations) { addOperations(operations) {
operations.forEach((o) => { operations.forEach((o) => {
if (o instanceof Operation) { if (o instanceof Operation) {
this.opList.push(o); this.opList.push(o);
} else {
this.opList.push({
name: o.name,
module: o.module,
ingValues: o.args,
breakpoint: o.breakpoint,
disabled: o.disabled,
});
} }
this.opList.push({
name: o.name,
module: o.module,
ingValues: o.args,
breakpoint: o.breakpoint,
disabled: o.disabled,
});
}); });
} }
@ -154,23 +180,13 @@ class Recipe {
if (startFrom === 0) this.lastRunOp = null; if (startFrom === 0) this.lastRunOp = null;
let modules = await import("./config/modules/OpModules"); await this._hydrateOpList();
modules = modules.default;
log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`); log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`);
for (let i = startFrom; i < this.opList.length; i++) { for (let i = startFrom; i < this.opList.length; i++) {
const opConfig = this.opList[i]; op = this.opList[i];
if (opConfig instanceof Operation) {
op = opConfig;
} else {
op = new modules[opConfig.module][opConfig.name]();
op.ingValues = opConfig.ingValues;
op.breakpoint = opConfig.breakpoint;
op.disabled = opConfig.disabled;
}
log.debug(`[${i}] ${op.name} ${JSON.stringify(op.ingValues)}`); log.debug(`[${i}] ${op.name} ${JSON.stringify(op.ingValues)}`);
@ -286,7 +302,8 @@ class Recipe {
* @returns {function} highlights[].b * @returns {function} highlights[].b
* @returns {Object[]} highlights[].args * @returns {Object[]} highlights[].args
*/ */
generateHighlightList() { async generateHighlightList() {
await this._hydrateOpList();
const highlights = []; const highlights = [];
for (let i = 0; i < this.opList.length; i++) { for (let i = 0; i < this.opList.length; i++) {