Skip to content

Commit 2ab21b6

Browse files
authored
Merge pull request #11066 from jimeh/add-syntax-highlighting-for-additional-languages
feat(diff/syntax-highlight): support 12 more languages
2 parents f073e0d + 98705f6 commit 2ab21b6

File tree

4 files changed

+139
-14
lines changed

4 files changed

+139
-14
lines changed

packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@codemirror/lang-xml": "^6.1.0",
5353
"@codemirror/lang-yaml": "^6.1.2",
5454
"@codemirror/language": "^6.11.2",
55-
"@codemirror/legacy-modes": "^6.5.1",
55+
"@codemirror/legacy-modes": "^6.5.2",
5656
"@csstools/postcss-bundler": "^1.0.15",
5757
"@gitbutler/core": "workspace:*",
5858
"@gitbutler/ui": "workspace:*",

packages/ui/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"devDependencies": {
3232
"@codemirror/lang-cpp": "^6.0.3",
3333
"@codemirror/lang-css": "^6.3.1",
34+
"@codemirror/lang-go": "^6.0.1",
3435
"@codemirror/lang-html": "^6.4.9",
3536
"@codemirror/lang-java": "^6.0.2",
3637
"@codemirror/lang-javascript": "^6.2.4",
@@ -42,13 +43,15 @@
4243
"@codemirror/lang-vue": "^0.1.3",
4344
"@codemirror/lang-wast": "^6.0.2",
4445
"@codemirror/lang-xml": "^6.1.0",
46+
"@codemirror/lang-yaml": "^6.1.2",
4547
"@codemirror/language": "^6.11.2",
46-
"@codemirror/legacy-modes": "^6.5.1",
48+
"@codemirror/legacy-modes": "^6.5.2",
4749
"@csstools/postcss-bundler": "^2.0.8",
4850
"@gitbutler/design-core": "^1.2.6",
4951
"@lezer/common": "^1.2.3",
5052
"@lezer/highlight": "^1.2.1",
5153
"@playwright/experimental-ct-svelte": "^1.56.1",
54+
"@replit/codemirror-lang-nix": "^6.0.1",
5255
"@replit/codemirror-lang-svelte": "^6.0.0",
5356
"@storybook/addon-docs": "^10.0.2",
5457
"@storybook/addon-links": "^10.0.2",
@@ -62,6 +65,8 @@
6265
"@types/postcss-pxtorem": "^6.1.0",
6366
"@vitest/browser": "catalog:",
6467
"autoprefixer": "^10.4.21",
68+
"codemirror-lang-elixir": "^4.0.0",
69+
"codemirror-lang-hcl": "^0.1.0",
6570
"cpy-cli": "^5.0.0",
6671
"cssnano": "^7.1.0",
6772
"dayjs": "^1.11.13",

packages/ui/src/lib/utils/diffParsing.ts

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cpp } from '@codemirror/lang-cpp';
22
import { css } from '@codemirror/lang-css';
3+
import { go } from '@codemirror/lang-go';
34
import { html } from '@codemirror/lang-html';
45
import { java } from '@codemirror/lang-java';
56
import { javascript } from '@codemirror/lang-javascript';
@@ -12,13 +13,24 @@ import { rust } from '@codemirror/lang-rust';
1213
import { vue } from '@codemirror/lang-vue';
1314
import { wast } from '@codemirror/lang-wast';
1415
import { xml } from '@codemirror/lang-xml';
16+
import { yaml } from '@codemirror/lang-yaml';
1517
import { HighlightStyle, StreamLanguage } from '@codemirror/language';
1618
import { kotlin } from '@codemirror/legacy-modes/mode/clike';
19+
import { commonLisp } from '@codemirror/legacy-modes/mode/commonlisp';
20+
import { dockerFile } from '@codemirror/legacy-modes/mode/dockerfile';
21+
import { jinja2 } from '@codemirror/legacy-modes/mode/jinja2';
22+
import { lua } from '@codemirror/legacy-modes/mode/lua';
1723
import { powerShell } from '@codemirror/legacy-modes/mode/powershell';
1824
import { protobuf } from '@codemirror/legacy-modes/mode/protobuf';
1925
import { ruby } from '@codemirror/legacy-modes/mode/ruby';
26+
import { shell } from '@codemirror/legacy-modes/mode/shell';
27+
import { swift } from '@codemirror/legacy-modes/mode/swift';
28+
import { toml } from '@codemirror/legacy-modes/mode/toml';
2029
import { NodeType, Tree, Parser } from '@lezer/common';
2130
import { tags, highlightTree } from '@lezer/highlight';
31+
import { nix } from '@replit/codemirror-lang-nix';
32+
import { elixir } from 'codemirror-lang-elixir';
33+
import { hcl } from 'codemirror-lang-hcl';
2234
import diff_match_patch from 'diff-match-patch';
2335
import type { BrandedId } from '$lib/utils/branding';
2436

@@ -266,19 +278,44 @@ export function parserFromExtension(extension: string): Parser | undefined {
266278
case 'h++':
267279
return cpp().language.parser;
268280

269-
// case 'text/x-go':
270-
// return new LanguageSupport(await CodeMirror.go());
281+
case 'ex':
282+
case 'exs':
283+
return elixir().language.parser;
284+
285+
case 'go':
286+
return go().language.parser;
287+
288+
case 'hcl':
289+
case 'hcl2':
290+
case 'nomad':
291+
case 'tf':
292+
case 'tfvars':
293+
return hcl().language.parser;
271294

272295
case 'java':
273296
return java().language.parser;
274297

298+
case 'j2':
299+
case 'jinja':
300+
case 'jinja2':
301+
return StreamLanguage.define(jinja2).parser;
302+
275303
case 'kt':
276304
case 'kts':
277305
return StreamLanguage.define(kotlin).parser;
278306

279307
case 'json':
280308
return json().language.parser;
281309

310+
case 'lisp':
311+
case 'lsp':
312+
case 'cl': // Common Lisp
313+
case 'el': // Emacs Lisp
314+
return StreamLanguage.define(commonLisp).parser;
315+
316+
case 'lua':
317+
return StreamLanguage.define(lua).parser;
318+
282319
case 'php':
283320
return php().language.parser;
284321

@@ -292,8 +329,8 @@ export function parserFromExtension(extension: string): Parser | undefined {
292329
case 'md':
293330
return markdown().language.parser;
294331

295-
// case 'text/x-sh':
296-
// return new LanguageSupport(await CodeMirror.shell());
332+
case 'nix':
333+
return nix().language.parser;
297334

298335
// case 'text/x-coffeescript':
299336
// return new LanguageSupport(await CodeMirror.coffeescript());
@@ -326,6 +363,14 @@ export function parserFromExtension(extension: string): Parser | undefined {
326363
// highlighting svelte with js + jsx works much better than the above
327364
return javascript({ typescript: true, jsx: true }).language.parser;
328365

366+
case 'sh':
367+
case 'bash':
368+
case 'zsh':
369+
return StreamLanguage.define(shell).parser;
370+
371+
case 'swift':
372+
return StreamLanguage.define(swift).parser;
373+
329374
case 'vue':
330375
return vue().language.parser;
331376

@@ -335,13 +380,27 @@ export function parserFromExtension(extension: string): Parser | undefined {
335380
case 'rb':
336381
return StreamLanguage.define(ruby).parser;
337382

383+
case 'toml':
384+
return StreamLanguage.define(toml).parser;
385+
386+
case 'yml':
387+
case 'yaml':
388+
return yaml().language.parser;
389+
338390
default:
339391
return undefined;
340392
}
341393
}
342394

343395
export function parserFromFilename(filename: string): Parser | undefined {
344-
const ext = filename.split('.').pop();
396+
const basename = filename.split('/').pop() || '';
397+
const ext = basename.split('.').pop()?.toLowerCase();
398+
399+
// Handle Dockerfiles (with common variations).
400+
if (basename === 'Dockerfile' || basename.startsWith('Dockerfile.') || ext === 'dockerfile') {
401+
return StreamLanguage.define(dockerFile).parser;
402+
}
403+
345404
if (!ext) return undefined;
346405
return parserFromExtension(ext);
347406
}

pnpm-lock.yaml

Lines changed: 68 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)