Ramses Bridge Extension
The Ramses Bridge is the central service provider and the architectural core of the Ramses SDK tooling. It runs as an invisible, background extension that manages shared state and logic, providing a stable API for all other extensions in the ecosystem.
Core Responsibilities
- Schema Provider: It loads the base RXML component schema and watches the user's workspace for custom components (
/components
directory). It then merges them into a single, unified schema that represents all available components for the project.
- Workspace Analysis: It understands the workspace structure, watching for file changes and providing this information to other extensions.
- Central API Hub: It exposes a consistent API, both through direct extension exports (for performance) and VS Code commands (for loose coupling), allowing other extensions like the Language Support and Designer to access its services.
- AST Manager (Future): It will be responsible for parsing
.rxml
files into an Abstract Syntax Tree (AST) and serving it to the Visual Designer, enabling real-time synchronization.
Usage (For Extension Developers)
Other extensions can interact with the bridge in two primary ways:
1. Via Commands (Recommended for loose coupling)
This is the safest way to interact with the bridge.
import * as vscode from "vscode";
// Get the complete, merged RXML schema
const mergedSchema = await vscode.commands.executeCommand(
"ramses.bridge.getSchema",
{
schemaType: "rxml-merged",
}
);
// Get only the user-defined components
const userComponents = await vscode.commands.executeCommand(
"ramses.bridge.getUserComponents"
);
// Force the bridge to rescan the /components directory
await vscode.commands.executeCommand("ramses.bridge.rescanComponents");
2. Direct API Access (For tightly-coupled extensions)
For higher performance, extensions running in the same host can get the bridge's exported API directly.
import * as vscode from "vscode";
export async function activate(context: vscode.ExtensionContext) {
const bridgeExt = vscode.extensions.getExtension("ramses-bridge-ext");
if (bridgeExt) {
// It's crucial to activate the extension to get its exports
const bridgeApi = await bridgeExt.activate();
// Now you can access its functions directly
const schema = bridgeApi.getSchema("rxml-merged");
console.log(
`Loaded schema with ${Object.keys(schema.components).length} components.`
);
// Subscribe to schema updates (e.g., when a user adds a new component)
const disposable = bridgeApi.onSchemaUpdated((schemaType) => {
console.log(`The ${schemaType} schema was updated!`);
// Reload your UI or re-validate documents here
});
context.subscriptions.push(disposable);
}
}