2025-12-13 16:34:17 +02:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
import { ChatViewProvider } from './ChatViewProvider';
|
|
|
|
|
import { createOpenCodeManager, type OpenCodeManager } from './opencode';
|
|
|
|
|
|
|
|
|
|
let chatViewProvider: ChatViewProvider | undefined;
|
|
|
|
|
let openCodeManager: OpenCodeManager | undefined;
|
|
|
|
|
|
2025-12-24 03:32:24 +02:00
|
|
|
export async function activate(context: vscode.ExtensionContext) {
|
2025-12-13 16:34:17 +02:00
|
|
|
// Create OpenCode manager first
|
|
|
|
|
openCodeManager = createOpenCodeManager(context);
|
|
|
|
|
|
|
|
|
|
// Create chat view provider with manager reference
|
2025-12-24 03:32:24 +02:00
|
|
|
// The webview will show a loading state until OpenCode is ready
|
2025-12-13 16:34:17 +02:00
|
|
|
chatViewProvider = new ChatViewProvider(context, context.extensionUri, openCodeManager);
|
|
|
|
|
|
|
|
|
|
context.subscriptions.push(
|
|
|
|
|
vscode.window.registerWebviewViewProvider(
|
|
|
|
|
ChatViewProvider.viewType,
|
|
|
|
|
chatViewProvider,
|
|
|
|
|
{ webviewOptions: { retainContextWhenHidden: true } }
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
context.subscriptions.push(
|
|
|
|
|
vscode.commands.registerCommand('openchamber.restartApi', async () => {
|
2025-12-13 21:14:18 +02:00
|
|
|
try {
|
|
|
|
|
await openCodeManager?.restart();
|
|
|
|
|
vscode.window.showInformationMessage('OpenChamber: API connection restarted');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
vscode.window.showErrorMessage(`OpenChamber: Failed to restart API - ${e}`);
|
2025-12-13 16:34:17 +02:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
context.subscriptions.push(
|
|
|
|
|
vscode.window.onDidChangeActiveColorTheme((theme) => {
|
|
|
|
|
chatViewProvider?.updateTheme(theme.kind);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-15 02:29:39 +02:00
|
|
|
// Theme changes can update the `workbench.colorTheme` setting slightly after the
|
|
|
|
|
// `activeColorTheme` event. Listen for config changes too so we can re-resolve
|
|
|
|
|
// the contributed theme JSON and update Shiki themes in the webview.
|
|
|
|
|
context.subscriptions.push(
|
|
|
|
|
vscode.workspace.onDidChangeConfiguration((event) => {
|
|
|
|
|
if (
|
|
|
|
|
event.affectsConfiguration('workbench.colorTheme') ||
|
|
|
|
|
event.affectsConfiguration('workbench.preferredLightColorTheme') ||
|
|
|
|
|
event.affectsConfiguration('workbench.preferredDarkColorTheme')
|
|
|
|
|
) {
|
|
|
|
|
chatViewProvider?.updateTheme(vscode.window.activeColorTheme.kind);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-24 03:32:24 +02:00
|
|
|
// Subscribe to status changes - this broadcasts to webview
|
2025-12-13 16:34:17 +02:00
|
|
|
context.subscriptions.push(
|
|
|
|
|
openCodeManager.onStatusChange((status, error) => {
|
|
|
|
|
chatViewProvider?.updateConnectionStatus(status, error);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-24 03:32:24 +02:00
|
|
|
// Start OpenCode API and wait for it to be ready
|
|
|
|
|
// The webview will show loading state during this time
|
|
|
|
|
await openCodeManager.start();
|
2025-12-13 16:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-24 03:32:24 +02:00
|
|
|
export async function deactivate() {
|
|
|
|
|
await openCodeManager?.stop();
|
2025-12-13 16:34:17 +02:00
|
|
|
openCodeManager = undefined;
|
|
|
|
|
chatViewProvider = undefined;
|
|
|
|
|
}
|