Repository navigation
feat(fetcher): add code_language_logo for repo-language Devicon hero - #169
Conversation
Detects the dominant language across the discovered repo's tracked files (file-count, no blob reads via the new `for_each_tracked_path` scan helper) and emits the matching Devicon PNG via the `Image` shape. Bundles 35 logos plus a generic `</>` fallback; assets extract once into `$SPLASHBOARD_HOME/cache/logos/<slug>.png` so `media_image` can render from a stable path. The intended hero for the upcoming `project_codebase` preset (#164). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR adds a new code language logo fetcher that detects the dominant programming language in a git repository and returns the corresponding bundled devicon PNG asset. It includes embedded language logos, an asset lookup module, path scanning utilities, and license documentation. Changes
Sequence DiagramsequenceDiagram
actor User
participant Fetcher as CodeLanguageLogo<br/>Fetcher
participant Repo as Git Repository
participant LangDetect as Language<br/>Detection
participant AssetLookup as Logo Assets
participant Cache as Cache<br/>Directory
participant Disk as Disk
User->>Fetcher: fetch(repo, options)
alt Language option provided
Fetcher->>LangDetect: use override language
else Auto-detect
Fetcher->>Repo: for_each_tracked_path()
Repo-->>Fetcher: iterate paths
Fetcher->>LangDetect: classify & count by language
LangDetect-->>Fetcher: dominant language label
end
Fetcher->>AssetLookup: asset_for(language)
AssetLookup-->>Fetcher: (slug, png_bytes)
Fetcher->>Cache: ensure logos/ subdir exists
Cache-->>Disk: create directory
Fetcher->>Disk: write PNG bytes to file
Disk-->>Fetcher: file path
Fetcher->>User: return image Payload
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #169 +/- ##
==========================================
+ Coverage 78.34% 78.50% +0.15%
==========================================
Files 128 130 +2
Lines 24394 24654 +260
==========================================
+ Hits 19112 19354 +242
- Misses 5282 5300 +18
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/fetcher/code/language_logo.rs`:
- Around line 117-130: ensure_extracted currently skips writing when a file
exists, causing stale cached PNGs to persist across releases; update
ensure_extracted to compare the existing file size to bytes.len() (use
std::fs::metadata(&path)?.len()) and if lengths differ, overwrite the file
(std::fs::write) so updated bundled bytes replace the cached file, mapping any
IO errors to FetchError::Failed as done now; keep the same stable slug-based
path logic (dir = logos_cache_dir(), path = dir.join(format!("{slug}.png"))).
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 22b706a0-b0c0-481e-8fa0-c04adef80808
⛔ Files ignored due to path filters (72)
assets/logos/png/_generic.pngis excluded by!**/*.pngassets/logos/png/c.pngis excluded by!**/*.pngassets/logos/png/clojure.pngis excluded by!**/*.pngassets/logos/png/cpp.pngis excluded by!**/*.pngassets/logos/png/csharp.pngis excluded by!**/*.pngassets/logos/png/css.pngis excluded by!**/*.pngassets/logos/png/dart.pngis excluded by!**/*.pngassets/logos/png/dockerfile.pngis excluded by!**/*.pngassets/logos/png/elixir.pngis excluded by!**/*.pngassets/logos/png/erlang.pngis excluded by!**/*.pngassets/logos/png/go.pngis excluded by!**/*.pngassets/logos/png/groovy.pngis excluded by!**/*.pngassets/logos/png/haskell.pngis excluded by!**/*.pngassets/logos/png/html.pngis excluded by!**/*.pngassets/logos/png/java.pngis excluded by!**/*.pngassets/logos/png/javascript.pngis excluded by!**/*.pngassets/logos/png/julia.pngis excluded by!**/*.pngassets/logos/png/kotlin.pngis excluded by!**/*.pngassets/logos/png/lua.pngis excluded by!**/*.pngassets/logos/png/nim.pngis excluded by!**/*.pngassets/logos/png/ocaml.pngis excluded by!**/*.pngassets/logos/png/perl.pngis excluded by!**/*.pngassets/logos/png/php.pngis excluded by!**/*.pngassets/logos/png/powershell.pngis excluded by!**/*.pngassets/logos/png/python.pngis excluded by!**/*.pngassets/logos/png/r.pngis excluded by!**/*.pngassets/logos/png/ruby.pngis excluded by!**/*.pngassets/logos/png/rust.pngis excluded by!**/*.pngassets/logos/png/scala.pngis excluded by!**/*.pngassets/logos/png/shell.pngis excluded by!**/*.pngassets/logos/png/svelte.pngis excluded by!**/*.pngassets/logos/png/swift.pngis excluded by!**/*.pngassets/logos/png/terraform.pngis excluded by!**/*.pngassets/logos/png/typescript.pngis excluded by!**/*.pngassets/logos/png/vue.pngis excluded by!**/*.pngassets/logos/png/zig.pngis excluded by!**/*.pngassets/logos/svg/_generic.svgis excluded by!**/*.svgassets/logos/svg/c.svgis excluded by!**/*.svgassets/logos/svg/clojure.svgis excluded by!**/*.svgassets/logos/svg/cpp.svgis excluded by!**/*.svgassets/logos/svg/csharp.svgis excluded by!**/*.svgassets/logos/svg/css.svgis excluded by!**/*.svgassets/logos/svg/dart.svgis excluded by!**/*.svgassets/logos/svg/dockerfile.svgis excluded by!**/*.svgassets/logos/svg/elixir.svgis excluded by!**/*.svgassets/logos/svg/erlang.svgis excluded by!**/*.svgassets/logos/svg/go.svgis excluded by!**/*.svgassets/logos/svg/groovy.svgis excluded by!**/*.svgassets/logos/svg/haskell.svgis excluded by!**/*.svgassets/logos/svg/html.svgis excluded by!**/*.svgassets/logos/svg/java.svgis excluded by!**/*.svgassets/logos/svg/javascript.svgis excluded by!**/*.svgassets/logos/svg/julia.svgis excluded by!**/*.svgassets/logos/svg/kotlin.svgis excluded by!**/*.svgassets/logos/svg/lua.svgis excluded by!**/*.svgassets/logos/svg/nim.svgis excluded by!**/*.svgassets/logos/svg/ocaml.svgis excluded by!**/*.svgassets/logos/svg/perl.svgis excluded by!**/*.svgassets/logos/svg/php.svgis excluded by!**/*.svgassets/logos/svg/powershell.svgis excluded by!**/*.svgassets/logos/svg/python.svgis excluded by!**/*.svgassets/logos/svg/r.svgis excluded by!**/*.svgassets/logos/svg/ruby.svgis excluded by!**/*.svgassets/logos/svg/rust.svgis excluded by!**/*.svgassets/logos/svg/scala.svgis excluded by!**/*.svgassets/logos/svg/shell.svgis excluded by!**/*.svgassets/logos/svg/svelte.svgis excluded by!**/*.svgassets/logos/svg/swift.svgis excluded by!**/*.svgassets/logos/svg/terraform.svgis excluded by!**/*.svgassets/logos/svg/typescript.svgis excluded by!**/*.svgassets/logos/svg/vue.svgis excluded by!**/*.svgassets/logos/svg/zig.svgis excluded by!**/*.svg
📒 Files selected for processing (5)
assets/logos/LICENSE-devicon.txtsrc/fetcher/code/language_logo.rssrc/fetcher/code/logo_assets.rssrc/fetcher/code/mod.rssrc/fetcher/code/scan.rs
| /// Materialises the bundled bytes onto disk so `media_image` (which only takes a path) can | ||
| /// open them. Stable per-slug filename under the cache dir means repeat invocations reuse the | ||
| /// same file and ratatui-image's protocol can warm-cache decoded frames. | ||
| fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> { | ||
| let dir = logos_cache_dir()?; | ||
| std::fs::create_dir_all(&dir) | ||
| .map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?; | ||
| let path = dir.join(format!("{slug}.png")); | ||
| if !path.exists() { | ||
| std::fs::write(&path, bytes) | ||
| .map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?; | ||
| } | ||
| Ok(path) | ||
| } |
There was a problem hiding this comment.
Stale-cache hazard across upgrades: path.exists() short-circuits even when bundled bytes change.
ensure_extracted only writes when the file is missing, so once a slug's PNG exists in $SPLASHBOARD_HOME/cache/logos/, the bundled-byte version is never picked up again. If a future release re-rasterizes the Devicon SVGs (or the image pipeline produces different PNG bytes), upgraded users will keep rendering the old logo until they manually wipe the cache. Worth invalidating on byte-length drift now while the surface is small.
🛡️ Proposed fix — invalidate when bundled length differs from cached length
fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> {
let dir = logos_cache_dir()?;
std::fs::create_dir_all(&dir)
.map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?;
let path = dir.join(format!("{slug}.png"));
- if !path.exists() {
+ let stale = std::fs::metadata(&path)
+ .map(|m| m.len() != bytes.len() as u64)
+ .unwrap_or(true);
+ if stale {
std::fs::write(&path, bytes)
.map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?;
}
Ok(path)
}Alternatively, embed a short content-hash in the on-disk filename (e.g., rust-<8hex>.png) so byte changes pick a fresh path and old files become harmless orphans — slightly more robust against same-length-but-different-bytes drift, at the cost of an extra hash on every fetch.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /// Materialises the bundled bytes onto disk so `media_image` (which only takes a path) can | |
| /// open them. Stable per-slug filename under the cache dir means repeat invocations reuse the | |
| /// same file and ratatui-image's protocol can warm-cache decoded frames. | |
| fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> { | |
| let dir = logos_cache_dir()?; | |
| std::fs::create_dir_all(&dir) | |
| .map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?; | |
| let path = dir.join(format!("{slug}.png")); | |
| if !path.exists() { | |
| std::fs::write(&path, bytes) | |
| .map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?; | |
| } | |
| Ok(path) | |
| } | |
| /// Materialises the bundled bytes onto disk so `media_image` (which only takes a path) can | |
| /// open them. Stable per-slug filename under the cache dir means repeat invocations reuse the | |
| /// same file and ratatui-image's protocol can warm-cache decoded frames. | |
| fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> { | |
| let dir = logos_cache_dir()?; | |
| std::fs::create_dir_all(&dir) | |
| .map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?; | |
| let path = dir.join(format!("{slug}.png")); | |
| let stale = std::fs::metadata(&path) | |
| .map(|m| m.len() != bytes.len() as u64) | |
| .unwrap_or(true); | |
| if stale { | |
| std::fs::write(&path, bytes) | |
| .map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?; | |
| } | |
| Ok(path) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/fetcher/code/language_logo.rs` around lines 117 - 130, ensure_extracted
currently skips writing when a file exists, causing stale cached PNGs to persist
across releases; update ensure_extracted to compare the existing file size to
bytes.len() (use std::fs::metadata(&path)?.len()) and if lengths differ,
overwrite the file (std::fs::write) so updated bundled bytes replace the cached
file, mapping any IO errors to FetchError::Failed as done now; keep the same
stable slug-based path logic (dir = logos_cache_dir(), path =
dir.join(format!("{slug}.png"))).
Summary
Adds
code_language_logo, a newcode_*family fetcher that detects the dominant programming language from the discovered git repo's tracked files and renders the matching Devicon PNG via theImageshape. Designed as the hero widget for the upcomingproject_codebasepreset (#164).for_each_tracked_pathscan helper alongside the existingfor_each_tracked_file).</>fallback.rsvg-convert); both the SVG sources and PNGs are committed. ~480 KB total.$SPLASHBOARD_HOME/cache/logos/<slug>.pngsomedia_image(which only takes a path) can render from a stable location.languageoverride skips auto-detection — useful for repos where the file-count majority isn't the language you want to lead with, and for non-repo contexts.Ticks the
code_language_logobox on thecode_*checklist in #62; closes the hero slot for theproject_codebasepreset tracked in #164.Reference
imageOptions
languagecode_*classifier (Rust,Go,Python, …); unknown values fall back to the generic</>glyph.Compatible renderers
imageanimated_boot,animated_postfx,animated_scanlines,animated_splitflap,animated_wave,media_imageLicensing
Devicon assets are MIT-licensed; the upstream
LICENSEis committed verbatim atassets/logos/LICENSE-devicon.txt. Generic</>glyph is a hand-authored SVG (no third-party content).Test plan
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test— 945 passed / 0 failed (8 new tests cover dominant-language detection, empty / unclassified paths, asset extraction idempotence, options parsing, and cache-key uniqueness)language = "Python"/ unknown language → generic) using themedia_imagerenderer🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Chores