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

+53 -3
View File
@@ -61,9 +61,18 @@ export async function run(): Promise<void> {
assert.equal(vscode.window.activeTextEditor?.document.uri.toString() === uri.toString(), false, 'no text editor was opened for it');
});
await check('.archify files are YAML and Show Source opens the text beside the diagram', async () => {
await check('Show Source keeps the diagram in its one tab (the page switches to Source)', async () => {
const uri = workspaceFile('web-platform.archify');
await vscode.commands.executeCommand('archify.showSource');
await new Promise((resolve) => setTimeout(resolve, 1000));
assert.equal(vscode.window.visibleTextEditors.some((e) => e.document.uri.toString() === uri.toString()), false, 'no text editor was opened');
const tabs = vscode.window.tabGroups.all.flatMap((g) => g.tabs).filter((t) => t.input instanceof vscode.TabInputCustom && t.input.uri.toString() === uri.toString());
assert.equal(tabs.length, 1);
});
await check('.archify files are YAML and Open in Text Editor opens the text beside the diagram', async () => {
const uri = workspaceFile('web-platform.archify');
await vscode.commands.executeCommand('archify.openInTextEditor');
const editor = await waitFor('source text editor', () =>
vscode.window.visibleTextEditors.find((e) => e.document.uri.toString() === uri.toString()),
);
@@ -333,14 +342,14 @@ export async function run(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 500));
});
await check('a .archify-registry file opens as the registry view and Show Source opens the YAML', async () => {
await check('a .archify-registry file opens as the registry view and Open in Text Editor opens the YAML', async () => {
const registry = workspaceFile('model/registry/people.archify-registry');
await vscode.commands.executeCommand('vscode.open', registry);
const tab = await waitFor('registry view tab', () =>
vscode.window.tabGroups.all.flatMap((g) => g.tabs).find((t) => t.isActive && t.input instanceof vscode.TabInputCustom && t.input.viewType === 'archify.registry' && t.input.uri.toString() === registry.toString()),
);
assert.ok(tab);
await vscode.commands.executeCommand('archify.showSource');
await vscode.commands.executeCommand('archify.openInTextEditor');
const editor = await waitFor('registry text editor', () => vscode.window.visibleTextEditors.find((e) => e.document.uri.toString() === registry.toString()));
assert.equal(editor.document.languageId, 'yaml');
});
@@ -459,4 +468,45 @@ export async function run(): Promise<void> {
const errors = vscode.languages.getDiagnostics(containers.uri).filter((d) => d.severity === vscode.DiagnosticSeverity.Error);
assert.deepEqual(errors.map((d) => d.message), []);
});
await check('a registry is checked against its schema without a YAML extension', async () => {
const target = workspaceFile('model/registry/typo.archify-registry');
await vscode.workspace.fs.writeFile(target, new TextEncoder().encode('schema_version: 1\nelements:\n billing:\n typ: backend\n label: Billing\n'));
const doc = await vscode.workspace.openTextDocument(target);
await vscode.window.showTextDocument(doc);
const unknown = await waitFor('unknown key diagnostic', () =>
vscode.languages.getDiagnostics(doc.uri).find((d) => d.source === 'archify' && /Unknown key "typ" in elements\.billing/.test(d.message)),
);
assert.equal(doc.getText(unknown.range), 'typ');
assert.ok(vscode.languages.getDiagnostics(doc.uri).some((d) => /"type" is required in elements\.billing/.test(d.message)));
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await vscode.workspace.fs.delete(target);
});
await check('registry and decision pages own their document: edits make it dirty and VS Code undo reverts them', async () => {
for (const [file, viewType] of [
['model/registry/containers.archify-registry', 'archify.registry'],
['model/decisions/0001-postgres-as-source-of-truth.archify-decision', 'archify.decision'],
] as const) {
const uri = workspaceFile(file);
await vscode.commands.executeCommand('vscode.openWith', uri, viewType);
await waitFor(`${viewType} tab`, () =>
vscode.window.tabGroups.activeTabGroup.activeTab?.input instanceof vscode.TabInputCustom &&
(vscode.window.tabGroups.activeTabGroup.activeTab.input as vscode.TabInputCustom).uri.toString() === uri.toString(),
);
const doc = await vscode.workspace.openTextDocument(uri);
const before = doc.getText();
// What the Source view does with a keystroke: a WorkspaceEdit on the document.
const edit = new vscode.WorkspaceEdit();
edit.insert(uri, new vscode.Position(0, 0), '# edited in Source\n');
assert.ok(await vscode.workspace.applyEdit(edit));
assert.ok(doc.isDirty, `${file} is dirty`);
const tab = vscode.window.tabGroups.activeTabGroup.activeTab;
assert.ok(tab?.isDirty, 'the page tab shows the dirty dot');
// ⌘Z in the page reaches VS Code as the undo command.
await vscode.commands.executeCommand('undo');
await waitFor('undo', () => doc.getText() === before);
await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor');
}
});
}