Skip to content

feat: additional syntax highlighting — PHP, C/C++, Swift, Terraform/HCL, Dockerfile#80

Merged
shouze merged 4 commits intomainfrom
feat/additional-syntax-highlighting
Mar 4, 2026
Merged

feat: additional syntax highlighting — PHP, C/C++, Swift, Terraform/HCL, Dockerfile#80
shouze merged 4 commits intomainfrom
feat/additional-syntax-highlighting

Conversation

@shouze
Copy link
Contributor

@shouze shouze commented Mar 4, 2026

Motivation

Extends the regex-based syntax highlighter (src/render/highlight.ts) with five new language profiles, as requested in #78 and the Developer experience EPIC #77.

What changed

src/render/highlight.ts

  • detectLang() — 12 new file extensions recognised:

    • PHP: .php, .phtml
    • C/C++: .c, .h, .cpp, .cc, .cxx, .hpp, .hxx
    • Swift: .swift
    • Terraform/HCL: .tf, .hcl
    • Dockerfile: filenames Dockerfile, dockerfile, Dockerfile.*
  • 5 new token rule sets:

Language Keywords Special tokens
PHP function, class, echo, foreach… → magenta $variables → cyan, strings → green, comments dim
C/C++ int, void, struct, class, nullptr… → magenta #include/#define directives → cyan, strings → green
Swift var, let, func, guard, protocol… → magenta Strings → green, PascalCase types → cyan
Terraform/HCL resource, variable, output, module… → magenta Booleans/null → magenta, strings → green, comments dim
Dockerfile FROM, RUN, CMD, COPY, EXPOSE… → magenta $ENV_VAR refs → cyan, comments dim

src/render/highlight.test.ts

  • 44 new tests, including strict ANSI-code assertions (\x1b[35m for magenta keywords, \x1b[36m for cyan tokens) that were red before implementation.

How to test manually

# Syntax-highlight a PHP file extract in TUI
GITHUB_TOKEN=... bun github-code-search.ts query "class" --org <org>
# Then navigate to a .php result to see PHP-specific highlighting

Checklist

  • bun test — 452 pass, 0 fail
  • bun run lint — 0 warnings, 0 errors
  • bun run format:check — no diff
  • bun run knip — no unused exports
  • Commits signed (GPG)

Closes #78
Part of #77

- Extend detectLang() to recognise 12 new file extensions (.php, .phtml,
  .c, .h, .cpp, .cc, .cxx, .hpp, .hxx, .swift, .tf, .hcl) and Dockerfile
  filenames (Dockerfile, dockerfile, Dockerfile.*)
- Add tokenRules for each new language:
    • php — keywords (magenta), $variables (cyan), strings, comments
    • c   — keywords (magenta), preprocessor directives (cyan), strings, comments
    • swift — keywords (magenta), strings, numeric literals, PascalCase types
    • terraform — block keywords (magenta), booleans, strings, hash/line comments
    • dockerfile — instructions (magenta), ENV variable refs (cyan), comments
- TDD: 44 new tests in highlight.test.ts, all with specific ANSI-code assertions
  (\x1b[35m for magenta keywords, \x1b[36m for cyan tokens) to ensure
  language-specific tokenizers are active

Closes #78
Part of #77
Copilot AI review requested due to automatic review settings March 4, 2026 18:16
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/additional-syntax-highlighting into main will be

96.18%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts86.52%100%93.33%85.89%117–118, 138–145, 148–154, 159, 164, 200–203
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts95.87%100%88%99.30%277–278
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the regex-based syntax highlighter (src/render/highlight.ts) with five new language profiles — PHP, C/C++, Swift, Terraform/HCL, and Dockerfile — and adds 44 new tests for them, closing issue #78 as part of the Developer Experience EPIC #77.

Changes:

  • Language detection extended with 12 new file extensions and filename-based Dockerfile detection
  • Five new token rule sets added to tokenRules with keyword, comment, string, and special-token highlighting
  • 44 new unit tests covering detection, keyword coloring, comments, strings, and literals for all five languages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/render/highlight.ts Adds PHP, C, Swift, Terraform, and Dockerfile Lang variants; extends detectLang() with new extensions and filename-based Dockerfile detection; adds five new token rule arrays
src/render/highlight.test.ts 44 new tests across five language-specific describe blocks covering detection, keyword magenta coloring, special tokens, comments, strings, and literals

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/additional-syntax-highlighting into main will be

96.46%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts95.87%100%88%99.30%277–278
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

- detectLang: perform extension map lookup before Dockerfile check to
  prevent false positives (e.g. Dockerfile.ts correctly detected as
  TypeScript, Dockerfile.php as PHP)
- PHP tokenizer: use /^#(?!\[)[^\n]*/ for hash comments to avoid
  dimming PHP 8+ attribute syntax (#[Route], #[ORM\Entity], etc.)
- Test: assert \x1b[35m magenta on Terraform boolean/null literals
  (was only checking text preservation via strip())
- Test: add MAINTAINER to Dockerfile instructions test (present in
  regex but was missing from test list)
- Test: add regression for Dockerfile.ts → typescript detection
- Test: add PHP 8+ attribute non-comment assertion
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/additional-syntax-highlighting into main will be

96.46%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.38%100%89.60%99.31%284–285
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

…80

- Swift PascalCase test: replace weak toMatch(/\x1b\[/) with specific
  toContain("\x1b[36m") assertion, consistent with all other per-language
  PascalCase/identifier tests in the file
- Dockerfile: add tests for $VAR and ${VAR} env-variable references (cyan),
  covering the existing rule on line 261 that had no test coverage
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/additional-syntax-highlighting into main will be

96.46%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.62%100%90.40%99.31%284–285
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@shouze shouze merged commit e9ce4f5 into main Mar 4, 2026
6 checks passed
@shouze shouze deleted the feat/additional-syntax-highlighting branch March 4, 2026 20:58
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: additional syntax highlighting — PHP, C/C++, Swift, Terraform/HCL, Dockerfile (v1.7.0)

2 participants