|
2 | 2 | import { loader } from '@monaco-editor/react'; |
3 | 3 | import * as monaco from 'monaco-editor'; |
4 | 4 |
|
5 | | -// Register YAML basic language (syntax highlighting only) to avoid LSP worker integration |
6 | 5 | import 'monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js'; |
7 | 6 |
|
8 | 7 | import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; |
9 | 8 |
|
| 9 | +import YamlWorker from 'monaco-yaml/yaml.worker?worker'; |
| 10 | + |
10 | 11 | // Use ESM monaco to avoid loading AMD loader from CDN |
11 | 12 | loader.config({ monaco }); |
12 | 13 |
|
13 | 14 | export const GITHUB_LIGHT_DEFAULT = 'github-light-default'; |
14 | 15 | export const GITHUB_DARK_DEFAULT = 'github-dark-default'; |
15 | 16 |
|
16 | | -// Inlined GitHub Light Default editor colors (subset focused on Monaco editor UI) |
17 | 17 | const GITHUB_LIGHT_EDITOR_COLORS: monaco.editor.IColors = { |
18 | 18 | 'editor.foreground': '#1f2328', |
19 | 19 | 'editor.background': '#ffffff', |
20 | 20 | 'editorWidget.background': '#f6f8fa', |
21 | 21 | 'editor.lineHighlightBackground': '#eaeef2', |
22 | 22 | 'editorCursor.foreground': '#0969da', |
23 | | - 'editor.selectionBackground': '#0969da33', // 20% opacity |
24 | | - 'editor.inactiveSelectionBackground': '#0969da12', // 7% opacity |
25 | | - 'editor.selectionHighlightBackground': '#1a7f3740', // 25% opacity |
| 23 | + 'editor.selectionBackground': '#0969da33', |
| 24 | + 'editor.inactiveSelectionBackground': '#0969da12', |
| 25 | + 'editor.selectionHighlightBackground': '#1a7f3740', |
26 | 26 | 'editorLineNumber.foreground': '#8c959f', |
27 | 27 | 'editorLineNumber.activeForeground': '#1f2328', |
28 | | - 'editorIndentGuide.background': '#1f23281f', // 12% opacity |
29 | | - 'editorIndentGuide.activeBackground': '#1f23283d', // 24% opacity |
| 28 | + 'editorIndentGuide.background': '#1f23281f', |
| 29 | + 'editorIndentGuide.activeBackground': '#1f23283d', |
30 | 30 | 'editorGutter.background': '#ffffff', |
31 | 31 | 'editorHoverWidget.background': '#f6f8fa', |
32 | 32 | 'editorHoverWidget.border': '#d0d7de', |
33 | 33 | 'editorSuggestWidget.background': '#f6f8fa', |
34 | 34 | 'editorSuggestWidget.border': '#d0d7de', |
35 | 35 | 'editorWidget.border': '#d0d7de', |
36 | 36 | 'editorWhitespace.foreground': '#d0d7de', |
37 | | - 'editor.wordHighlightBackground': '#afb8c180', // 50% opacity |
38 | | - 'editor.wordHighlightStrongBackground': '#afb8c14d', // 30% opacity |
| 37 | + 'editor.wordHighlightBackground': '#afb8c180', |
| 38 | + 'editor.wordHighlightStrongBackground': '#afb8c14d', |
39 | 39 | }; |
40 | 40 |
|
41 | | -// Inlined GitHub Dark Default editor colors (subset focused on Monaco editor UI) |
42 | 41 | const GITHUB_DARK_EDITOR_COLORS: monaco.editor.IColors = { |
43 | 42 | 'editor.foreground': '#e6edf3', |
44 | 43 | 'editor.background': '#0d1117', |
45 | 44 | 'editorWidget.background': '#161b22', |
46 | 45 | 'editor.lineHighlightBackground': '#161b22', |
47 | 46 | 'editorCursor.foreground': '#2f81f7', |
48 | | - 'editor.selectionBackground': '#2f81f733', // 20% opacity |
49 | | - 'editor.inactiveSelectionBackground': '#2f81f712', // 7% opacity |
50 | | - 'editor.selectionHighlightBackground': '#2ea04340', // 25% opacity |
| 47 | + 'editor.selectionBackground': '#2f81f733', |
| 48 | + 'editor.inactiveSelectionBackground': '#2f81f712', |
| 49 | + 'editor.selectionHighlightBackground': '#2ea04340', |
51 | 50 | 'editorLineNumber.foreground': '#6e7681', |
52 | 51 | 'editorLineNumber.activeForeground': '#e6edf3', |
53 | | - 'editorIndentGuide.background': '#e6edf31f', // 12% opacity |
54 | | - 'editorIndentGuide.activeBackground': '#e6edf33d', // 24% opacity |
| 52 | + 'editorIndentGuide.background': '#e6edf31f', |
| 53 | + 'editorIndentGuide.activeBackground': '#e6edf33d', |
55 | 54 | 'editorGutter.background': '#0d1117', |
56 | 55 | 'editorHoverWidget.background': '#161b22', |
57 | 56 | 'editorHoverWidget.border': '#30363d', |
58 | 57 | 'editorSuggestWidget.background': '#161b22', |
59 | 58 | 'editorSuggestWidget.border': '#30363d', |
60 | 59 | 'editorWidget.border': '#30363d', |
61 | 60 | 'editorWhitespace.foreground': '#484f58', |
62 | | - 'editor.wordHighlightBackground': '#6e768180', // 50% opacity |
63 | | - 'editor.wordHighlightStrongBackground': '#6e76814d', // 30% opacity |
| 61 | + 'editor.wordHighlightBackground': '#6e768180', |
| 62 | + 'editor.wordHighlightStrongBackground': '#6e76814d', |
64 | 63 | }; |
65 | 64 |
|
66 | 65 | export const configureMonaco = () => { |
67 | | - self.MonacoEnvironment = { |
68 | | - getWorker: (_: string) => new EditorWorker(), |
| 66 | + // Route YAML language to monaco-yaml worker, everything else to the default editor worker |
| 67 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 68 | + (self as any).MonacoEnvironment = { |
| 69 | + getWorker: (_: string, label: string) => { |
| 70 | + if (label === 'yaml') { |
| 71 | + return new YamlWorker(); |
| 72 | + } |
| 73 | + return new EditorWorker(); |
| 74 | + }, |
69 | 75 | }; |
70 | 76 |
|
71 | | - // Register GitHub Light Default |
72 | 77 | monaco.editor.defineTheme(GITHUB_LIGHT_DEFAULT, { |
73 | 78 | base: 'vs', |
74 | 79 | inherit: true, |
75 | 80 | rules: [], |
76 | 81 | colors: GITHUB_LIGHT_EDITOR_COLORS, |
77 | 82 | }); |
78 | 83 |
|
79 | | - // Register GitHub Dark Default |
80 | 84 | monaco.editor.defineTheme(GITHUB_DARK_DEFAULT, { |
81 | 85 | base: 'vs-dark', |
82 | 86 | inherit: true, |
|
0 commit comments