Skip to content

feat: add C# syntax highlighting#1651

Open
dev693-ai wants to merge 1 commit into
getpaseo:mainfrom
dev693-ai:feat/csharp-highlighting
Open

feat: add C# syntax highlighting#1651
dev693-ai wants to merge 1 commit into
getpaseo:mainfrom
dev693-ai:feat/csharp-highlighting

Conversation

@dev693-ai

@dev693-ai dev693-ai commented Jun 21, 2026

Copy link
Copy Markdown

Linked issue

Closes #1527

Type of change

  • New feature (with prior issue + design alignment)

What does this PR do

Adds C# (.cs) syntax highlighting, implementing the request in #1527 (proposed with a patch by @percyboy). It wires the @replit/codemirror-lang-csharp Lezer grammar into @getpaseo/highlight following the existing per-language pattern (Java/Rust/Swift), and aliases the csharp / c# markdown fence names to cs.

This makes C# highlight everywhere code is rendered through the shared highlighter — the file viewer, diff views, and ```csharp / ```cs / ```c# markdown code fences in agent messages.

One deliberate change from the patch in the issue: I register csharpLanguage.parser, not the package's raw parser export. The Replit package applies its highlight styleTags only inside csharpLanguage (via parser.configure), so the raw parser would produce a valid tree but render with no highlighting. This differs from @lezer/java etc., whose parser export ships highlight props baked in.

Changed files:

  • packages/highlight/package.json — add @replit/codemirror-lang-csharp
  • packages/highlight/src/parsers.ts — register cs: csharpLanguage.parser
  • packages/app/src/components/highlighted-code-block.tsxcsharp / c# fence aliases
  • packages/highlight/src/__tests__/* — parser + highlighter test cases

How did you verify it

  • Added unit tests and ran the two changed suites:
    npx vitest run packages/highlight/src/__tests__/{parsers,highlighter}.test.ts → 23 passed, including the new C# cases (asserts class → keyword, string → string).

  • npm run build:server then npm run typecheck → clean across all workspaces.

  • npm run lint → 0 warnings / 0 errors. npm run format → clean.

  • Opened a real .cs file (Program.cs) in the running Paseo app and confirmed full highlighting (keywords, types, method names, switch pattern matching, interpolated strings, LINQ, comments), on web and desktop (Electron):

    Web (browser):

csharp-app-web

Desktop (Electron):
csharp-app-desktop

Verified on web + desktop; iOS/Android render through the identical cross-platform component (no platform-gated code in the highlight path), so they were not separately captured.

Checklist

  • One focused change. Unrelated cleanups split out.
  • npm run typecheck passes
  • npm run lint passes
  • npm run format ran (Biome)
  • UI change includes screenshots (web + desktop)
  • Tests added or updated where it made sense

@greptile-apps

greptile-apps Bot commented Jun 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds C# (.cs) syntax highlighting by wiring the @replit/codemirror-lang-csharp Lezer grammar into the @getpaseo/highlight package and aliasing the csharp / c# markdown fence names in the app component.

  • packages/highlight/src/parsers.ts: Registers cs: csharpLanguage.parser, correctly using the language wrapper (not the raw parser export) so that the package's styleTags highlight props are applied.
  • packages/app/src/components/highlighted-code-block.tsx: Adds csharp and c# fence aliases pointing to cs, consistent with every other alias in the table.
  • Tests: New cases in both parsers.test.ts and highlighter.test.ts follow the existing per-language pattern and assert keyword and string token styles on a representative snippet.

Confidence Score: 5/5

Safe to merge — a minimal, focused language addition with no changes to existing logic.

The change touches only the extension registration map, the fence alias table, and the dependency list. It follows the established pattern exactly (import parser, add entry, add alias, add tests). The technical explanation for using csharpLanguage.parser over the raw export is correct and verified by the passing unit tests. No existing behavior is altered.

No files require special attention.

Important Files Changed

Filename Overview
packages/highlight/src/parsers.ts Adds cs: csharpLanguage.parser entry following the identical pattern used by Java, Rust, and Swift; import and registration are clean.
packages/app/src/components/highlighted-code-block.tsx Adds csharp and c# aliases to the LANGUAGE_ALIASES map; consistent with the existing alias table and the fenceLanguageToExtension logic.
packages/highlight/package.json Adds @replit/codemirror-lang-csharp: ^6.2.0 to dependencies; all peers are satisfied by existing CodeMirror 6 packages in the project.
packages/highlight/src/tests/highlighter.test.ts New C# test case mirrors the Dart/Swift/Python pattern — asserts class → keyword and string literal → string style.
packages/highlight/src/tests/parsers.test.ts Adds test.cs to isLanguageSupported and cs to getSupportedExtensions checks; follows the existing test structure.
package-lock.json Adds only the @replit/codemirror-lang-csharp node and the one reference in packages/highlight; previously-flagged lockfile churn was addressed in the fixup commit.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Markdown fence / file path\ne.g. ```csharp or file.cs"] --> B["fenceLanguageToExtension\nor getParserForFile"]
    B --> C{"LANGUAGE_ALIASES lookup\n(highlighted-code-block.tsx)"}
    C -- "csharp / c# → cs" --> D["extension = 'cs'"]
    C -- "already an ext key\n(e.g. 'cs')" --> D
    D --> E["parsersByExtension\n(parsers.ts)"]
    E --> F["csharpLanguage.parser\n(@replit/codemirror-lang-csharp)"]
    F --> G["highlightCode → token stream\nwith keyword / string / type styles"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["Markdown fence / file path\ne.g. ```csharp or file.cs"] --> B["fenceLanguageToExtension\nor getParserForFile"]
    B --> C{"LANGUAGE_ALIASES lookup\n(highlighted-code-block.tsx)"}
    C -- "csharp / c# → cs" --> D["extension = 'cs'"]
    C -- "already an ext key\n(e.g. 'cs')" --> D
    D --> E["parsersByExtension\n(parsers.ts)"]
    E --> F["csharpLanguage.parser\n(@replit/codemirror-lang-csharp)"]
    F --> G["highlightCode → token stream\nwith keyword / string / type styles"]
Loading

Reviews (3): Last reviewed commit: "feat: add C# syntax highlighting" | Re-trigger Greptile

Comment thread package-lock.json
Wire the @replit/codemirror-lang-csharp Lezer grammar into @getpaseo/highlight following the existing per-language pattern (Java/Rust/Swift). Map the cs extension to the parser and alias the csharp and c# markdown fence names so fenced code blocks highlight.

Register csharpLanguage.parser rather than the package's raw parser export: the highlight styleTags are applied only inside csharpLanguage (via parser.configure), so the raw parser would parse but render unstyled.

Closes getpaseo#1527

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dev693-ai dev693-ai force-pushed the feat/csharp-highlighting branch from ed119dc to 4294ed5 Compare June 21, 2026 22:12
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.

feat: patch to add C# syntax highlighting support

2 participants