Skip to content

fix: warn when atomize blocks missing from highlight template#90

Open
TyceHerrman wants to merge 1 commit into
jsonMartin:masterfrom
TyceHerrman:fix/warn-atomize-blocks-missing
Open

fix: warn when atomize blocks missing from highlight template#90
TyceHerrman wants to merge 1 commit into
jsonMartin:masterfrom
TyceHerrman:fix/warn-atomize-blocks-missing

Conversation

@TyceHerrman
Copy link
Copy Markdown

@TyceHerrman TyceHerrman commented Mar 19, 2026

Summary

Closes #88

  • Adds a warning in the settings UI (below the atomic highlights toggle) when the highlight template has no atomize blocks
  • Adds a sync-time notice when atomic highlights is enabled but no atomize blocks are present
  • Updates the default highlight template to include {% atomize %} blocks for new installations
  • Hardens the atomizer's basename handling to coerce non-string values and fall back to highlight ID

Test plan

  • Enable atomic highlights with a custom template that has NO atomize blocks → warning appears below toggle in settings
  • Enable atomic highlights with the default template (has atomize blocks) → no warning
  • Disable atomic highlights → warning disappears immediately
  • Sync with atomic highlights enabled + no atomize blocks → notice appears
  • Sync with atomic highlights enabled + atomize blocks present → no notice
  • Disable atomic highlights, use default template, render a highlight → verify output matches pre-change behavior (COMPOSITE mode strips wrapper)
  • Enable atomic highlights with default template → atoms created with numeric ID filenames
  • Verify basename=id (numeric) doesn't throw in FIRST or SECOND pass

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added validation and notification alerts for atomic highlights configuration
    • Settings tab now displays guidance on required atomize block syntax when using atomic highlights
  • Improvements

    • Enhanced template variable handling with improved type coercion and fallback logic
    • Refined filename sanitization for generated atomic notes

When users enable atomic highlights but don't add atomize blocks to their
highlight template, the plugin silently creates an empty Highlight/ folder.
This adds warnings in both settings UI and at sync time, updates the default
highlight template to include atomize blocks for new users, and hardens the
atomizer against non-string basename values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3088e21-9738-4f25-acb0-b8655e869343

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf33ec and 55d809f.

📒 Files selected for processing (5)
  • src/constants/index.ts
  • src/main.ts
  • src/services/atomizer.ts
  • src/ui/settings-tab.ts
  • src/utils/template-utils.ts

📝 Walkthrough

Walkthrough

This pull request implements template validation and user-facing warnings for atomic highlights. It updates the default highlight template to include atomize blocks, adds a utility function to detect atomize syntax, performs preflight validation during sync, displays UI warnings when atomize blocks are missing despite enabled settings, and improves basename coercion safety in the atomizer service.

Changes

Cohort / File(s) Summary
Default Template Update
src/constants/index.ts
Wrapped DEFAULT_SETTINGS.highlightTemplate with {% atomize %}...{% endatomize %} blocks and passed id, basename, and embed=true parameters.
Template Validation Utilities
src/utils/template-utils.ts
Added hasAtomizeBlocks() function to detect both Nunjucks-style and custom delimiter (%%!) atomize block syntax in templates.
Atomic Highlights Validation
src/main.ts, src/ui/settings-tab.ts
Imported and integrated hasAtomizeBlocks utility; added preflight notice during sync when atomic highlights are enabled but template lacks atomize blocks; added UI warning in settings with example syntax and wiki link; updated toggle handler to refresh UI state after changes.
Atomizer Service
src/services/atomizer.ts
Improved basename argument coercion by explicitly converting to string before regex/trim operations and guaranteed fallback to _id when sanitized result is empty, ensuring safe handling of null/undefined/non-string values.

Sequence Diagram

sequenceDiagram
    participant User
    participant Settings as Settings UI
    participant Main as Main Plugin
    participant Atomizer as Atomizer Service
    
    User->>Settings: Enable atomic highlights toggle
    Settings->>Main: saveSettings() + display()
    Settings->>Settings: Check hasAtomizeBlocks() on template
    alt Atomize blocks detected
        Settings->>Settings: Show normal description
    else Atomize blocks missing
        Settings->>Settings: Display warning with code example
    end
    
    Note over User,Settings: Later during sync...
    User->>Main: Trigger sync/update
    Main->>Main: Check if atomicHighlights enabled
    Main->>Main: Check hasAtomizeBlocks(highlightTemplate)
    alt Blocks found
        Main->>Atomizer: Execute atomization
        Atomizer->>Atomizer: Process with atomize blocks
    else Blocks NOT found
        Main->>User: Show notice: "atomic highlights enabled but no atomize blocks found"
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #80: Introduced the Atomizer/AtomizeExtension subsystem and core atomize block functionality that this PR builds validation and user warnings upon.

Suggested labels

released

Poem

🐰 A template wrapped in atomize blocks so neat,
With warnings now shown when the syntax's incomplete,
No silent failures—just helpful direction,
The rabbit ensures every highlight's perfection! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a warning when atomize blocks are missing from the highlight template, which is the core feature of this PR.
Linked Issues check ✅ Passed All requirements from #88 are met: warnings added in settings UI and sync notices when atomic highlights are enabled without atomize blocks, plus hardened basename handling and updated default template.
Out of Scope Changes check ✅ Passed All changes directly support the PR objective of warning users about missing atomize blocks and preventing silent failures. The basename handling hardening is a reasonable safety improvement for the atomizer.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can get early access to new features in CodeRabbit.

Enable the early_access setting to enable early access features such as new models, tools, and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[IMPROVEMENT] Enabling atomic highlights toggle without template changes silently does nothing

1 participant