diff --git a/mobile/src/session/mobile-file-syntax.test.ts b/mobile/src/session/mobile-file-syntax.test.ts index 296fb2c55cc..8f5b31f3252 100644 --- a/mobile/src/session/mobile-file-syntax.test.ts +++ b/mobile/src/session/mobile-file-syntax.test.ts @@ -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'], diff --git a/mobile/src/session/mobile-file-syntax.ts b/mobile/src/session/mobile-file-syntax.ts index ac8df01a02b..3bc9bc7a35a 100644 --- a/mobile/src/session/mobile-file-syntax.ts +++ b/mobile/src/session/mobile-file-syntax.ts @@ -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 { diff --git a/src/shared/editor-language/editor-language-detect.ts b/src/shared/editor-language/editor-language-detect.ts index 77c21d7852a..a6adacf30ff 100644 --- a/src/shared/editor-language/editor-language-detect.ts +++ b/src/shared/editor-language/editor-language-detect.ts @@ -73,6 +73,7 @@ const EXT_TO_LANGUAGE: Record = { '.php': 'php', '.swift': 'swift', '.sh': 'shell', + '.just': 'shell', '.bash': 'shell', '.zsh': 'shell', '.fish': 'shell', @@ -135,6 +136,8 @@ const FILENAME_TO_LANGUAGE: Record = { Dockerfile: 'dockerfile', Jenkinsfile: 'groovy', Makefile: 'makefile', + Justfile: 'shell', + '.justfile': 'shell', 'CMakeLists.txt': 'cmake', '.gitignore': 'ini', '.gitattributes': 'ini',