diff --git a/src/commands/openSchemaVisualizer.ts b/src/commands/openSchemaVisualizer.ts index febdcc0..1013497 100644 --- a/src/commands/openSchemaVisualizer.ts +++ b/src/commands/openSchemaVisualizer.ts @@ -8,6 +8,7 @@ import { openSchemaVisualizerPanel } from "../panels/schemaVisualizerPanel"; import { EXTENSION_URI } from "../extension"; import { services } from "../services"; import { handleError } from "../errors"; +import { MESSAGES } from "../utils/constants"; /** * Opens the schema visualizer panel. @@ -20,9 +21,21 @@ export async function openSchemaVisualizer( context: vscode.ExtensionContext, focusedType?: string, ) { + // Check workspace trust + if (!vscode.workspace.isTrusted) { + vscode.window.showWarningMessage(MESSAGES.FEATURE_NOT_AVAILABLE_UNTRUSTED); + return; + } + + // Check if workspace is open + if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) { + vscode.window.showErrorMessage(MESSAGES.NO_WORKSPACE_OPEN); + return; + } + try { services.logger.info( - `Opening Schema Visualizer command${focusedType ? ` focused on type: ${focusedType}` : ""}`, + `Opening Schema Visualizer${focusedType ? ` focused on type: ${focusedType}` : ""}`, ); const extensionUri = EXTENSION_URI || context.extensionUri; diff --git a/src/panels/schemaVisualizerPanel.ts b/src/panels/schemaVisualizerPanel.ts index 3052b57..9d65e09 100644 --- a/src/panels/schemaVisualizerPanel.ts +++ b/src/panels/schemaVisualizerPanel.ts @@ -12,7 +12,6 @@ import type { TypeRelationship, } from "../services/schema/indexer"; import { services } from "../services"; -import { resolveStepZenProjectRoot } from "../utils/stepzenProject"; import * as path from "path"; import * as fs from "fs"; import { MESSAGES, FILE_PATTERNS, UI } from "../utils/constants"; @@ -94,16 +93,18 @@ class SchemaVisualizerPanel extends BaseWebviewPanel { // Build the schema model for visualization const schemaModel = this.buildSchemaModel(); - // Debug logging + // Validate the schema model + const typeCount = Object.keys(schemaModel.types).length; + const fieldCount = Object.keys(schemaModel.fields).length; + const relationshipCount = schemaModel.relationships.length; + services.logger.debug( - `Schema model built: ${Object.keys(schemaModel.types).length} types, ${ - Object.keys(schemaModel.fields).length - } fields with entries, ${schemaModel.relationships.length} relationships`, + `Schema model built: ${typeCount} types, ${fieldCount} field entries, ${relationshipCount} relationships`, ); - if (Object.keys(schemaModel.types).length === 0) { - services.logger.warn("No types found in schema model"); - this.panel.webview.html = this.getNoProjectHtml(); + if (typeCount === 0) { + services.logger.warn("No types found in schema model - showing empty schema message"); + this.panel.webview.html = this.getEmptySchemaHtml(); return; } @@ -119,7 +120,7 @@ class SchemaVisualizerPanel extends BaseWebviewPanel { private setupMessageHandling(): void { if (!this.panel) {return;} - this.messageHandler = this.panel.webview.onDidReceiveMessage((message) => { + this.messageHandler = this.panel.webview.onDidReceiveMessage(async (message) => { switch (message.command) { case "navigateToLocation": const uri = vscode.Uri.file(message.location.uri); @@ -141,6 +142,19 @@ class SchemaVisualizerPanel extends BaseWebviewPanel { // Log messages from the webview to the StepZen output channel services.logger.debug(`[Webview] ${message.message}`); return; + case "refresh-schema": + // Handle schema refresh request + services.logger.info("Schema refresh requested from visualizer"); + try { + // Clear the schema index cache + services.schemaIndex.clearState(); + // Reload the schema data + await this.openWithFocus(); + } catch (error) { + services.logger.error("Failed to refresh schema", error); + vscode.window.showErrorMessage("Failed to refresh schema data. Check the output for details."); + } + return; } }); } @@ -199,7 +213,7 @@ class SchemaVisualizerPanel extends BaseWebviewPanel {