feat(cli): background-agnostic describe highlighting with LSP-exact tokens - #4017
Conversation
…okens Three fixes to baml describe's terminal rendering, all in paint.rs: - Background-agnostic palette: colors are now restricted to the terminal's named ANSI palette (slots 0-15, which the terminal theme controls) plus dim/bold attributes. The fixed 256-color-cube values (173/179/214/244/245) and the forced white for variables are gone - ordinary names render at the default foreground, comments and operators use dim. - Modifiers are honored: declarations render bold, defaultLibrary (stdlib) entities italic, deprecated ones struck through. A dim-base token type trades dim for bold at its declaration instead of stacking both weights. - Synthesized fragments (keyword-doc examples, interface member signatures) now run through the exact compiler classifier the LSP uses - parsed as a scratch file in a thread-local in-memory project - instead of the hand-rolled lexer scanner, which colored only keywords/primitives/literals and left every other identifier plain. Names a fragment cannot resolve stay at the default foreground, matching editor behavior for unresolved names. The lexer fallback (PRIMITIVE_TYPES, decl_keyword_kind, is_keyword) is deleted; Highlighter::range and highlight_str share one token-render loop.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesSemantic highlighting
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Painter
participant ProjectDatabase
participant styled_from_tokens
Painter->>ProjectDatabase: Parse synthesized fragment and request semantic_tokens
ProjectDatabase-->>Painter: Return sorted tokens and modifiers
Painter->>styled_from_tokens: Apply token styles and render plain gaps
styled_from_tokens-->>Painter: Return styled fragment
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Binary size checks passed✅ 7 passed
Generated by |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@baml_language/crates/baml_cli/src/paint.rs`:
- Around line 100-140: Update tests covering style_for to validate rendered
styling behavior rather than searching output for individual SGR fragments such
as bold or color escapes. Account for console::Style combining multiple
attributes into one escape sequence, while preserving coverage for declaration,
color, italic, and strikethrough behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 788b25d5-7602-4854-b3f1-5c503a65a634
📒 Files selected for processing (1)
baml_language/crates/baml_cli/src/paint.rs
CodeRabbit review on #4017: console::Style may batch attributes into one escape sequence (\x1b[1;33m vs \x1b[1m\x1b[33m), so substring checks on individual fragments could reject valid output. The paint tests now decode SGR parameter lists into effects (attribute / palette-indexed / truecolor) and assert on the effects active at a given rendered name, which is encoding-shape independent. The stricter assertions also surfaced that constructor-position names classify syntactically even when unresolved, so the neutrality test now pins that behavior and checks true neutrality on a member of an unresolvable receiver instead.
Follow-up to #4011 (now on canary). Fixes three gaps that made
baml describehighlighting look worse than the same code in an editor:defaultLibrary(stdlib) entities italic, deprecated ones struck through — the same signals editor themes derive from the LSP modifier bitset, previously discarded. Dim-base token types trade dim for bold at their declaration instead of stacking contradictory weights.semantic_tokens— replacing the hand-rolled lexer scanner that colored only keywords/primitives/literals. Names a context-free fragment can't resolve stay neutral, exactly like an editor. The scanner (PRIMITIVE_TYPES,decl_keyword_kind,is_keyword) is deleted andHighlighter::range/highlight_strnow share one render loop.Tests
baml_clisuite 343/343 (describe snapshots are colorless and unaffected); clippy clean.describe deferkeyword page with forced color.Summary by CodeRabbit