Inject ``body`` between the ``CODEGEN_ `` markers in ``text``. When the markers are missing AND the body is non-empty, fire a diagnostic that names the host kind (e.g. 'subclass header'), the path, the tag, and what didn't land. Returns (new_text, ok). This collapses ~12 near-id
(
text: str,
tag: str,
body: str,
*,
host_path: str,
host_kind: str,
block_label: str,
diag_source: str,
)
| 231 | |
| 232 | |
| 233 | def _inject_or_diag( |
| 234 | text: str, |
| 235 | tag: str, |
| 236 | body: str, |
| 237 | *, |
| 238 | host_path: str, |
| 239 | host_kind: str, |
| 240 | block_label: str, |
| 241 | diag_source: str, |
| 242 | ) -> Tuple[str, bool]: |
| 243 | """Inject ``body`` between the ``CODEGEN_<tag>`` markers in ``text``. |
| 244 | When the markers are missing AND the body is non-empty, fire a |
| 245 | diagnostic that names the host kind (e.g. 'subclass header'), the |
| 246 | path, the tag, and what didn't land. Returns (new_text, ok). |
| 247 | |
| 248 | This collapses ~12 near-identical try-inject-then-diag stanzas |
| 249 | that used to live in the emit_*_class_injection callers.""" |
| 250 | new_text, ok = inject_between_tags(text, tag, body, balance_source=diag_source) |
| 251 | if not ok and body.strip(): |
| 252 | _diag_add( |
| 253 | f"[diagnostic] {host_kind} '{host_path}' is missing the " |
| 254 | f"CODEGEN_{tag}_START/END marker pair; {block_label} was " |
| 255 | f"NOT injected.", |
| 256 | source=diag_source, |
| 257 | ) |
| 258 | return new_text, ok |
| 259 | |
| 260 | |
| 261 | def _guarded_export(toggle: str, body: str, |
no test coverage detected