From aa85ed29e8718b19b3b67ea7c4f3aa4f9ebba333 Mon Sep 17 00:00:00 2001 From: Hyko Date: Wed, 15 Apr 2026 13:43:42 -0400 Subject: [PATCH] feat: add VS Code extension entry point with model selection - Register commands for generating commit messages, aborting generation, and selecting AI models - Implement `selectModel` command with progress notification while fetching available models from the configured provider - Display current model in QuickPick and persist selection globally - Show appropriate error/warning messages on failure or empty results --- src/extension.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/extension.ts diff --git a/src/extension.ts b/src/extension.ts new file mode 100644 index 0000000..3ea3abb --- /dev/null +++ b/src/extension.ts @@ -0,0 +1,52 @@ +import * as vscode from "vscode" +import { abortGeneration, generateCommitMsg } from "./commitGenerator" +import { fetchAvailableModels } from "./providers" + +export function activate(context: vscode.ExtensionContext): void { + context.subscriptions.push( + vscode.commands.registerCommand("aiCommit.generateCommitMessage", (scm?: vscode.SourceControl) => + generateCommitMsg(scm), + ), + vscode.commands.registerCommand("aiCommit.abortGeneration", () => abortGeneration()), + vscode.commands.registerCommand("aiCommit.selectModel", () => selectModel()), + ) +} + +async function selectModel(): Promise { + const config = vscode.workspace.getConfiguration("aiCommit") + + let models: string[] + try { + models = await vscode.window.withProgress( + { location: vscode.ProgressLocation.Notification, title: "Zemit: Fetching available models…", cancellable: false }, + () => fetchAvailableModels(config), + ) + } catch (err) { + const msg = err instanceof Error ? err.message : String(err) + vscode.window.showErrorMessage(`[Zemit] ${msg}`) + return + } + + if (models.length === 0) { + vscode.window.showWarningMessage("[Zemit] No models found for the configured provider.") + return + } + + const currentModel = config.get("model", "") + const items = models.map((id) => ({ + label: id, + description: id === currentModel ? "current" : undefined, + })) + + const picked = await vscode.window.showQuickPick(items, { + placeHolder: "Select a model", + matchOnDescription: false, + }) + + if (!picked) return + + await config.update("model", picked.label, vscode.ConfigurationTarget.Global) + vscode.window.showInformationMessage(`[Zemit] Model set to ${picked.label}`) +} + +export function deactivate(): void {}