| 53 | } |
| 54 | |
| 55 | async getCodeSuggestions(context) { |
| 56 | const suggestions = [] |
| 57 | const stepName = context.step?.title |
| 58 | const recipes = matchRecipes(this.recipes, this.contextName) |
| 59 | .filter(r => !r.steps || !stepName || r.steps.includes(stepName)) |
| 60 | |
| 61 | debug('Recipes', recipes) |
| 62 | |
| 63 | const currentOutputLevel = output.level() |
| 64 | output.level(0) |
| 65 | |
| 66 | for (const [property, prepareFn] of Object.entries( |
| 67 | recipes |
| 68 | .map(r => r.prepare) |
| 69 | .filter(p => !!p) |
| 70 | .reduce((acc, obj) => ({ ...acc, ...obj }), {}), |
| 71 | )) { |
| 72 | if (!prepareFn) continue |
| 73 | |
| 74 | if (context[property]) continue |
| 75 | context[property] = await prepareFn(container.support()) |
| 76 | } |
| 77 | |
| 78 | output.level(currentOutputLevel) |
| 79 | |
| 80 | for (const recipe of recipes) { |
| 81 | let snippets = await recipe.fn(context) |
| 82 | if (!Array.isArray(snippets)) snippets = [snippets] |
| 83 | |
| 84 | suggestions.push({ |
| 85 | name: recipe.name, |
| 86 | snippets, |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | return suggestions.filter(s => !isBlank(s.snippets)) |
| 91 | } |
| 92 | |
| 93 | async healStep(failedStep, error, failureContext = {}) { |
| 94 | output.debug(`Trying to heal ${failedStep.toCode()} step`) |