Highlight .dart, .nix, and .groovy files in read/write views (#11790)

The `read` and `write` tool views find a file's language from its
extension with `getLanguageFromPath()`. That function's extension table
had no entries for Dart, Nix, or Groovy. Their highlight.js grammars are
loaded at startup, but the lookup returned `undefined`, so these files
were shown as plain uncolored text.

This change adds `dart → dart`, `nix → nix`, `groovy → groovy`, and
`gradle → groovy` to the table in
`packages/coding-agent/src/modes/interactive/theme/theme.ts`.

HTML export keeps its own separate extension map and a vendored
highlight bundle without a Dart grammar. This change does not touch
either.

## Testing

- Added a test to `test/syntax-highlight.test.ts` that checks the new
extension mappings. It fails without the fix and passes with it.
- `node ../../node_modules/vitest/dist/cli.js --run
test/syntax-highlight.test.ts` passes.
- Before, `getLanguageFromPath("a.dart")` (and `.nix`, `.groovy`,
`build.gradle`) returned `undefined` from the built dist. After, they
return `dart`, `nix`, `groovy`, and `groovy`.
- `npm run check` reports 6 type errors in `packages/ai/test` (model ID
types). Main without this change has the same 6 errors.

Fixes #11643

Requested by @badlogic

Co-authored-by: triagent <triagent@localhost>
This commit is contained in:
robopipi[bot] 2026-11-04 10:45:55 +01:00 • committed by GitHub
parent c5d3978350
commit c13f6acfbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -1,6 +1,12 @@
import { resetCapabilitiesCache, setCapabilities } from "@earendil-works/pi-tui";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { getMarkdownTheme, highlightCode, initTheme, theme } from "../src/modes/interactive/theme/theme.ts";
import {
getLanguageFromPath,
getMarkdownTheme,
highlightCode,
initTheme,
theme,
} from "../src/modes/interactive/theme/theme.ts";
import {
highlight,
loadAllHighlightLanguages,
@ -41,6 +47,14 @@ describe("syntax highlight renderer", () => {
expect(supportsLanguage("ada")).toBe(true);
});
it("maps file extensions of eagerly loaded languages to their language", () => {
expect(getLanguageFromPath("lib/main.dart")).toBe("dart");
expect(getLanguageFromPath("flake.nix")).toBe("nix");
expect(getLanguageFromPath("script.groovy")).toBe("groovy");
expect(getLanguageFromPath("build.gradle")).toBe("groovy");
expect(getLanguageFromPath("src/Main.kt")).toBe("kotlin");
});
it("renders highlighted spans with the provided theme", () => {
const rendered = renderHighlightedHtml('<span class="hljs-keyword">const</span> value', {
keyword: (text) => `[keyword:${text}]`,