fix(editor): highlight Justfile recipes and mobile HCL assignments (#35573)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-28 21:39:54 -07:00
committed by GitHub
co-authored by OrcaWin
parent 55f53280d8
commit 4a5e10223d
3 changed files with 43 additions and 1 deletions
@@ -9,6 +9,43 @@ import {
import type { MobileDiffLine } from './mobile-diff-lines'
describe('mobile file syntax highlighting', () => {
it.each(['justfile', 'Justfile', '.justfile', 'tasks.just', 'C:\\repo\\TASKS.JUST'])(
'highlights shell recipes in %s',
(filePath) => {
const source = '# Build recipe\nbuild:\n echo "ready"\n'
const result = highlightMobileCode(source, resolveMobileSyntaxLanguage(filePath))
expect(result.highlighted).toBe(true)
expect(result.segments.map((segment) => segment.text).join('')).toBe(source)
expect(result.segments).toEqual(
expect.arrayContaining([
{ text: '# Build recipe', kind: 'comment' },
{ text: '"ready"', kind: 'string' }
])
)
}
)
it.each(['terraform.tfvars', 'C:\\repo\\PROD.TFVARS', 'main.tf', 'config.hcl'])(
'highlights HCL assignments in %s',
(filePath) => {
const source = '# Deployment\nregion = "us-west-2"\ncount = 3\n'
const language = resolveMobileSyntaxLanguage(filePath)
const result = highlightMobileCode(source, language)
expect(result.highlighted).toBe(true)
expect(result.segments.map((segment) => segment.text).join('')).toBe(source)
expect(result.segments).toEqual(
expect.arrayContaining([
{ text: '# Deployment', kind: 'comment' },
{ text: 'region', kind: 'variable' },
{ text: '"us-west-2"', kind: 'string' }
])
)
const [line] = highlightMobileDiffLines([{ text: 'region = "us-west-2"' }], language)
expect(line?.highlighted).toBe(true)
expect(line?.segments).toContainEqual({ text: '"us-west-2"', kind: 'string' })
}
)
it.each([
['.env', 'dotenv'],
['.env.local', 'dotenv'],
+3 -1
View File
@@ -55,7 +55,9 @@ const LANGUAGE_ALIASES = new Map([
['glimmer-js', 'javascript'],
['glimmer-ts', 'typescript'],
// lowlight has no dotenv grammar; ini covers KEY=value and # comments.
['dotenv', 'ini']
['dotenv', 'ini'],
// HCL assignments, strings and comments use the bundled ini grammar on mobile.
['hcl', 'ini']
])
export function resolveMobileSyntaxLanguage(filePath: string, preferredLanguage?: string): string {
@@ -73,6 +73,7 @@ const EXT_TO_LANGUAGE: Record<string, string> = {
'.php': 'php',
'.swift': 'swift',
'.sh': 'shell',
'.just': 'shell',
'.bash': 'shell',
'.zsh': 'shell',
'.fish': 'shell',
@@ -135,6 +136,8 @@ const FILENAME_TO_LANGUAGE: Record<string, string> = {
Dockerfile: 'dockerfile',
Jenkinsfile: 'groovy',
Makefile: 'makefile',
Justfile: 'shell',
'.justfile': 'shell',
'CMakeLists.txt': 'cmake',
'.gitignore': 'ini',
'.gitattributes': 'ini',