Improve the git commit message generator (#6583)
* Commit message generator shouldn't create it's own StateManager, just use the one from the webview. * Use the correct Cline logo * Move it into the vscode specific directory, it uses too many VSCode APIs to work cross-platform.
This commit is contained in:
1 parent
99b8b92b27
commit
c2f69737aa
3 files changed
+13
-18
No files matched your search
+4
-1
@@ -168,7 +168,10 @@
|
||||
"command": "cline.generateGitCommitMessage",
|
||||
"title": "Generate Commit Message with Cline",
|
||||
"category": "Cline",
|
||||
"icon": "$(robot)"
|
||||
"icon": {
|
||||
"light": "assets/icons/robot_panel_light.png",
|
||||
"dark": "assets/icons/robot_panel_dark.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "cline.abortGitCommitMessage",
|
||||
|
||||
+3
-3
@@ -29,9 +29,9 @@ import { sendAddToInputEvent } from "./core/controller/ui/subscribeToAddToInput"
|
||||
import { sendFocusChatInputEvent } from "./core/controller/ui/subscribeToFocusChatInput"
|
||||
import { workspaceResolver } from "./core/workspace"
|
||||
import { focusChatInput, getContextForCommand } from "./hosts/vscode/commandUtils"
|
||||
import { abortCommitGeneration, generateCommitMessage } from "./hosts/vscode/commit-message-generator"
|
||||
import { VscodeDiffViewProvider } from "./hosts/vscode/VscodeDiffViewProvider"
|
||||
import { VscodeWebviewProvider } from "./hosts/vscode/VscodeWebviewProvider"
|
||||
import { GitCommitGenerator } from "./integrations/git/commit-message-generator"
|
||||
import { ExtensionRegistryInfo } from "./registry"
|
||||
import { AuthService } from "./services/auth/AuthService"
|
||||
import { telemetryService } from "./services/telemetry"
|
||||
@@ -365,10 +365,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
// Register the generateGitCommitMessage command handler
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand(commands.GenerateCommit, async (scm) => {
|
||||
await GitCommitGenerator?.generate?.(context, scm)
|
||||
generateCommitMessage(webview.controller.stateManager, scm)
|
||||
}),
|
||||
vscode.commands.registerCommand(commands.AbortCommit, () => {
|
||||
GitCommitGenerator?.abort?.()
|
||||
abortCommitGeneration()
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
+6
-14
@@ -9,10 +9,6 @@ import { getCwd } from "@/utils/path"
|
||||
/**
|
||||
* Git commit message generator module
|
||||
*/
|
||||
export const GitCommitGenerator = {
|
||||
generate,
|
||||
abort,
|
||||
}
|
||||
|
||||
let commitGenerationAbortController: AbortController | undefined
|
||||
|
||||
@@ -28,9 +24,9 @@ The commit message should:
|
||||
4. Be clear and informative`,
|
||||
}
|
||||
|
||||
async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceControl) {
|
||||
export async function generateCommitMessage(stateManager: StateManager, scm?: vscode.SourceControl) {
|
||||
const cwd = await getCwd()
|
||||
if (!context || !cwd) {
|
||||
if (!cwd) {
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "No workspace folder open",
|
||||
@@ -55,7 +51,7 @@ async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceCon
|
||||
title: "Generating commit message...",
|
||||
cancellable: true,
|
||||
},
|
||||
() => performCommitGeneration(context, gitDiff, inputBox),
|
||||
() => performCommitGeneration(stateManager, gitDiff, inputBox),
|
||||
)
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
@@ -66,7 +62,7 @@ async function generate(context: vscode.ExtensionContext, scm?: vscode.SourceCon
|
||||
}
|
||||
}
|
||||
|
||||
async function performCommitGeneration(context: vscode.ExtensionContext, gitDiff: string, inputBox: any) {
|
||||
async function performCommitGeneration(stateManager: StateManager, gitDiff: string, inputBox: any) {
|
||||
try {
|
||||
vscode.commands.executeCommand("setContext", "cline.isGeneratingCommit", true)
|
||||
|
||||
@@ -82,11 +78,7 @@ async function performCommitGeneration(context: vscode.ExtensionContext, gitDiff
|
||||
const prompt = prompts.join("\n\n")
|
||||
|
||||
// Get the current API configuration
|
||||
const stateManager = new StateManager(context)
|
||||
await stateManager.initialize()
|
||||
|
||||
// Set to use Act mode for now by default
|
||||
// TODO: A new mode for commit generation
|
||||
const apiConfiguration = stateManager.getApiConfiguration()
|
||||
const currentMode = "act"
|
||||
|
||||
@@ -125,7 +117,7 @@ async function performCommitGeneration(context: vscode.ExtensionContext, gitDiff
|
||||
}
|
||||
}
|
||||
|
||||
function abort() {
|
||||
export function abortCommitGeneration() {
|
||||
commitGenerationAbortController?.abort()
|
||||
vscode.commands.executeCommand("setContext", "cline.isGeneratingCommit", false)
|
||||
}
|
||||
@@ -135,7 +127,7 @@ function abort() {
|
||||
* @param str String containing the AI response
|
||||
* @returns The extracted commit message
|
||||
*/
|
||||
export function extractCommitMessage(str: string): string {
|
||||
function extractCommitMessage(str: string): string {
|
||||
// Remove any markdown formatting or extra text
|
||||
return str
|
||||
.trim()
|
||||
Reference in new issue
Block a user