fix: restore commit msg generation functionality to command palette (#7417)
Co-authored-by: Kevin Murphy <murkvin@amazon.com> Co-authored-by: CandiedUniverse <132302818+candieduniverse@users.noreply.github.com>
This commit is contained in:
4 files changed
+127
-31
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
fix: restore commit msg generation functionality to command palette
|
||||
+2
-2
@@ -284,11 +284,11 @@
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "cline.generateGitCommitMessage",
|
||||
"when": "config.git.enabled && scmProvider == git && !cline.isGeneratingCommit"
|
||||
"when": "config.git.enabled && !cline.isGeneratingCommit"
|
||||
},
|
||||
{
|
||||
"command": "cline.abortGitCommitMessage",
|
||||
"when": "config.git.enabled && scmProvider == git && cline.isGeneratingCommit"
|
||||
"when": "config.git.enabled && cline.isGeneratingCommit"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ import { HookDiscoveryCache } from "./core/hooks/HookDiscoveryCache"
|
||||
import { HookProcessRegistry } from "./core/hooks/HookProcessRegistry"
|
||||
import { workspaceResolver } from "./core/workspace"
|
||||
import { focusChatInput, getContextForCommand } from "./hosts/vscode/commandUtils"
|
||||
import { abortCommitGeneration, generateCommitMessage } from "./hosts/vscode/commit-message-generator"
|
||||
import { abortCommitGeneration, generateCommitMsg } from "./hosts/vscode/commit-message-generator"
|
||||
import { VscodeDiffViewProvider } from "./hosts/vscode/VscodeDiffViewProvider"
|
||||
import { VscodeWebviewProvider } from "./hosts/vscode/VscodeWebviewProvider"
|
||||
import { ExtensionRegistryInfo } from "./registry"
|
||||
@@ -392,7 +392,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
// Register the generateGitCommitMessage command handler
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand(commands.GenerateCommit, async (scm) => {
|
||||
generateCommitMessage(webview.controller.stateManager, scm)
|
||||
generateCommitMsg(webview.controller.stateManager, scm)
|
||||
}),
|
||||
vscode.commands.registerCommand(commands.AbortCommit, () => {
|
||||
abortCommitGeneration()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { buildApiHandler } from "@core/api"
|
||||
import * as path from "path"
|
||||
import * as vscode from "vscode"
|
||||
import { StateManager } from "@/core/storage/StateManager"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getGitDiff } from "@/utils/git"
|
||||
import { getCwd } from "@/utils/path"
|
||||
|
||||
/**
|
||||
* Git commit message generator module
|
||||
@@ -24,35 +24,31 @@ The commit message should:
|
||||
4. Be clear and informative`,
|
||||
}
|
||||
|
||||
export async function generateCommitMessage(stateManager: StateManager, scm?: vscode.SourceControl) {
|
||||
const cwd = await getCwd()
|
||||
if (!cwd) {
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "No workspace folder open",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
export async function generateCommitMsg(stateManager: StateManager, scm?: vscode.SourceControl) {
|
||||
try {
|
||||
const inputBox = scm?.inputBox
|
||||
if (!inputBox) {
|
||||
throw new Error("Git extension not found or no repositories available")
|
||||
const gitExtension = vscode.extensions.getExtension("vscode.git")?.exports
|
||||
if (!gitExtension) {
|
||||
throw new Error("Git extension not found")
|
||||
}
|
||||
|
||||
const gitDiff = await getGitDiff(cwd)
|
||||
if (!gitDiff) {
|
||||
throw new Error("No changes in workspace for commit message")
|
||||
const git = gitExtension.getAPI(1)
|
||||
if (git.repositories.length === 0) {
|
||||
throw new Error("No Git repositories available")
|
||||
}
|
||||
|
||||
await vscode.window.withProgress(
|
||||
{
|
||||
location: vscode.ProgressLocation.SourceControl,
|
||||
title: "Generating commit message...",
|
||||
cancellable: true,
|
||||
},
|
||||
() => performCommitGeneration(stateManager, gitDiff, inputBox),
|
||||
)
|
||||
// If scm is provided, then the user specified one repository by clicking the "Source Control" menu button
|
||||
if (scm) {
|
||||
const repository = git.getRepository(scm.rootUri)
|
||||
|
||||
if (!repository) {
|
||||
throw new Error("Repository not found for provided SCM")
|
||||
}
|
||||
|
||||
await generateCommitMsgForRepository(stateManager, repository)
|
||||
return
|
||||
}
|
||||
|
||||
await orchestrateWorkspaceCommitMsgGeneration(stateManager, git.repositories)
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
HostProvider.window.showMessage({
|
||||
@@ -62,13 +58,108 @@ export async function generateCommitMessage(stateManager: StateManager, scm?: vs
|
||||
}
|
||||
}
|
||||
|
||||
async function performCommitGeneration(stateManager: StateManager, gitDiff: string, inputBox: any) {
|
||||
async function orchestrateWorkspaceCommitMsgGeneration(stateManager: StateManager, repos: any[]) {
|
||||
const reposWithChanges = await filterForReposWithChanges(repos)
|
||||
|
||||
if (reposWithChanges.length === 0) {
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.INFORMATION,
|
||||
message: "No changes found in any workspace repositories",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (reposWithChanges.length === 1) {
|
||||
// Only one repo with changes, generate for it
|
||||
const repo = reposWithChanges[0]
|
||||
await generateCommitMsgForRepository(stateManager, repo)
|
||||
return
|
||||
}
|
||||
|
||||
const selection = await promptRepoSelection(reposWithChanges)
|
||||
|
||||
if (!selection) {
|
||||
// User cancelled
|
||||
return
|
||||
}
|
||||
|
||||
if (selection.repo === null) {
|
||||
// Generate for all repositories with changes
|
||||
for (const repo of reposWithChanges) {
|
||||
try {
|
||||
await generateCommitMsgForRepository(stateManager, repo)
|
||||
} catch (error) {
|
||||
console.error(`Failed to generate commit message for ${repo.rootUri.fsPath}:`, error)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Generate for selected repository
|
||||
await generateCommitMsgForRepository(stateManager, selection.repo)
|
||||
}
|
||||
}
|
||||
|
||||
async function filterForReposWithChanges(repos: any[]) {
|
||||
const reposWithChanges = []
|
||||
|
||||
// Check which repositories have changes
|
||||
for (const repo of repos) {
|
||||
try {
|
||||
const gitDiff = await getGitDiff(repo.rootUri.fsPath)
|
||||
if (gitDiff) {
|
||||
reposWithChanges.push(repo)
|
||||
}
|
||||
} catch (error) {
|
||||
// Skip repositories with errors (no changes, etc.)
|
||||
}
|
||||
}
|
||||
return reposWithChanges
|
||||
}
|
||||
|
||||
async function promptRepoSelection(repos: any[]) {
|
||||
// Multiple repos with changes - ask user to choose
|
||||
const repoItems = repos.map((repo) => ({
|
||||
label: repo.rootUri.fsPath.split(path.sep).pop() || repo.rootUri.fsPath,
|
||||
description: repo.rootUri.fsPath,
|
||||
repo: repo,
|
||||
}))
|
||||
|
||||
repoItems.unshift({
|
||||
label: "$(git-commit) Generate for all repositories with changes",
|
||||
description: `Generate commit messages for ${repos.length} repositories`,
|
||||
repo: null as any,
|
||||
})
|
||||
|
||||
return await vscode.window.showQuickPick(repoItems, {
|
||||
placeHolder: "Select repository for commit message generation",
|
||||
})
|
||||
}
|
||||
|
||||
async function generateCommitMsgForRepository(stateManager: StateManager, repository: any) {
|
||||
const inputBox = repository.inputBox
|
||||
const repoPath = repository.rootUri.fsPath
|
||||
const gitDiff = await getGitDiff(repoPath)
|
||||
|
||||
if (!gitDiff) {
|
||||
throw new Error(`No changes in repository ${repoPath.split(path.sep).pop() || "repository"} for commit message`)
|
||||
}
|
||||
|
||||
await vscode.window.withProgress(
|
||||
{
|
||||
location: vscode.ProgressLocation.SourceControl,
|
||||
title: `Generating commit message for ${repoPath.split(path.sep).pop() || "repository"}...`,
|
||||
cancellable: true,
|
||||
},
|
||||
() => performCommitMsgGeneration(stateManager, gitDiff, inputBox),
|
||||
)
|
||||
}
|
||||
|
||||
async function performCommitMsgGeneration(stateManager: StateManager, gitDiff: string, inputBox: any) {
|
||||
try {
|
||||
vscode.commands.executeCommand("setContext", "cline.isGeneratingCommit", true)
|
||||
|
||||
const prompts = [PROMPT.instruction]
|
||||
|
||||
const currentInput = inputBox?.value?.trim() || ""
|
||||
const currentInput = inputBox.value?.trim() || ""
|
||||
if (currentInput) {
|
||||
prompts.push(PROMPT.user.replace("{{USER_CURRENT_INPUT}}", currentInput))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user