Highligting for Recipe now working. Discovered bug when highlighting on a test case
parent
9af5e40071
commit
58a8af20a6
|
@ -157,9 +157,9 @@ class Chef {
|
|||
* @param {number} pos.end - The end offset.
|
||||
* @returns {Object}
|
||||
*/
|
||||
calculateHighlights(recipeConfig, direction, pos) {
|
||||
async calculateHighlights(recipeConfig, direction, pos) {
|
||||
const recipe = new Recipe(recipeConfig);
|
||||
const highlights = recipe.generateHighlightList();
|
||||
const highlights = await recipe.generateHighlightList();
|
||||
|
||||
if (!highlights) return false;
|
||||
|
||||
|
|
|
@ -157,8 +157,8 @@ async function getDishAs(data) {
|
|||
* @param {number} pos.start - The start offset.
|
||||
* @param {number} pos.end - The end offset.
|
||||
*/
|
||||
function calculateHighlights(recipeConfig, direction, pos) {
|
||||
pos = self.chef.calculateHighlights(recipeConfig, direction, pos);
|
||||
async function calculateHighlights(recipeConfig, direction, pos) {
|
||||
pos = await self.chef.calculateHighlights(recipeConfig, direction, pos);
|
||||
|
||||
self.postMessage({
|
||||
action: "highlightsCalculated",
|
||||
|
|
|
@ -22,7 +22,6 @@ class Recipe {
|
|||
*/
|
||||
constructor(recipeConfig) {
|
||||
this.opList = [];
|
||||
this.opList = [];
|
||||
|
||||
if (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.
|
||||
*
|
||||
|
@ -80,8 +104,10 @@ class Recipe {
|
|||
addOperations(operations) {
|
||||
operations.forEach((o) => {
|
||||
if (o instanceof Operation) {
|
||||
|
||||
this.opList.push(o);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
this.opList.push({
|
||||
name: o.name,
|
||||
|
@ -91,8 +117,8 @@ class Recipe {
|
|||
disabled: o.disabled,
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -154,23 +180,13 @@ class Recipe {
|
|||
|
||||
if (startFrom === 0) this.lastRunOp = null;
|
||||
|
||||
let modules = await import("./config/modules/OpModules");
|
||||
modules = modules.default;
|
||||
await this._hydrateOpList();
|
||||
|
||||
log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`);
|
||||
|
||||
for (let i = startFrom; i < this.opList.length; i++) {
|
||||
|
||||
const opConfig = 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;
|
||||
}
|
||||
op = this.opList[i];
|
||||
|
||||
log.debug(`[${i}] ${op.name} ${JSON.stringify(op.ingValues)}`);
|
||||
|
||||
|
@ -286,7 +302,8 @@ class Recipe {
|
|||
* @returns {function} highlights[].b
|
||||
* @returns {Object[]} highlights[].args
|
||||
*/
|
||||
generateHighlightList() {
|
||||
async generateHighlightList() {
|
||||
await this._hydrateOpList();
|
||||
const highlights = [];
|
||||
|
||||
for (let i = 0; i < this.opList.length; i++) {
|
||||
|
|
Loading…
Reference in New Issue