diff --git a/web/src/components/SourceCodeEditor/MonacoSourceCodeEditor.tsx b/web/src/components/SourceCodeEditor/MonacoSourceCodeEditor.tsx index ae40d3202..d1eddd28d 100644 --- a/web/src/components/SourceCodeEditor/MonacoSourceCodeEditor.tsx +++ b/web/src/components/SourceCodeEditor/MonacoSourceCodeEditor.tsx @@ -38,7 +38,8 @@ export default function MonacoSourceCodeEditor({ height, autoHeight, wordWrap = true, - onChange = noop + onChange = noop, + schema }: SourceCodeEditorProps) { const [editor, setEditor] = useState() const scrollbar = autoHeight ? 'hidden' : 'auto' @@ -51,6 +52,23 @@ export default function MonacoSourceCodeEditor({ } }, []) + useEffect(() => { + if (window.monaco && language === 'yaml' && schema) { + monaco.languages.yaml?.yamlDefaults?.setDiagnosticsOptions?.({ + validate: true, + enableSchemaRequest: false, + hover: true, + completion: true, + schemas: [ + { + fileMatch: ['*'], + schema + } + ] + }) + } + }, [language, schema]) + useEventListener('resize', () => { editor?.layout({ width: 0, height: 0 }) window.requestAnimationFrame(() => editor?.layout()) diff --git a/web/src/pages/NewPipeline/NewPipeline.tsx b/web/src/pages/NewPipeline/NewPipeline.tsx index 7a81dd9f3..d90bafca1 100644 --- a/web/src/pages/NewPipeline/NewPipeline.tsx +++ b/web/src/pages/NewPipeline/NewPipeline.tsx @@ -8,10 +8,11 @@ import { Color } from '@harnessio/design-system' import type { OpenapiCommitFilesRequest, RepoCommitFilesResponse } from 'services/code' import { useStrings } from 'framework/strings' import { useGetSpaceParam } from 'hooks/useGetSpaceParam' -import { SourceCodeEditor } from 'components/SourceCodeEditor/SourceCodeEditor' +import MonacoSourceCodeEditor from 'components/SourceCodeEditor/MonacoSourceCodeEditor' import { useAppContext } from 'AppContext' import type { CODEProps } from 'RouteDefinitions' import { getErrorMessage } from 'utils/Utils' +import pipelineSchema from './schema/pipeline-schema.json' import css from './NewPipeline.module.scss' @@ -26,7 +27,7 @@ const NewPipeline = (): JSX.Element => { const { mutate, loading } = useMutate({ verb: 'POST', - path: `/api/v1/repos/test-space/vb-repo/+/commits` + path: `/api/v1/repos/${space}/vb-repo/+/commits` }) const handleSaveAndRun = (): void => { @@ -90,8 +91,9 @@ const NewPipeline = (): JSX.Element => { /> - void + schema?: Record } // Monaco editor has a bug where when its value is set, the value