0.9.2: Source view, schema checks without the YAML extension

Every Archify page can show its file's YAML in place. Diagrams get
Diagram | Graph | Source (Graph only inside a model), main.archify
Model | Graph | Source, registry and decision pages View | Source, and the
Graph page a Source segment. 2D | 3D moves left of that switch and hides
while Source shows.

The YAML opens in a CodeMirror editor inside the page (dist/source.js,
loaded on first use), themed with the page's colours. Edits go to the VS
Code document as WorkspaceEdits; outside changes come back to the page.
Undo and redo are the editor's own, since VS Code sends ⌘Z in a focused
webview to the webview; save and find stay VS Code's. Problems come from
the host only (what the Problems panel holds for the file) and are
counted on the Source segment; completion and hover come from the schema,
folded into one draft-07 document per diagram type.

The host now checks .archify files against the extension's schema with
ajv on the YAML as written, before archify validate, and checks
.archify-registry files against the registry schema for the first time.
Registry and decision pages become text editor providers. While Source
shows, new renders wait and appear when the picture comes back.

Show Source switches the page to Source; Open in Text Editor (the editor
title button) opens the text beside it, as Show Source did. The decision
schema is no longer given to the YAML extension. Fixed: YAML errors in
registry and decision files were reported on line 1; "Webview is
disposed" when a diagram closed mid-render; the model heading under the
toolbar in narrow editors.
This commit is contained in:
root-at-skic committed 2026-10-27 23:46:05 +02:00
1 parent 5bcd34b839
commit 27d4794ff8
32 files changed
+2486 -127

No files matched your search

+5 -3
View File
@@ -1,4 +1,4 @@
import { isMap, isScalar, isSeq, parseDocument } from 'yaml';
import { LineCounter, isMap, isScalar, isSeq, parseDocument } from 'yaml';
import { ModelProblem, Registry } from './format';
/**
@@ -46,9 +46,11 @@ export function slugify(title: string): string {
/** Parses one decision file. Problems carry 0-based lines. */
export function parseDecision(text: string, file: string): { decision?: Decision; problems: ModelProblem[] } {
const problems: ModelProblem[] = [];
const doc = parseDocument(text, { prettyErrors: false, uniqueKeys: false });
// prettyErrors would put line numbers into the messages; the line counter gives them without.
const lines = new LineCounter();
const doc = parseDocument(text, { prettyErrors: false, uniqueKeys: false, lineCounter: lines });
for (const error of doc.errors) {
problems.push({ message: `Decision is not valid YAML: ${error.message.split('\n')[0]}`, severity: 'error', file, line: error.linePos?.[0].line ? error.linePos[0].line - 1 : 0 });
problems.push({ message: `Decision is not valid YAML: ${error.message.split('\n')[0]}`, severity: 'error', file, line: lines.linePos(error.pos[0]).line - 1 });
}
if (doc.errors.length) return { problems };
const lineOf = (offset: number | undefined) => (offset === undefined ? 0 : text.slice(0, offset).split('\n').length - 1);
+5 -3
View File
@@ -1,4 +1,4 @@
import { isMap, isScalar, parseDocument, parse as parseYaml } from 'yaml';
import { LineCounter, isMap, isScalar, parse as parseYaml, parseDocument } from 'yaml';
/**
* The model file formats (see docs/model.md): `main.archify` with a `model`
@@ -83,9 +83,11 @@ export function hasDiagramBody(doc: unknown): boolean {
export function parseRegistry(text: string, file: string): { elements: RegistryElement[]; problems: ModelProblem[] } {
const problems: ModelProblem[] = [];
const elements: RegistryElement[] = [];
const doc = parseDocument(text, { prettyErrors: false, uniqueKeys: false });
// prettyErrors would put line numbers into the messages; the line counter gives them without.
const lines = new LineCounter();
const doc = parseDocument(text, { prettyErrors: false, uniqueKeys: false, lineCounter: lines });
for (const error of doc.errors) {
problems.push({ message: `Registry is not valid YAML: ${error.message.split('\n')[0]}`, severity: 'error', file, line: error.linePos?.[0].line ? error.linePos[0].line - 1 : 0 });
problems.push({ message: `Registry is not valid YAML: ${error.message.split('\n')[0]}`, severity: 'error', file, line: lines.linePos(error.pos[0]).line - 1 });
}
if (doc.errors.length) return { elements, problems };
const lineOf = (offset: number | undefined) => (offset === undefined ? 0 : text.slice(0, offset).split('\n').length - 1);