Skip to content

feat(vscode): syntax-highlight code blocks and show a cursor while streaming - #1796

Merged
addyCooks merged 3 commits into
Nano-Collective:mainfrom
addyCooks:feat/751-vscode-streaming-syntax-highlight
Nov 3, 2026
Merged

addyCooks merged 3 commits into
Nano-Collective:mainfrom
addyCooks:feat/751-vscode-streaming-syntax-highlight

Conversation

@addyCooks

Copy link
Copy Markdown
Collaborator

Closes #751

Description

The VS Code chat panel rendered fenced code with no colour at all, while streaming and once finished. The issue assumed the renderer waits for the closing backticks, but the vendored marked v15 already turns a still-open fence into <pre><code class="language-x">, so the missing piece is a highlighter.

  • Syntax highlighting. Vendors a small highlight.js bundle (media/highlight.min.js, 16 common languages, the same static-file approach as marked.min.js, no new dependency) and registers one marked code renderer (media/markdown-highlight.js). Every marked.parse() in the panel, meaning streaming text, finished text and thought bubbles, is highlighted with no per-call-site changes. A language still being typed (py, pyth) falls back to plain escaped text instead of throwing. Token colours follow the light or dark VS Code theme.
  • Streaming cursor. A pure-CSS blinking ▌ on the assistant text block that is still receiving chunks. It is cleared when a tool call starts the next block and in setProcessing(false) (completed, cancelled or failed), and it respects prefers-reduced-motion.

The highlighting hook lives in its own small file so it can be unit tested in Node like the other media helpers.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (extension README)
  • No breaking changes
  • Appropriate logging added using structured logging (no runtime paths that need logging)

…reaming

The chat panel rendered fenced code with no colour at all, while streaming and
once finished. marked already turns a still-open fence into <pre><code>, so the
missing piece is a highlighter, not waiting for the closing backticks.

Vendor a small highlight.js bundle (16 common languages, the same static-file
approach as marked.min.js, no new dependency) and register one marked code
renderer, so every marked.parse() in the panel (streaming text, finished text,
thought bubbles) is highlighted. A language still being typed (py, pyth) falls
back to plain escaped text instead of throwing. Token colours follow the light or
dark VS Code theme.

Add a pure-CSS blinking cursor (U+258C) on the assistant text block that is still
receiving chunks. It is cleared when a tool call starts the next block and when the
turn completes, is cancelled or fails, and it respects prefers-reduced-motion.

The highlighting hook lives in media/markdown-highlight.js so it can be unit tested
in Node like the other media helpers.

Closes Nano-Collective#751
@github-actions github-actions Bot added the area:vscode VS Code extension and host integration label Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: nothing to raise

@addyCooks — nothing to raise from the automated review.

PR #1796 closes issue #751 by vendoring a small highlight.js bundle (v10.7.3, 16 languages) and registering a marked code hook in markdown-highlight.js, plus a .streaming-cursor CSS class with a blinking ▌ glyph that is added when an agent text block starts and cleared in endCurrentTextBlock and setProcessing(false). The hook handles partial language names, prototype-pollution names like __proto__, and highlighter throws by falling back to escaped plain text; XSS payloads and a hostile info-string breakout are covered by the new spec, which loads the real bundles via node:vm so it is not the 'test that asserts nothing' failure mode. The changeset, README bump, script-tag ordering and asset-version URI plumbing match the surrounding code, and both halves of issue #751 (highlights + cursor) are addressed.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:clean nc-review had nothing to raise label Oct 16, 2026
CodeQL flags the visibleText helper (js/incomplete-multi-character-
sanitization): it removed tags with a regex and then decoded entities, which
can reassemble a <script. Skip tags with a scan and decode entities in a
single pass instead. Test behaviour is unchanged.
chat-panel.js now calls NanocoderMarkdownHighlight.configureMarkdown at
load, but the VM harness only ran the mention, uri and slash command
helpers first, so every spec that boots the panel threw a TypeError.
Run markdown-highlight.js before the panel, as chat-panel.html does.
@addyCooks
addyCooks merged commit 645a9d8 into Nano-Collective:main Nov 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:clean nc-review had nothing to raise area:vscode VS Code extension and host integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Streaming Markdown & Code Syntax Highlighting Polish in VS Code Extension

2 participants