Suggest brand IDs after brand: and place unknown-brand errors on their line
- Completion for brand values in .archify (YAML) and Archify JSON sources, from the bundled brand-marks/catalog.json (107 marks); aliases and product names match, so "kafka" offers apache-kafka - brand/unknown diagnostics carry their JSON pointer only at the start of the message; use it when subject.path is missing, so the error lands on the brand line instead of the top of the file - Unit tests for catalog loading, value detection and pointer fallback; integration checks for completion and diagnostic placement Closes #5
This commit is contained in:
@@ -131,6 +131,54 @@ export async function run(): Promise<void> {
|
||||
);
|
||||
});
|
||||
|
||||
await check('suggests brand IDs after brand: in .archify files', async () => {
|
||||
const target = workspaceFile('brands.archify');
|
||||
const text = [
|
||||
'schema_version: 1',
|
||||
'diagram_type: architecture',
|
||||
'meta:',
|
||||
' title: Brands',
|
||||
'components:',
|
||||
' - id: db',
|
||||
' type: database',
|
||||
' label: DB',
|
||||
' brand: ',
|
||||
' - id: bus',
|
||||
' type: messagebus',
|
||||
' label: Bus',
|
||||
' brand: kafka',
|
||||
'',
|
||||
].join('\n');
|
||||
await vscode.workspace.fs.writeFile(target, new TextEncoder().encode(text));
|
||||
const doc = await vscode.workspace.openTextDocument(target);
|
||||
const labels = async (line: number) => {
|
||||
const list = await vscode.commands.executeCommand<vscode.CompletionList>(
|
||||
'vscode.executeCompletionItemProvider',
|
||||
doc.uri,
|
||||
new vscode.Position(line, doc.lineAt(line).text.length),
|
||||
);
|
||||
return list.items.map((item) => (typeof item.label === 'string' ? item.label : item.label.label));
|
||||
};
|
||||
const empty = await labels(8);
|
||||
assert.ok(empty.includes('postgresql') && empty.includes('redis'), 'brand IDs offered after "brand: "');
|
||||
const kafka = await labels(12);
|
||||
assert.ok(kafka.includes('apache-kafka'), 'the alias "kafka" finds apache-kafka');
|
||||
assert.equal((await labels(7)).includes('postgresql'), false, 'nothing offered for other fields');
|
||||
});
|
||||
|
||||
await check('an unknown brand is reported on its own line', async () => {
|
||||
const target = workspaceFile('unknown-brand.archify');
|
||||
const text = new TextDecoder().decode(await vscode.workspace.fs.readFile(workspaceFile('web-platform.archify')))
|
||||
.replace(/^( {2}- id: [^\n]+\n)/m, '$1 brand: not-a-brand\n');
|
||||
await vscode.workspace.fs.writeFile(target, new TextEncoder().encode(text));
|
||||
const doc = await vscode.workspace.openTextDocument(target);
|
||||
await vscode.window.showTextDocument(doc);
|
||||
const diagnostic = await waitFor('brand/unknown diagnostic', () =>
|
||||
vscode.languages.getDiagnostics(doc.uri).find((d) => d.source === 'archify' && d.code === 'brand/unknown'),
|
||||
);
|
||||
assert.match(doc.lineAt(diagnostic.range.start.line).text, /brand: not-a-brand/);
|
||||
});
|
||||
|
||||
await check('opens a live preview beside the source', async () => {
|
||||
await vscode.commands.executeCommand('archify.showPreviewToSide', workspaceFile('production-deployment.architecture.json'));
|
||||
const tabs = await waitFor('preview tab', () => {
|
||||
|
||||
Reference in New Issue
Block a user