Implement the following plan: Plan: Extract Vendor Codegen Boilerplate into…
- User
Implement the following plan:
Plan: Extract Vendor Codegen Boilerplate into generator_utils
Context
All 4 vendor codegen modules (datadog, honeycomb, dynatrace, newrelic) duplicate identical boilerplate for
terraform_settings(),provider(),generate_terraform(), andgenerate_resources(). Only the vendor-specific resource building (ir_to_terraform_resource) and a few helper functions are truly unique per vendor. This refactoring extracts shared patterns intogenerator_utils.gleam, reducing ~200 lines of boilerplate while keeping vendor-specific logic in vendor modules.Key constraint: Datadog is special — its
generate_terraformreturns warnings (#(String, List(String))) and itsgenerate_resourcesusestry_foldfor per-resource warning accumulation. Datadog only benefits from Steps 1-2.Files Modified
caffeine_lang/src/caffeine_lang/codegen/generator_utils.gleam— add 4 builder functionscaffeine_lang/src/caffeine_lang/codegen/datadog.gleam— delegate terraform_settings + providercaffeine_lang/src/caffeine_lang/codegen/honeycomb.gleam— delegate all 4caffeine_lang/src/caffeine_lang/codegen/dynatrace.gleam— delegate all 4caffeine_lang/src/caffeine_lang/codegen/newrelic.gleam— delegate all 4
Steps
Step 1: Add
build_terraform_settingsto generator_utilsAdd to
generator_utils.gleam:gleam@internal pub fn build_terraform_settings( provider_name provider_name: String, source source: String, version version: String, ) -> terraform.TerraformSettingsThen in each vendor module, replace the body of
terraform_settings()with a one-liner call. Example for datadog:gleamgenerator_utils.build_terraform_settings( provider_name: constants.provider_datadog, source: "DataDog/datadog", version: "~> 3.0", )Vendor args: honeycomb (
"honeycombio/honeycombio","~> 0.31"), dynatrace (, ), newrelic (, ). Assistant
I'll implement this plan step by step. Let me first read the existing files to understand the current code.
Assistant
Now let me read the existing generator_utils.gleam.
Assistant
Good, I have a clear picture. Let me implement all steps. I'll start by adding the helper functions to
generator_utils.gleam, then update each vendor module.Step 1-5: Add all builder functions to generator_utils.gleam
Assistant
Now add the new functions at the end of generator_utils.gleam.
Assistant
Now update the vendor modules. Let me do all 4 in parallel.
Datadog — only Steps 1-2 (terraform_settings + provider):
Assistant
Now let me clean up unused imports from the vendor modules. With the delegation, some imports like
dict,option,list,resultmay no longer be needed in certain modules. Let me check what's still used.Assistant
The code looks good. Let me check if
gleam/listis now unused in dynatrace since its only use was in the oldgenerate_resources.Assistant
gleam/listis unused in dynatrace now. Let me remove it.Assistant
Now let me run the tests to verify everything works.
Assistant
All 232 tests pass on Erlang. Now let me run on JavaScript target.
Assistant
All 232 tests pass on both Erlang and JavaScript targets. Let me also run formatting to make sure the code is properly formatted.
Assistant
The files I modified need formatting. Let me fix them.
Assistant
Now let me verify the lint passes and run the full test suite across all packages.
Assistant
All CI passes — lint, build, and tests across all 3 packages. Let me also verify the JavaScript target as required.
Assistant
All 232 tests pass on both targets. Here's a summary of what was done:
Summary
Added 5 shared builder functions to
generator_utils.gleamand delegated boilerplate from all 4 vendor modules:generator_utils.gleam— 5 new@internal pub fn:build_terraform_settings— constructsTerraformSettingswith a single required providerbuild_provider— constructs aProviderwith name and attribute listgenerate_resources_simple—list.try_map+ empty warnings (for 1:1 IR→Resource)generate_resources_multi—list.try_map+list.flatten+ empty warnings (for 1:N IR→Resources)generate_terraform— assembles resources/settings/provider/variables, discards warnings
Vendor module changes:
Module terraform_settings- User
ok whats next?
Assistant
Looking at the recent commits and the refactoring we just completed, let me check if there's anything obvious remaining on this branch.
Assistant
There are uncommitted changes on this branch — both from our refactoring and from other modified files that were already dirty. The changes aren't committed yet and there are no commits ahead of main.
Would you like me to:
- Commit the changes (just our codegen refactoring files, or all modified files)?
- Something else — is there another task you'd like to work on?
- User
yes commit this firsy
Assistant
I see there are other modified files beyond our refactoring (formatting changes from
make lint-fix). I'll only commit our 5 codegen files.Assistant
Committed as
6d562a7. The remaining 13 modified files are formatting-only changes frommake lint-fixthat were pre-existing — not part of our refactoring.What's next?