11import { cpp } from '@codemirror/lang-cpp' ;
22import { css } from '@codemirror/lang-css' ;
3+ import { go } from '@codemirror/lang-go' ;
34import { html } from '@codemirror/lang-html' ;
45import { java } from '@codemirror/lang-java' ;
56import { javascript } from '@codemirror/lang-javascript' ;
@@ -12,13 +13,24 @@ import { rust } from '@codemirror/lang-rust';
1213import { vue } from '@codemirror/lang-vue' ;
1314import { wast } from '@codemirror/lang-wast' ;
1415import { xml } from '@codemirror/lang-xml' ;
16+ import { yaml } from '@codemirror/lang-yaml' ;
1517import { HighlightStyle , StreamLanguage } from '@codemirror/language' ;
1618import { 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' ;
1723import { powerShell } from '@codemirror/legacy-modes/mode/powershell' ;
1824import { protobuf } from '@codemirror/legacy-modes/mode/protobuf' ;
1925import { 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' ;
2029import { NodeType , Tree , Parser } from '@lezer/common' ;
2130import { 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' ;
2234import diff_match_patch from 'diff-match-patch' ;
2335import 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
343395export 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}
0 commit comments