diff --git a/src/commands/BaseCommand.ts b/src/commands/BaseCommand.ts index 03684c9..e0a3f7b 100644 --- a/src/commands/BaseCommand.ts +++ b/src/commands/BaseCommand.ts @@ -1,10 +1,14 @@ import * as vscode from "vscode"; import { NotificationHandler } from "../utils/NotificationHandler"; import { ConfigurationManager } from "../config/ConfigurationManager"; -import { LocalizationManager } from '../utils/LocalizationManager' +import { LocalizationManager } from "../utils/LocalizationManager"; export abstract class BaseCommand { - constructor(protected readonly context: vscode.ExtensionContext) {} + protected context: vscode.ExtensionContext; + + constructor(context: vscode.ExtensionContext) { + this.context = context; + } protected async validateConfig(): Promise { if (!(await ConfigurationManager.getInstance().validateConfiguration())) { @@ -14,7 +18,10 @@ export abstract class BaseCommand { return true; } - protected async handleError(error: unknown, errorMessage: string): Promise { + protected async handleError( + error: unknown, + errorMessage: string + ): Promise { console.error(errorMessage, error); if (error instanceof Error) { await NotificationHandler.error( diff --git a/src/commands/GenerateCommitCommand.ts b/src/commands/GenerateCommitCommand.ts index 1a4792d..1960c16 100644 --- a/src/commands/GenerateCommitCommand.ts +++ b/src/commands/GenerateCommitCommand.ts @@ -5,9 +5,7 @@ import { NotificationHandler } from "../utils/NotificationHandler"; import { ProgressHandler } from "../utils/ProgressHandler"; import { AIProviderFactory } from "../ai/AIProviderFactory"; import { SCMFactory } from "../scm/SCMProvider"; -import { getProviderModelConfig, type ConfigKey } from "../config/types"; -import { DISPLAY_NAME } from "../constants"; -import { getMaxCharacters } from "../ai/types"; +import { type ConfigKey } from "../config/types"; import { LocalizationManager } from "../utils/LocalizationManager"; import { ModelPickerService } from "../services/ModelPickerService"; @@ -35,8 +33,8 @@ export class GenerateCommitCommand extends BaseCommand { } const config = ConfigurationManager.getInstance(); - await config.updateConfig("PROVIDERS_OPENAI_BASEURL" as ConfigKey, baseURL); - await config.updateConfig("PROVIDERS_OPENAI_APIKEY" as ConfigKey, apiKey); + await config.updateConfig("PROVIDERS_OPENAI_BASEURL", baseURL); + await config.updateConfig("PROVIDERS_OPENAI_APIKEY", apiKey); return true; } @@ -219,7 +217,8 @@ export class GenerateCommitCommand extends BaseCommand { const result = await aiProvider.generateResponse({ ...configuration.base, // 包含 systemPrompt, language 等基础配置 - ...configuration.features.commitOptions, // 包含 allowMergeCommits, useEmoji 等选项 + ...configuration.features.commitFormat, + ...configuration.features.codeAnalysis, additionalContext: currentInput, diff: diffContent, model: selectedModel, diff --git a/src/commands/SelectModelCommand.ts b/src/commands/SelectModelCommand.ts index 01223a7..08aef71 100644 --- a/src/commands/SelectModelCommand.ts +++ b/src/commands/SelectModelCommand.ts @@ -2,22 +2,27 @@ import * as vscode from "vscode"; import { BaseCommand } from "./BaseCommand"; import { ConfigurationManager } from "../config/ConfigurationManager"; import { NotificationHandler } from "../utils/NotificationHandler"; -import { AIProviderFactory } from "../ai/AIProviderFactory"; -import { getProviderModelConfig } from "../config/types"; -import { LocalizationManager } from "../utils/LocalizationManager"; import { ModelPickerService } from "../services/ModelPickerService"; export class SelectModelCommand extends BaseCommand { + constructor(context: vscode.ExtensionContext) { + super(context); + } + async execute(): Promise { - const config = ConfigurationManager.getInstance(); - const configuration = config.getConfiguration(); + const configManager = ConfigurationManager.getInstance(); + + // 只获取需要的配置项 + const currentProvider = configManager.getConfig("BASE_PROVIDER"); + const currentModel = configManager.getConfig("BASE_MODEL"); + const modelSelection = await this.showModelPicker( - configuration.base.provider, - getProviderModelConfig(configuration, configuration.base.provider) + currentProvider, + currentModel ); if (modelSelection) { - await config.updateAIConfiguration( + await configManager.updateAIConfiguration( modelSelection.provider, modelSelection.model );