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
6 changed files
with
70 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,56 @@ | ||
package cc.unitmesh.devti.actions | ||
|
||
import cc.unitmesh.devti.DevtiIcons | ||
import cc.unitmesh.devti.connector.openai.OpenCodeCopilot | ||
import cc.unitmesh.devti.gui.createSuggestionPopup | ||
import cc.unitmesh.devti.runconfig.AutoCRUDState | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.diagnostic.logger | ||
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 FindBugAction(methodName: @NlsSafe String, method: PsiMethod) : AnAction({ "Find bug for $methodName" }, DevtiIcons.AI_COPILOT) { | ||
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 task = object : Task.Backgroundable(project, "Find bug", true) { | ||
override fun run(indicator: ProgressIndicator) { | ||
indicator.fraction = 0.2 | ||
indicator.text = "Preparing code complete prompt" | ||
|
||
val apiExecutor = OpenCodeCopilot() | ||
|
||
indicator.fraction = 0.5 | ||
indicator.text = "Call OpenAI API..." | ||
|
||
val suggestion = apiExecutor.findBug(method.text).trimIndent() | ||
|
||
indicator.fraction = 0.8 | ||
indicator.text = "Start replacing method" | ||
|
||
val popup = createSuggestionPopup(suggestion) | ||
ApplicationManager.getApplication().invokeLater() { | ||
popup.showCenteredInCurrentWindow(project) | ||
} | ||
|
||
indicator.fraction = 1.0 | ||
} | ||
} | ||
|
||
ApplicationManager.getApplication().invokeLater { | ||
ProgressManager.getInstance().run(task) | ||
} | ||
} | ||
|
||
companion object { | ||
private val log: Logger = logger<AutoCRUDState>() | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
请作为软件质量保证测试员, 分析下面的代码,找出其中是否有潜在的 bug,如果有,说明 bug 的原因,如何修正。 | ||
|
||
### | ||
{code} | ||
### |