feat(entities-plugins,monaco-editor): schema-aware code editor for yaml & datakit#2895
feat(entities-plugins,monaco-editor): schema-aware code editor for yaml & datakit#2895
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a schema‑aware YAML and Datakit configuration editor, wiring Datakit’s Zod schemas into JSON Schema to power Monaco‑based YAML completions, validation, and smart editing, and unifying strict/compat Datakit config validation between the code editor and flow editor.
Changes:
- Refactors Datakit schemas into a shared
config-baseplusstrict/compatwrappers, adds graph‑level validation (graph-validation.ts), and derives JSON Schema (json-schema.ts) to describe plugin/config payloads. - Integrates a custom YAML stack into
@kong-ui-public/monaco-editor(schema view, cursor context, completions, smart edits) and plugs it into the DatakitCodeEditor.vuefor schema‑aware validation and completions (including reference and property completions). - Replaces
js-yamlwithyamlacross Datakit components, adds plugin‑data and IO indexing utilities for completions, and wires form validation/flow‑editor availability to strict/compat Datakit schema results.
Reviewed changes
Copilot reviewed 43 out of 44 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds yaml package lock entries for entities-plugins and monaco-editor consumers. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/strict.ts | Simplifies strict Datakit config schema to reuse config-base and layer graph validation on top. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/shared.ts | Removes legacy name/connection validation in favor of new graph validator; keeps shared IO validation helpers. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/plugin-data.ts | Defines Zod schema for the Datakit plugin root payload (including config, scope, and metadata) used for editor JSON Schema generation. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/node-io.ts | Defines IO descriptors for implicit and config nodes, backed by a field index, to validate and suggest connection fields. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/node-field-index.ts | Builds a cached index of allowed input/output fields per node type by walking the generated Datakit JSON Schema. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/json-schema.ts | Converts Datakit Zod schemas (plugin and config) to JSON Schema with stable $ids for use by the YAML editor and IO index. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/io-index.ts | Extracts node names/types and dynamic outputs (static nodes and vault) from parsed configs for completion and validation. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/graph-validation.ts | Implements full graph validation (duplicates, unknown nodes/fields, self-loops, cycles, branch constraints, implicit edges). |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/config-base.ts | Centralizes Datakit config/node/resource Zod schemas and exports shared types used by strict/compat modes and UI. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/completion.ts | Defines relaxed config schema variant to drive editor completions while reusing base node schemas. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/schema/compat.ts | Keeps compat Datakit schema but replaces legacy name/connection checks with the new graph validator in compat mode. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/flow-editor/store/validation.ts | Adds config-graph validation via validateGraph on a DatakitConfig built from editor state, integrating with existing error collection. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/flow-editor/store/store.ts | Passes a getConfigNodes callback into useValidators so graph validation can derive a DatakitConfig from state. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/flow-editor/side-panel/CacheField.vue | Switches Redis cache YAML serialization from js-yaml to yaml.stringify with explicit options (no aliases, YAML 1.1). |
| packages/entities/entities-plugins/src/components/free-form/Datakit/flow-editor/modal/EditorMain.vue | Replaces js-yaml parsing for examples with yaml.parseDocument, adding error checks before loading example configs. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/config-extractors.ts | Replaces js-yaml with yaml.parseDocument for deck/KIC config extraction and adds basic error handling on parse failures. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/zod-issue-markers.ts | Maps Zod issues to Monaco marker ranges by correlating Zod paths with YAML AST nodes and fallback heuristics. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/yaml-schema.ts | Exposes Datakit plugin JSON Schema for the Datakit YAML editor. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/yaml-path-index.ts | Builds and queries a YAML AST path index (value, key, parent-key) with utilities to compute Monaco ranges from nodes and offsets. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/yaml-cursor.ts | Locates YAML AST paths based on cursor offsets for simple cursor-aware features. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/schema-context.ts | Resolves JSON Schema context at a YAML path (including unions, allOf, discriminators) to drive higher-level completions. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/datakit-ref-completions.ts | Provides Datakit-specific completion items for connection references and branch node lists based on IO index (contains a regex bug in the connection-path branch). |
| packages/entities/entities-plugins/src/components/free-form/Datakit/code-editor/datakit-property-completions.ts | Adds completion for Datakit property node values using supported Kong client properties, including {key} snippets. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/DatakitForm.vue | Wires strict/compat Zod validation into form validity, controls flow-editor availability, and routes layout changes/code-editor validation into onValidityChange. |
| packages/entities/entities-plugins/src/components/free-form/Datakit/CodeEditor.vue | Swaps js-yaml for yaml, adds YAML schema attachment, smart validation with markers (YAML + compat + strict), and emits granular validation events. |
| packages/entities/entities-plugins/package.json | Adds yaml as a dependency for entities-plugins. |
| packages/core/monaco-editor/vite-plugin/index.ts | Adjusts handling of customLanguages to work with copied arrays and updates documentation comments in generated worker code. |
| packages/core/monaco-editor/vite-plugin/README.md | Updates customLanguages docs to describe generic custom languages instead of specifically monaco-yaml. |
| packages/core/monaco-editor/src/yaml/types.ts | Defines shared YAML types: schema, style, completion options, cursor context, and extension interfaces for YAML completions. |
| packages/core/monaco-editor/src/yaml/suggest.ts | Adds a suggestion trigger helper and global command for YAML smart completions, consulting model-specific config. |
| packages/core/monaco-editor/src/yaml/smart-edits.ts | Implements schema-aware smart edits for YAML (colon/enter/dash behavior, indentation, and auto-triggered completions). |
| packages/core/monaco-editor/src/yaml/schema.ts | Implements JSON Schema traversal utilities for determining kind, resolving unions/allOf, discriminators, and object property views. |
| packages/core/monaco-editor/src/yaml/registry.ts | Maintains per-model YAML config (schema, completion, style, extensions) and tracks model-to-editor mapping. |
| packages/core/monaco-editor/src/yaml/index.ts | Public entry for YAML support: registers completion provider, attaches schema/config per model, and wires smart edits + command. |
| packages/core/monaco-editor/src/yaml/doc-cache.ts | Caches parsed YAML documents per Monaco model/version to avoid redundant parses. |
| packages/core/monaco-editor/src/yaml/context.ts | Derives a rich cursor context (paths, slot, prefix, indentation) from the YAML AST and document text. |
| packages/core/monaco-editor/src/yaml/constants.ts | Defines the command ID used to trigger YAML suggestions. |
| packages/core/monaco-editor/src/yaml/completion.ts | Core YAML completion provider that combines schema-derived key/value completions with extension results and de-duplicates suggestions. |
| packages/core/monaco-editor/src/types/index.ts | Extends UseMonacoEditorOptions with an optional modelUri used to bind models to schemas. |
| packages/core/monaco-editor/src/index.ts | Re-exports YAML helper APIs alongside the core Monaco editor exports. |
| packages/core/monaco-editor/src/composables/useMonacoEditor.ts | Allows callers to specify a modelUri when creating the model, enabling stable URIs for schema attachment. |
| packages/core/monaco-editor/src/components/MonacoEditor.vue | Accepts and forwards a modelUri prop to useMonacoEditor so callers can control model URIs from Vue. |
| packages/core/monaco-editor/package.json | Adds yaml as a dependency for the monaco-editor package. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const wantsSource = slot === 'input' || slot === 'inputs' | ||
|
|
||
| const linePrefix = model.getLineContent(position.lineNumber).slice(0, position.column - 1) | ||
| if (/\\.[A-Za-z0-9_-]*$/.test(linePrefix)) { |
There was a problem hiding this comment.
The regex here is written as /\\.[A-Za-z0-9_-]*$/, which matches a literal backslash followed by any character, not a dot-prefixed field name as intended. This means we may incorrectly fall back to node-name suggestions even when the user has typed nodeName.<field>, instead of suppressing them. Updating the pattern to /\.[A-Za-z0-9_-]*$/ will correctly detect a trailing . and field fragment.
| if (/\\.[A-Za-z0-9_-]*$/.test(linePrefix)) { | |
| if (/\.[A-Za-z0-9_-]*$/.test(linePrefix)) { |
| const keyPathAtPrev = indexes.keyLineIndex.get(prevLine) | ||
| const seqPathAtPrev = indexes.seqLineIndex.get(prevLine) | ||
|
|
||
| if (!keyPath && !valuePath && prevIndent > lineIndent.length) { |
There was a problem hiding this comment.
This negation always evaluates to true.
| if (!keyPath && !valuePath && prevIndent > lineIndent.length) { | |
| if (!valuePath && prevIndent > lineIndent.length) { |
95d1626 to
03b9a4a
Compare
🔴 PR audit failed. 🔴🔥 No test coverage detected.This PR does not include any test coverage changes, but it modifies source code. Please add appropriate tests to cover the changes made in this PR. If you believe this is a false positive or if there are valid reasons for not including test coverage changes, please request an exemption by adding the |
Preview components from this PR in consuming applicationIn consuming application project install preview versions of shared packages generated by this PR: |
Summary
KM-2236