|
1 | 1 | import React, { useEffect, useCallback, useReducer, useRef } from 'react'
|
2 | 2 | import MonacoEditor, { MonacoDiffEditor } from 'react-monaco-editor'
|
3 |
| -import { Progressing, copyToClipboard, useWindowSize } from '@devtron-labs/devtron-fe-common-lib' |
| 3 | +import { MODES, Progressing, copyToClipboard, useWindowSize } from '@devtron-labs/devtron-fe-common-lib' |
4 | 4 | import YAML from 'yaml'
|
5 | 5 | import ReactGA from 'react-ga4'
|
6 | 6 | import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
|
| 7 | +import { configureMonacoYaml } from 'monaco-yaml' |
| 8 | + |
7 | 9 | import { useJsonYaml, Select, RadioGroup } from '../common'
|
8 | 10 | import { ReactComponent as ClipboardIcon } from '../../assets/icons/ic-copy.svg'
|
9 | 11 | import { ReactComponent as Info } from '../../assets/icons/ic-info-filled.svg'
|
10 | 12 | import { ReactComponent as ErrorIcon } from '../../assets/icons/ic-error-exclamation.svg'
|
11 | 13 | import { ReactComponent as WarningIcon } from '../../assets/icons/ic-warning.svg'
|
12 | 14 | import './codeEditor.scss'
|
13 | 15 | import 'monaco-editor'
|
| 16 | + |
| 17 | +import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker' |
| 18 | +import YamlWorker from '../../yaml.worker.js?worker' |
14 | 19 | import { cleanKubeManifest } from '../../util/Util'
|
15 | 20 |
|
| 21 | +self.MonacoEnvironment = { |
| 22 | + getWorker(_, label) { |
| 23 | + if (label === MODES.YAML) { |
| 24 | + return new YamlWorker() |
| 25 | + } |
| 26 | + return new editorWorker() |
| 27 | + }, |
| 28 | +} |
| 29 | + |
16 | 30 | // @ts-ignore
|
17 | 31 | const { yaml } = monaco.languages || {}
|
18 | 32 |
|
@@ -223,22 +237,17 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
|
223 | 237 | if (!validatorSchema) {
|
224 | 238 | return
|
225 | 239 | }
|
226 |
| - yaml && |
227 |
| - yaml.yamlDefaults.setDiagnosticsOptions({ |
228 |
| - validate: true, |
229 |
| - enableSchemaRequest: true, |
230 |
| - hover: true, |
231 |
| - completion: true, |
232 |
| - isKubernetes, |
233 |
| - format: true, |
234 |
| - schemas: [ |
235 |
| - { |
236 |
| - uri: `https://github.com/devtron-labs/devtron/tree/main/scripts/devtron-reference-helm-charts/reference-chart_${chartVersion}/schema.json`, // id of the first schema |
237 |
| - fileMatch: ['*'], // associate with our model |
238 |
| - schema: validatorSchema, |
239 |
| - }, |
240 |
| - ], |
241 |
| - }) |
| 240 | + configureMonacoYaml(monaco, { |
| 241 | + enableSchemaRequest: true, |
| 242 | + isKubernetes, |
| 243 | + schemas: [ |
| 244 | + { |
| 245 | + uri: `https://github.com/devtron-labs/devtron/tree/main/scripts/devtron-reference-helm-charts/reference-chart_${chartVersion}/schema.json`, // id of the first schema |
| 246 | + fileMatch: ['*'], // associate with our model |
| 247 | + schema: validatorSchema, |
| 248 | + }, |
| 249 | + ], |
| 250 | + }) |
242 | 251 | // eslint-disable-next-line react-hooks/exhaustive-deps
|
243 | 252 | }, [validatorSchema, chartVersion])
|
244 | 253 | useEffect(() => {
|
|
0 commit comments