Conversation
- 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
|
Coverage after merging feat/additional-syntax-highlighting into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
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
tokenRuleswith 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 |
|
Coverage after merging feat/additional-syntax-highlighting into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- 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
|
Coverage after merging feat/additional-syntax-highlighting into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…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
|
Coverage after merging feat/additional-syntax-highlighting into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsdetectLang()— 12 new file extensions recognised:.php,.phtml.c,.h,.cpp,.cc,.cxx,.hpp,.hxx.swift.tf,.hclDockerfile,dockerfile,Dockerfile.*5 new token rule sets:
function,class,echo,foreach… → magenta$variables→ cyan, strings → green, comments dimint,void,struct,class,nullptr… → magenta#include/#definedirectives → cyan, strings → greenvar,let,func,guard,protocol… → magentaresource,variable,output,module… → magentaFROM,RUN,CMD,COPY,EXPOSE… → magenta$ENV_VARrefs → cyan, comments dimsrc/render/highlight.test.ts\x1b[35mfor magenta keywords,\x1b[36mfor cyan tokens) that were red before implementation.How to test manually
Checklist
bun test— 452 pass, 0 failbun run lint— 0 warnings, 0 errorsbun run format:check— no diffbun run knip— no unused exportsCloses #78
Part of #77