Files
archify-vscode-ext/src/commands/context.ts
T
root-at-skic ebf320a023 Architecture decisions: files, diagram references, views and panels
- *.archify-decision files: id (unique, words), title, status, date,
  elements, diagrams, supersedes, and prose; parsed, merged and link-checked
  in the model index; diagnostics on the file
- diagrams point at decisions with decisions: [...] on the diagram, nodes
  and edges; stripped before Archify, unknown ids reported, completion,
  hover and go-to-definition for the ids and for elements/diagrams/
  supersedes in decision files
- Decisions panel on the main.archify page; Decisions rail panel under a
  diagram (hover lights up the node or connection); decisions on element
  cards and in the element dialog; decision view for the file, with a
  lost-model note outside a model
- Archify | New Decision… command and template; editor schemas; the three
  New Model examples carry decisions; docs, changelog, 0.8.0
2026-10-19 23:13:05 +03:00

45 lines
1.7 KiB
TypeScript

import * as vscode from 'vscode';
import { HTML_VIEW_TYPE, HtmlViewerProvider } from '../views/htmlViewer';
import { ModelService } from '../model/service';
import { DiagramViewManager } from '../views/diagramView';
import { RegistryViewProvider } from '../views/registryView';
import { DecisionViewProvider } from '../views/decisionView';
/** What command handlers share: the extension context and the open views. */
export interface CommandContext {
extension: vscode.ExtensionContext;
views: DiagramViewManager;
htmlViewer: HtmlViewerProvider;
registry: RegistryViewProvider;
decision: DecisionViewProvider;
models: ModelService;
}
export function isHtmlUri(uri: vscode.Uri): boolean {
return /\.html?$/i.test(uri.path);
}
/** The file a command applies to: explicit argument, focused preview or viewer, then the text editor. */
export function targetUri(ctx: CommandContext, arg?: unknown): vscode.Uri | undefined {
if (arg instanceof vscode.Uri) return arg;
return ctx.views.activePreview?.uri ?? ctx.registry.activeUri ?? ctx.decision.activeUri ?? ctx.htmlViewer.activeUri ?? vscode.window.activeTextEditor?.document.uri;
}
export function sourceUri(ctx: CommandContext, arg?: unknown): vscode.Uri | undefined {
const uri = targetUri(ctx, arg);
if (!uri) vscode.window.showWarningMessage('Archify: open a .archify diagram first.');
return uri;
}
export const openHtmlViewer = (uri: vscode.Uri, viewColumn?: vscode.ViewColumn) =>
vscode.commands.executeCommand('vscode.openWith', uri, HTML_VIEW_TYPE, viewColumn);
export async function exists(uri: vscode.Uri): Promise<boolean> {
try {
await vscode.workspace.fs.stat(uri);
return true;
} catch {
return false;
}
}