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
This commit is contained in:
@@ -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<void> {
|
||||||
|
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<string>("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 {}
|
||||||
Reference in New Issue
Block a user