Add StyleOverride trait and rainbow brackets for terminal formatter#730
Add StyleOverride trait and rainbow brackets for terminal formatter#730dannote wants to merge 3 commits into
Conversation
Clippy nightly flags derivable_impls lint. Replace manual Default impl with #[derive(Default)].
|
@leandrocp Pushed a fix for the clippy nightly lint ( |
|
Hey @dannote thanks for the contribution! I like the ideia of opening formatters for extension, I'll review it today to check if it does fit other use cases that we need to cover. At first glance I can tell:
|
|
Thanks for the pointers — I added support for the standard rainbow delimiter theme groups and pushed it. What changed:
I also kept the generated theme diff scoped to only adding |
Motivation
Rainbow brackets — color-coding nested delimiters by depth — is a standard feature in editors (Helix, Neovim's rainbow-delimiters.nvim, VS Code). Adding it to Lumis makes terminal output more readable for deeply nested code.
Rather than a one-off feature, this introduces a generic
StyleOverridetrait inlumis-corethat any formatter consumer can implement. Rainbow brackets are the first concrete implementation.What changed
Core:
StyleOverridetrait (lumis-core)New
pub trait StyleOverride: Send + Sync + Debuginformatter/mod.rs:text/scope— the token and its highlight scope namebase— the style resolved from the themestate— mutableusizethat persists across tokens (e.g. nesting depth)The terminal formatter calls the override after resolving the theme style. Zero cost when
None— same code path as before.The override also fires when the theme has no style for a scope but a scope exists, so rainbow brackets work without a theme.
Built-in:
RainbowBrackets(lumis-core)Colors
punctuation.brackettokens with a cycling palette based on nesting depth. Lives inlumis-coreso all runtimes (CLI, Rust API, Elixir NIF) can use it.CLI:
--rainbow-bracketsflagElixir:
rainbow_bracketsoptionNew
Lumis.RainbowBracketsmodule withnew/0(defaults) andnew/1(custom colors). Empty color list is rejected on both sides.Rust API
Docs
--rainbow-bracketsflag and exampleNot in scope (future work)
Files changed
lumis-core/formatter/mod.rslumis-core/formatter/terminal.rslumis-core/formatter/rainbow_brackets.rs(new)lumis/formatter/terminal.rslumis/formatter/mod.rslumis-cli/main.rslumis_nif/src/elixir.rslumis.exlumis/rainbow_brackets.ex(new)lumis_test.exsterminal.mdx,commands.mdxTest coverage
lumis+ 43lumis-core+ 31lumis-cli)cargo fmt --checkcleancargo clippy -- -D warningscleanmix format --check-formattedclean