Skip to content

Commit

Permalink
fix: remove unused parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 23, 2023
1 parent 12a81bb commit fb68b71
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
Expand Up @@ -25,6 +25,7 @@ class CodeCompleteAction(
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val psiElementFactory = project.let { JavaPsiFacade.getElementFactory(it) }
val code = method.text

val task = object : Task.Backgroundable(project, "Code completing", true) {
override fun run(indicator: ProgressIndicator) {
Expand All @@ -43,7 +44,7 @@ class CodeCompleteAction(
method.containingFile?.name?.replace(".java", "")
}

val newMethodCode = apiExecutor.codeCompleteFor(method.text, className!!).trimIndent()
val newMethodCode = apiExecutor.codeCompleteFor(code, className!!).trimIndent()

indicator.fraction = 0.8
indicator.text = "Start replacing method"
Expand Down
Expand Up @@ -13,14 +13,14 @@ import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.util.NlsSafe
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiMethod


class CodeSuggestionAction(methodName: @NlsSafe String, val method: PsiMethod) :
AnAction({ "Code Suggestion for $methodName" }, DevtiIcons.AI_COPILOT) {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val code = method.text

val task = object : Task.Backgroundable(project, "Code completing", true) {
override fun run(indicator: ProgressIndicator) {
Expand All @@ -32,13 +32,7 @@ class CodeSuggestionAction(methodName: @NlsSafe String, val method: PsiMethod) :
indicator.fraction = 0.5
indicator.text = "Call OpenAI API..."

val className = if (method.parent is PsiClass) {
(method.parent as PsiClass).name
} else {
method.containingFile?.name?.replace(".java", "")
}

val suggestion = apiExecutor.codeReviewFor(method.text, className!!).trimIndent()
val suggestion = apiExecutor.codeReviewFor(code).trimIndent()

indicator.fraction = 0.8
indicator.text = "Start replacing method"
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/actions/FindBugAction.kt
Expand Up @@ -20,6 +20,7 @@ class FindBugAction(methodName: @NlsSafe String, val method: PsiMethod) :
AnAction({ "Find bug for $methodName" }, DevtiIcons.AI_COPILOT) {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val code = method.text

val task = object : Task.Backgroundable(project, "Find bug", true) {
override fun run(indicator: ProgressIndicator) {
Expand All @@ -31,7 +32,7 @@ class FindBugAction(methodName: @NlsSafe String, val method: PsiMethod) :
indicator.fraction = 0.5
indicator.text = "Call OpenAI API..."

val suggestion = apiExecutor.findBug(method.text).trimIndent()
val suggestion = apiExecutor.findBug(code).trimIndent()

indicator.fraction = 0.8
indicator.text = "Start replacing method"
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/cc/unitmesh/devti/connector/CodeCopilot.kt
Expand Up @@ -2,8 +2,7 @@ package cc.unitmesh.devti.connector

interface CodeCopilot {
fun codeCompleteFor(text: String, className: String): String

fun autoComment(text: String): String
fun codeReviewFor(text: String, className: String): String
fun codeReviewFor(text: String): String
fun findBug(text: String): String
}
Expand Up @@ -15,7 +15,7 @@ class CustomConnector(val url: String, val key: String) : CodeCopilot {
return ""
}

override fun codeReviewFor(text: String, className: String): String {
override fun codeReviewFor(text: String): String {
return ""
}

Expand Down
Expand Up @@ -122,8 +122,8 @@ class OpenCodeCopilot : CodeCopilot, DevtiFlowAction {
}
}

override fun codeReviewFor(text: String, className: String): String {
val promptText = promptGenerator.codeReview(text, className)
override fun codeReviewFor(text: String): String {
val promptText = promptGenerator.codeReview(text)
logger.warn("codeReviewFor prompt text: $promptText")
return runBlocking {
val result = prompt(promptText)
Expand Down
Expand Up @@ -49,12 +49,11 @@ class PromptGenerator() {
.replace("{code}", methodCode)
}

fun codeReview(text: String, className: String): String {
fun codeReview(text: String): String {
val promptText: InputStream = this::class.java.classLoader.getResourceAsStream("prompts/openai/copilot/code_review.txt")!!
val promptTextString = promptText.bufferedReader().use { it.readText() }
return promptTextString
.replace("{code}", text)
.replace("{className}", className)
}

fun findBug(text: String): String {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/gui/SuggestionPopup.kt
Expand Up @@ -9,14 +9,16 @@ import javax.swing.JPanel

fun createSuggestionPopup(suggestion: String): JBPopup {
val myTextField = EditorTextField(suggestion)
myTextField.size = Dimension(640, 480)

val panel = JPanel(BorderLayout(0, 20))
panel.add(myTextField, BorderLayout.CENTER)

val builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField)


val popup = builder.createPopup()
popup.setMinimumSize(Dimension(320, 240))
popup.size = Dimension(640, 480)

return popup
}
2 changes: 1 addition & 1 deletion src/main/resources/prompts/openai/copilot/code_review.txt
@@ -1,4 +1,4 @@
请作为代码审查者,对 class {className} 中的代码变更提供反馈
请作为代码审查者,对下面的的代码变更提供反馈

要求:

Expand Down

0 comments on commit fb68b71

Please sign in to comment.