Skip to content

feat(ask): syntax-highlight answer code blocks and linkify citations - #4

Merged
RutaTang merged 1 commit into
mainfrom
feat/ask-rich-answers
Aug 3, 2026
Merged

feat(ask): syntax-highlight answer code blocks and linkify citations#4
RutaTang merged 1 commit into
mainfrom
feat/ask-rich-answers

Conversation

@RutaTang

@RutaTang RutaTang commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Two UX gaps in Ask answers (and Explain views — the renderer is shared):

Syntax highlighting for code blocks

Fenced code went through iced's markdown widget, which renders it as flat monospace (the iced highlighter feature is deliberately off — its themes don't match). Fenced blocks are now their own segment, highlighted with clew's own tree-sitter pipeline at prepare time: answer code gets the exact same palette as the editor, on the editor background, scrolling horizontally instead of wrapping. lang_for_fence maps the common fence tags and aliases (rust/rs, py, ts, golang, …); unknown languages fall back to plain lines. Mermaid fences keep their existing diagram path.

Clickable citations

path:line citations were inert code chips. They now become links (clew: scheme) that jump straight to that file and line in the editor — exactly what the panel's own tagline promises. Resolution is conservative so prose code chips stay chips:

  • exact project rels (src/app/update.rs:62), with :a-b ranges collapsing to their start
  • bare basenames only when unique in the project (theme.rs:37)
  • type names / non-files (Vec<String>) are left alone; fenced blocks are never touched

Tested

  • richmd unit tests: fence→Code segmentation, linkify (exact rel, range collapse, unique basename, non-file negatives, fence immunity)
  • Live: asked about the horizontal-scroll extent — the answer rendered a fully-highlighted Rust block and every citation link jumped to the right line (including codeview.rs:668 where the blame line shows this morning's fix).

Answers (and explanations — the renderer is shared) previously pushed
fenced code through iced's markdown widget, which renders it as plain
monospace: no colors at all. And path:line citations were inert code
chips you had to retype into the finder.

- richmd: fenced blocks become their own Segment::Code (mermaid keeps
  its diagram path); prepare_segments highlights them with clew's own
  tree-sitter pipeline (lang_for_fence maps the common fence tags and
  aliases), so answer code gets the exact palette of the editor. The
  block renders on the editor background and scrolls horizontally
  instead of wrapping.
- richmd::linkify_citations: inline-code citations (path:line,
  path:a-b ranges, bare paths, and unique basenames like theme.rs)
  become clew: links when they resolve to a real project file — type
  names and non-files stay code chips. OpenLink handles the clew:
  scheme by jumping to that file and line in the editor.
- Fence contents are never math-scanned or linkified.
@RutaTang
RutaTang merged commit 7353d19 into main Aug 3, 2026
3 checks passed
@RutaTang
RutaTang deleted the feat/ask-rich-answers branch August 3, 2026 09:31
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