Skip to content

Commit

Permalink
feat(vcs): add support for Diff variable in VcsToolchainVariable
Browse files Browse the repository at this point in the history
This commit introduces the Diff variable to the VcsToolchainVariable, enabling the retrieval of the current changes' diff. The implementation includes necessary imports and a new method to analyze the log data for the diff content.
  • Loading branch information
phodal committed Nov 24, 2024
1 parent d34a8da commit d448e33
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum class VcsToolchainVariable(
CurrentBranch("currentBranch", description = "The name of the current branch"),

HistoryCommitMessages("historyCommitMessages", description = "The commit messages in the history"),

Diff("diff", description = "The diff of the current changes")
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.phodal.shire.git.provider

import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.VcsDataKeys
import com.intellij.openapi.vcs.changes.Change
import com.intellij.openapi.vcs.changes.CurrentContentRevision
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import com.intellij.vcs.commit.CommitWorkflowUi
import com.intellij.vcs.log.VcsFullCommitDetails
import com.intellij.vcs.log.VcsLogDataKeys
import com.intellij.vcs.log.VcsLogFilterCollection
import com.intellij.vcs.log.VcsLogProvider
import com.intellij.vcs.log.impl.VcsProjectLog
Expand All @@ -16,6 +22,7 @@ import com.phodal.shirecore.provider.variable.ToolchainVariableProvider
import com.phodal.shirecore.provider.variable.model.ToolchainVariable
import com.phodal.shirecore.provider.variable.model.toolchain.VcsToolchainVariable
import com.phodal.shire.git.VcsPrompting
import com.phodal.shirecore.variable.template.VariableActionEventDataHolder
import java.awt.EventQueue.invokeAndWait


Expand All @@ -27,6 +34,7 @@ class GitToolchainVariableProvider : ToolchainVariableProvider {
VcsToolchainVariable.CurrentChanges -> true
VcsToolchainVariable.HistoryCommitMessages -> true
VcsToolchainVariable.CurrentBranch -> true
VcsToolchainVariable.Diff -> true
else -> false
}
}
Expand Down Expand Up @@ -81,11 +89,34 @@ class GitToolchainVariableProvider : ToolchainVariableProvider {
variable.value = exampleCommitMessages
}
}

VcsToolchainVariable.Diff -> {
val dataContext = VariableActionEventDataHolder.getData()?.vcsDataContext
variable.value = analysisLog(dataContext, project)
}
}

return variable
}

private fun analysisLog(dataContext: DataContext?, project: Project): String {
if (dataContext == null) {
return ""
}


val vcsLog = dataContext.getData(VcsLogDataKeys.VCS_LOG) ?: return ""

val details: List<VcsFullCommitDetails> = vcsLog.selectedDetails.toList()
val selectList = dataContext.getData(VcsDataKeys.SELECTED_CHANGES).orEmpty().toList()

val vcsPrompting = project.service<VcsPrompting>()
val fullChangeContent =
vcsPrompting.buildDiffPrompt(details, selectList.toList(), project)

return fullChangeContent ?: ""
}

/**
* Finds example commit messages based on the project's VCS log, takes the first three commits.
* If the no user or user has committed anything yet, the current branch name is used instead.
Expand Down

0 comments on commit d448e33

Please sign in to comment.