Skip to content

Commit 5894bf5

Browse files
committed
feat(action): add dropdown to generate commit action
1 parent 951b219 commit 5894bf5

File tree

15 files changed

+111
-106
lines changed

15 files changed

+111
-106
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Generate commit action button is now a split button with a dropdown from which the user can change the LLM client from the commit dialog.
8+
59
## [2.11.1] - 2025-04-25
610

711
### Fixed
Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,36 @@
11
package com.github.blarc.ai.commits.intellij.plugin
22

3-
import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
4-
import com.github.blarc.ai.commits.intellij.plugin.notifications.Notification
5-
import com.github.blarc.ai.commits.intellij.plugin.notifications.sendNotification
6-
import com.github.blarc.ai.commits.intellij.plugin.settings.ProjectSettings
7-
import com.intellij.openapi.actionSystem.ActionUpdateThread
8-
import com.intellij.openapi.actionSystem.AnAction
9-
import com.intellij.openapi.actionSystem.AnActionEvent
10-
import com.intellij.openapi.components.service
3+
import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings2
4+
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
5+
import com.intellij.openapi.actionSystem.*
116
import com.intellij.openapi.project.DumbAware
12-
import com.intellij.openapi.vcs.VcsDataKeys
13-
import com.intellij.openapi.vcs.ui.CommitMessage
14-
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
157

16-
class AICommitAction : AnAction(), DumbAware {
17-
18-
19-
override fun getActionUpdateThread(): ActionUpdateThread {
20-
return ActionUpdateThread.EDT
21-
}
22-
23-
override fun update(e: AnActionEvent) {
24-
e.project?.service<ProjectSettings>()?.getActiveLLMClientConfiguration()?.let {
25-
if (it.getGenerateCommitMessageJob()?.isActive == true) {
26-
e.presentation.icon = Icons.Process.STOP.getThemeBasedIcon()
27-
} else {
28-
e.presentation.icon = it.getClientIcon()
29-
e.presentation.text = message("action.tooltip", it.name)
8+
class AICommitAction : SplitButtonAction(object : ActionGroup() {
9+
override fun getChildren(e: AnActionEvent?): Array<AnAction> {
10+
val configurations = AppSettings2.instance.llmClientConfigurations.sortedWith(
11+
compareBy<LLMClientConfiguration> {
12+
it.id != AppSettings2.instance.activeLlmClientId
13+
}.thenBy {
14+
it.name
3015
}
31-
}
32-
}
16+
)
3317

34-
override fun actionPerformed(e: AnActionEvent) {
35-
val project = e.project ?: return
18+
val actions = mutableListOf<AnAction>()
19+
if (configurations.isNotEmpty()) {
20+
actions.add(configurations.first())
3621

37-
val llmClient = project.service<ProjectSettings>().getActiveLLMClientConfiguration()
38-
if (llmClient == null) {
39-
sendNotification(Notification.clientNotSet())
40-
return
41-
}
42-
43-
val generateCommitMessageJob = llmClient.getGenerateCommitMessageJob()
44-
if (generateCommitMessageJob?.isActive == true) {
45-
generateCommitMessageJob.cancel()
46-
return
47-
}
22+
if (configurations.size > 1) {
23+
actions.add(Separator.getInstance())
24+
}
4825

49-
val commitWorkflowHandler = e.getData(VcsDataKeys.COMMIT_WORKFLOW_HANDLER) as AbstractCommitWorkflowHandler<*, *>?
50-
if (commitWorkflowHandler == null) {
51-
sendNotification(Notification.noCommitMessage())
52-
return
26+
actions.addAll(configurations.drop(1))
5327
}
5428

55-
val commitMessage = VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.dataContext) as CommitMessage?
56-
if (commitMessage == null) {
57-
sendNotification(Notification.noCommitMessage())
58-
return
59-
}
29+
return actions.toTypedArray()
30+
}
31+
}), DumbAware {
6032

61-
llmClient.generateCommitMessage(commitWorkflowHandler, commitMessage, project)
33+
override fun getActionUpdateThread(): ActionUpdateThread {
34+
return ActionUpdateThread.EDT
6235
}
6336
}

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/LLMClientConfiguration.kt

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.github.blarc.ai.commits.intellij.plugin.settings.clients
22

3+
import com.github.blarc.ai.commits.intellij.plugin.Icons
4+
import com.github.blarc.ai.commits.intellij.plugin.notifications.Notification
5+
import com.github.blarc.ai.commits.intellij.plugin.notifications.sendNotification
6+
import com.intellij.openapi.actionSystem.ActionUpdateThread
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
39
import com.intellij.openapi.project.Project
4-
import com.intellij.openapi.vcs.ui.CommitMessage
10+
import com.intellij.openapi.vcs.VcsDataKeys
511
import com.intellij.util.xmlb.annotations.Attribute
612
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
713
import kotlinx.coroutines.Job
@@ -12,7 +18,7 @@ abstract class LLMClientConfiguration(
1218
@Attribute var name: String,
1319
@Attribute var modelId: String,
1420
@Attribute var temperature: String,
15-
) : Cloneable, Comparable<LLMClientConfiguration> {
21+
) : Cloneable, Comparable<LLMClientConfiguration>, AnAction() {
1622

1723
@Attribute
1824
var id: String = UUID.randomUUID().toString()
@@ -39,11 +45,11 @@ abstract class LLMClientConfiguration(
3945
getSharedState().modelIds.add(modelId)
4046
}
4147

42-
open fun setCommitMessage(commitMessage: CommitMessage, prompt: String, result: String) {
43-
commitMessage.setCommitMessage(result)
48+
open fun setCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, prompt: String, result: String) {
49+
commitWorkflowHandler.setCommitMessage(result)
4450
}
4551

46-
abstract fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project)
52+
abstract fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project)
4753

4854
abstract fun getGenerateCommitMessageJob(): Job?
4955

@@ -55,6 +61,39 @@ abstract class LLMClientConfiguration(
5561
return name.compareTo(other.name)
5662
}
5763

64+
override fun actionPerformed(e: AnActionEvent) {
65+
val project = e.project ?: return
66+
67+
val generateCommitMessageJob = getGenerateCommitMessageJob()
68+
if (generateCommitMessageJob?.isActive == true) {
69+
generateCommitMessageJob.cancel()
70+
return
71+
}
72+
73+
val commitWorkflowHandler = e.getData(VcsDataKeys.COMMIT_WORKFLOW_HANDLER) as AbstractCommitWorkflowHandler<*, *>?
74+
if (commitWorkflowHandler == null) {
75+
sendNotification(Notification.noCommitMessage())
76+
return
77+
}
78+
79+
generateCommitMessage(commitWorkflowHandler, project)
80+
}
81+
82+
override fun update(e: AnActionEvent) {
83+
84+
if (getGenerateCommitMessageJob()?.isActive == true) {
85+
e.presentation.icon = Icons.Process.STOP.getThemeBasedIcon()
86+
} else {
87+
e.presentation.icon = getClientIcon()
88+
// e.presentation.text = message("action.tooltip", name)
89+
e.presentation.text = name
90+
}
91+
}
92+
93+
override fun getActionUpdateThread(): ActionUpdateThread {
94+
return ActionUpdateThread.EDT
95+
}
96+
5897
// override fun equals(other: Any?): Boolean {
5998
// return other is LLMClientConfiguration && other.id == id
6099
// }

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/LLMClientService.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.Project
1919
import com.intellij.openapi.ui.ComboBox
2020
import com.intellij.openapi.ui.naturalSorted
2121
import com.intellij.openapi.vcs.changes.Change
22-
import com.intellij.openapi.vcs.ui.CommitMessage
2322
import com.intellij.platform.ide.progress.withBackgroundProgress
2423
import com.intellij.ui.components.JBLabel
2524
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
@@ -75,7 +74,7 @@ abstract class LLMClientService<C : LLMClientConfiguration>(private val cs: Coro
7574
}
7675
}
7776

78-
fun generateCommitMessage(clientConfiguration: C, commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
77+
fun generateCommitMessage(clientConfiguration: C, commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
7978

8079
val commitContext = commitWorkflowHandler.workflow.commitContext
8180
val includedChanges = commitWorkflowHandler.ui.getIncludedChanges().toMutableList()
@@ -96,16 +95,16 @@ abstract class LLMClientService<C : LLMClientConfiguration>(private val cs: Coro
9695
}
9796

9897
val branch = getCommonBranch(includedChanges, project)
99-
val prompt = constructPrompt(project.service<ProjectSettings>().activePrompt.content, diff, branch, commitMessage.text, project)
98+
val prompt = constructPrompt(project.service<ProjectSettings>().activePrompt.content, diff, branch, commitWorkflowHandler.getCommitMessage(), project)
10099

101100
makeRequest(clientConfiguration, prompt, onSuccess = {
102101
withContext(Dispatchers.EDT) {
103-
clientConfiguration.setCommitMessage(commitMessage, prompt, it)
102+
clientConfiguration.setCommitMessage(commitWorkflowHandler, prompt, it)
104103
}
105104
AppSettings2.instance.recordHit()
106105
}, onError = {
107106
withContext(Dispatchers.EDT) {
108-
commitMessage.setCommitMessage(it)
107+
commitWorkflowHandler.setCommitMessage(it)
109108
}
110109
})
111110
}

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/anthropic/AnthropicClientConfiguration.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.github.blarc.ai.commits.intellij.plugin.Icons
44
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
55
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientSharedState
66
import com.intellij.openapi.project.Project
7-
import com.intellij.openapi.vcs.ui.CommitMessage
87
import com.intellij.util.xmlb.annotations.Attribute
98
import com.intellij.util.xmlb.annotations.Transient
109
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
@@ -50,8 +49,8 @@ class AnthropicClientConfiguration : LLMClientConfiguration(
5049
return AnthropicClientSharedState.getInstance()
5150
}
5251

53-
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
54-
return AnthropicClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, commitMessage, project)
52+
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
53+
return AnthropicClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, project)
5554
}
5655

5756
override fun getGenerateCommitMessageJob(): Job? {

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/azureOpenAi/AzureOpenAiClientConfiguration.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.github.blarc.ai.commits.intellij.plugin.Icons
44
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
55
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientSharedState
66
import com.intellij.openapi.project.Project
7-
import com.intellij.openapi.vcs.ui.CommitMessage
87
import com.intellij.util.xmlb.annotations.Attribute
98
import com.intellij.util.xmlb.annotations.Transient
109
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
@@ -44,8 +43,8 @@ class AzureOpenAiClientConfiguration : LLMClientConfiguration(
4443
return AzureOpenAiClientSharedState.getInstance()
4544
}
4645

47-
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
48-
return AzureOpenAiClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, commitMessage, project)
46+
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
47+
return AzureOpenAiClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, project)
4948
}
5049

5150
override fun getGenerateCommitMessageJob(): Job? {

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/geminiGoogle/GeminiGoogleClientConfiguration.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.github.blarc.ai.commits.intellij.plugin.Icons
55
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
66
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientSharedState
77
import com.intellij.openapi.project.Project
8-
import com.intellij.openapi.vcs.ui.CommitMessage
98
import com.intellij.util.xmlb.annotations.Attribute
109
import com.intellij.util.xmlb.annotations.Transient
1110
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
@@ -40,8 +39,8 @@ class GeminiGoogleClientConfiguration : LLMClientConfiguration(
4039
return GeminiGoogleClientSharedState.getInstance()
4140
}
4241

43-
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
44-
return GeminiGoogleClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, commitMessage, project)
42+
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
43+
return GeminiGoogleClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, project)
4544
}
4645

4746
override fun getGenerateCommitMessageJob(): Job? {

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/geminiVertex/GeminiClientConfiguration.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.github.blarc.ai.commits.intellij.plugin.Icons
44
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
55
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientSharedState
66
import com.intellij.openapi.project.Project
7-
import com.intellij.openapi.vcs.ui.CommitMessage
87
import com.intellij.util.xmlb.annotations.Attribute
98
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
109
import kotlinx.coroutines.Job
@@ -42,8 +41,8 @@ class GeminiClientConfiguration : LLMClientConfiguration(
4241
return GeminiVertexClientSharedState.getInstance()
4342
}
4443

45-
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
46-
return GeminiVertexClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, commitMessage, project)
44+
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
45+
return GeminiVertexClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, project)
4746
}
4847

4948
override fun getGenerateCommitMessageJob(): Job? {

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/githubModels/GitHubModelsClientConfiguration.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.github.blarc.ai.commits.intellij.plugin.Icons
44
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
55
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientSharedState
66
import com.intellij.openapi.project.Project
7-
import com.intellij.openapi.vcs.ui.CommitMessage
87
import com.intellij.util.xmlb.annotations.Attribute
98
import com.intellij.util.xmlb.annotations.Transient
109
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
@@ -40,8 +39,8 @@ class GitHubModelsClientConfiguration : LLMClientConfiguration(
4039
return GitHubModelsClientSharedState.getInstance()
4140
}
4241

43-
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
44-
return GitHubModelsClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, commitMessage, project)
42+
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
43+
return GitHubModelsClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, project)
4544
}
4645

4746
override fun getGenerateCommitMessageJob(): Job? {

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/huggingface/HuggingFaceClientConfiguration.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.github.blarc.ai.commits.intellij.plugin.Icons
44
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientConfiguration
55
import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientSharedState
66
import com.intellij.openapi.project.Project
7-
import com.intellij.openapi.vcs.ui.CommitMessage
87
import com.intellij.util.xmlb.annotations.Attribute
98
import com.intellij.util.xmlb.annotations.Transient
109
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
@@ -47,17 +46,17 @@ class HuggingFaceClientConfiguration : LLMClientConfiguration(
4746
return HuggingFaceClientSharedState.getInstance()
4847
}
4948

50-
override fun setCommitMessage(commitMessage: CommitMessage, prompt: String, result: String) {
49+
override fun setCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, prompt: String, result: String) {
5150
var newResult = result
5251
if (removePrompt) {
5352
// https://github.com/Blarc/ai-commits-intellij-plugin/issues/294
5453
newResult = result.substring(prompt.length+1)
5554
}
56-
super.setCommitMessage(commitMessage, prompt, newResult)
55+
super.setCommitMessage(commitWorkflowHandler, prompt, newResult)
5756
}
5857

59-
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, commitMessage: CommitMessage, project: Project) {
60-
return HuggingFaceClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, commitMessage, project)
58+
override fun generateCommitMessage(commitWorkflowHandler: AbstractCommitWorkflowHandler<*, *>, project: Project) {
59+
return HuggingFaceClientService.getInstance().generateCommitMessage(this, commitWorkflowHandler, project)
6160
}
6261

6362
override fun getGenerateCommitMessageJob(): Job? {

0 commit comments

Comments
 (0)