generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/cc/unitmesh/devti/actions/vcs/CodeReviewAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cc.unitmesh.devti.actions.vcs | ||
|
||
import cc.unitmesh.devti.actions.chat.base.ChatBaseAction | ||
import cc.unitmesh.devti.gui.chat.ChatActionType | ||
import cc.unitmesh.devti.gui.chat.ChatContext | ||
import cc.unitmesh.devti.gui.sendToChatPanel | ||
import cc.unitmesh.devti.prompting.VcsPrompting | ||
import cc.unitmesh.devti.provider.ContextPrompter | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder | ||
import com.intellij.openapi.util.io.FileUtilRt | ||
import com.intellij.openapi.vcs.VcsDataKeys | ||
import com.intellij.openapi.vcs.changes.Change | ||
import com.intellij.openapi.vcs.changes.ContentRevision | ||
import com.intellij.openapi.vcs.changes.CurrentContentRevision | ||
import com.intellij.vcs.log.VcsLogDataKeys | ||
import org.jetbrains.annotations.NotNull | ||
|
||
class CodeReviewAction : ChatBaseAction() { | ||
override fun getActionType(): ChatActionType = ChatActionType.CODE_REVIEW | ||
|
||
companion object { | ||
val log = logger<CodeReviewAction>() | ||
} | ||
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.project ?: return | ||
|
||
// Make changes available for diff action | ||
val vcsLog = e.getData(VcsLogDataKeys.VCS_LOG) | ||
val details = vcsLog?.let { log -> | ||
log.selectedDetails | ||
}?.toList() ?: return | ||
|
||
val vcsPrompting = project.service<VcsPrompting>() | ||
val diff = vcsPrompting.calculateDiff(details, project) | ||
|
||
var prompt = """You are a seasoned software developer, and I'm seeking your expertise to review the following code: | ||
| | ||
|- Please provide an overview of the business objectives and the context behind this commit. This will ensure that the code aligns with the project's requirements and goals. | ||
|- Focus on critical algorithms, logical flow, and design decisions within the code. Discuss how these changes impact the core functionality and the overall structure of the code. | ||
|- Identify and highlight any potential issues or risks introduced by these code changes. This will help reviewers pay special attention to areas that may require improvement or further analysis. | ||
|- Emphasize the importance of compatibility and consistency with the existing codebase. Ensure that the code adheres to the established standards and practices for code uniformity and long-term maintainability. | ||
|- Lastly, provide a concise high-level summary that encapsulates the key aspects of this commit. This summary should enable reviewers to quickly grasp the major changes in this update. | ||
| | ||
|PS: Your insights and feedback are invaluable in ensuring the quality and reliability of this code. Thank you for your assistance. | ||
| | ||
""".trimMargin() | ||
|
||
prompt += diff.second | ||
|
||
log.info("prompt: $prompt") | ||
|
||
sendToChatPanel(project) { panel, service -> | ||
val chatContext = ChatContext(null, "", "") | ||
|
||
service.handlePromptAndResponse(panel, object : ContextPrompter() { | ||
override fun displayPrompt() = prompt | ||
override fun requestPrompt() = prompt | ||
}, chatContext) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters