Skip to content

fix(editor): cache rainbow bracket tokenization and improve the rainbow bracket related issues happens when editing#2012

Merged
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/rainbow-brackets-cache
Apr 4, 2026
Merged

fix(editor): cache rainbow bracket tokenization and improve the rainbow bracket related issues happens when editing#2012
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/rainbow-brackets-cache

Conversation

@bajrangCoder
Copy link
Copy Markdown
Member

No description provided.

…ow bracket related issues happens when editing
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 4, 2026

Greptile Summary

This PR rewrites the rainbow brackets plugin to use a block-based LRU cache (2048-char blocks, 192-entry max) that avoids re-tokenizing unchanged text on every keystroke, and makes rainbow bracket colors theme-aware by deriving them from the active theme config. A new update:editorTheme listener in editorManager.js ensures the rainbow compartment is reconfigured whenever the editor theme changes.

All remaining findings are P2 style suggestions: a redundant != null guard on an array length check, a redundant /i flag on a regex whose input is already lowercased, and the removal of RAF debouncing that could cause occasional main-thread blocking on large pastes.

Confidence Score: 5/5

Safe to merge — all findings are non-blocking P2 style suggestions with no correctness or data-integrity issues

The block cache logic is correct, LRU eviction via Map insertion order is well-implemented, theme color derivation is sound, and the editorTheme listener properly re-applies colors on theme change. No P0/P1 issues were found.

src/cm/rainbowBrackets.ts deserves a future pass to consider restoring RAF debouncing for large-paste scenarios, but this is not a blocker

Important Files Changed

Filename Overview
src/cm/rainbowBrackets.ts Complete rewrite adding block-based LRU cache and theme-aware colors; minor redundancies in normalizeHexColor regex flag and the colors guard; synchronous rebuild is a potential latency trade-off worth documenting
src/lib/editorManager.js Adds makeRainbowBracketExtension() factory and update:editorTheme listener to correctly sync rainbow bracket colors when the editor theme changes

Sequence Diagram

sequenceDiagram
    participant U as User
    participant S as appSettings
    participant EM as editorManager
    participant F as makeRainbowBracketExtension
    participant RB as rainbowBrackets()
    participant RC as rainbowCompartment

    U->>S: change editorTheme
    S->>EM: emit update:editorTheme
    EM->>EM: editor.setTheme(newThemeId)
    Note over EM: themeCompartment reconfigured
    EM->>F: applyOptions(["rainbowBrackets"])
    F->>F: getThemeConfig(themeId)
    F->>RB: getRainbowBracketColors(config)
    RB-->>F: theme-appropriate colors[]
    F->>RB: rainbowBrackets({ colors })
    RB-->>RC: [ViewPlugin, baseTheme]
    RC->>EM: reconfigure compartment with new colors
Loading

Reviews (1): Last reviewed commit: "fix(editor): cache rainbow bracket token..." | Re-trigger Greptile

@bajrangCoder bajrangCoder merged commit ca5cb77 into Acode-Foundation:main Apr 4, 2026
6 checks passed
@bajrangCoder bajrangCoder deleted the fix/rainbow-brackets-cache branch April 4, 2026 19:29
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.

1 participant