Skip to content

Commit 611bfcc

Browse files
committed
feat(shared/codeHighlight): add Swift syntax highlighting support
Add support for Swift language highlighting in the code highlighter component. This enables proper syntax highlighting for Swift code by importing the swift language module from @codemirror/legacy-modes and adding a parser definition for files with the 'swift' extension.
1 parent 01184f8 commit 611bfcc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/shared/src/lib/codeHighlight.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { HighlightStyle, StreamLanguage } from '@codemirror/language';
2222
import { commonLisp } from '@codemirror/legacy-modes/mode/commonlisp';
2323
import { lua } from '@codemirror/legacy-modes/mode/lua';
2424
import { ruby } from '@codemirror/legacy-modes/mode/ruby';
25+
import { swift } from '@codemirror/legacy-modes/mode/swift';
2526
import { toml } from '@codemirror/legacy-modes/mode/toml';
2627
import { NodeType, Tree, Parser } from '@lezer/common';
2728
import { tags, highlightTree } from '@lezer/highlight';
@@ -189,6 +190,9 @@ export function parserFromFilename(filename: string): Parser | null {
189190
// highlighting svelte with js + jsx works much better than the above
190191
return javascript({ typescript: true, jsx: true }).language.parser;
191192

193+
case 'swift':
194+
return StreamLanguage.define(swift).parser;
195+
192196
case 'vue':
193197
return vue().language.parser;
194198

0 commit comments

Comments
 (0)