Skip to content

Commit 36517ee

Browse files
committed
feat(prompts): simplify change retrieval for prompt preview with ChangeListManager
Replaced custom Git handling logic with ChangeListManager to streamline change retrieval. This reduces complexity and reliance on Git-specific operations, improving maintainability and clarity.
1 parent 2f03a16 commit 36517ee

File tree

1 file changed

+2
-27
lines changed
  • src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/prompts

1 file changed

+2
-27
lines changed

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/prompts/PromptTable.kt

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import com.github.blarc.ai.commits.intellij.plugin.createColumn
99
import com.github.blarc.ai.commits.intellij.plugin.notBlank
1010
import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings2
1111
import com.github.blarc.ai.commits.intellij.plugin.unique
12-
import com.intellij.dvcs.repo.VcsRepositoryManager
1312
import com.intellij.ide.DataManager
1413
import com.intellij.openapi.actionSystem.CommonDataKeys
1514
import com.intellij.openapi.application.EDT
1615
import com.intellij.openapi.application.ModalityState
1716
import com.intellij.openapi.application.asContextElement
18-
import com.intellij.openapi.diagnostic.Logger
1917
import com.intellij.openapi.project.Project
2018
import com.intellij.openapi.ui.DialogWrapper
19+
import com.intellij.openapi.vcs.changes.ChangeListManager
2120
import com.intellij.ui.components.JBTextArea
2221
import com.intellij.ui.components.JBTextField
2322
import com.intellij.ui.dsl.builder.Align
@@ -26,7 +25,6 @@ import com.intellij.ui.dsl.builder.panel
2625
import com.intellij.ui.dsl.builder.text
2726
import com.intellij.ui.table.TableView
2827
import com.intellij.util.ui.ListTableModel
29-
import git4idea.branch.GitBranchWorker
3028
import kotlinx.coroutines.CoroutineScope
3129
import kotlinx.coroutines.Dispatchers
3230
import kotlinx.coroutines.launch
@@ -122,7 +120,6 @@ class PromptTable(private val cs: CoroutineScope) {
122120
var branch: String? = null
123121
lateinit var diff: String
124122
lateinit var project: Project
125-
private val logger = Logger.getInstance(PromptDialog::class.java)
126123

127124
init {
128125
setSize(AppSettings2.instance.promptDialogWidth, AppSettings2.instance.promptDialogHeight)
@@ -210,29 +207,7 @@ class PromptTable(private val cs: CoroutineScope) {
210207
}
211208

212209
private fun getChangesAndSetPreview(project: Project) = cs.launch(Dispatchers.IO + ModalityState.stateForComponent(rootPane).asContextElement()) {
213-
val repositories = VcsRepositoryManager.getInstance(project).repositories
214-
if (repositories.isEmpty()) {
215-
logger.warn("No Git repositories found in the project.")
216-
return@launch
217-
}
218-
219-
val changes = repositories.asSequence()
220-
.filter { it.currentBranchName != null }
221-
.flatMap { repository ->
222-
val branchName = repository.currentBranchName!!
223-
try {
224-
GitBranchWorker.loadTotalDiff(repository, branchName).asSequence()
225-
} catch (e: Exception) {
226-
logger.error("Failed to load diff for branch '$branchName' in repository: ${repository.presentableUrl}", e)
227-
emptySequence()
228-
}
229-
}
230-
.toList()
231-
232-
if (changes.isEmpty()) {
233-
logger.warn("No changes found for the current branch.")
234-
}
235-
210+
val changes = ChangeListManager.getInstance(project).allChanges.toList()
236211
branch = getCommonBranch(changes, project)
237212
diff = computeDiff(changes, true, project)
238213

0 commit comments

Comments
 (0)