From 8488faad02ab7430a77193cf12cf0fbcb5a85ea7 Mon Sep 17 00:00:00 2001 From: Andrew Charneski Date: Sat, 11 Nov 2023 14:24:54 -0500 Subject: [PATCH] wip --- .../actions/code/GenerateProjectAction.groovy | 2 -- .../aicoder/actions/FileContextAction.kt | 15 ++++++------ .../aicoder/actions/SelectionAction.kt | 24 +++++++++---------- .../aicoder/actions/dev/CodeChatAction.kt | 10 ++++---- .../aicoder/actions/dev/CodeChatServer.kt | 8 +++---- .../aicoder/actions/dev/ConvertFileTo.kt | 13 +++++----- .../aicoder/actions/dev/PrintTreeAction.kt | 5 ++-- .../actions/generic/DictationAction.kt | 11 ++++----- .../aicoder/actions/generic/RedoLast.kt | 5 ++-- .../actions/markdown/MarkdownListAction.kt | 14 +++++------ .../aicoder/config/ActionSettingsRegistry.kt | 8 +++---- .../aicoder/config/ActionTable.kt | 2 +- .../aicoder/ui/ModelSelectionWidgetFactory.kt | 6 ++--- .../ui/TemperatureControlWidgetFactory.kt | 6 ++--- .../aicoder/ui/TokenCountWidgetFactory.kt | 6 ++--- .../aicoder/util/ComputerLanguage.kt | 1 + .../aicoder/util/IdeaOpenAIClient.kt | 5 ++-- .../simiacryptus/aicoder/util/LineComment.kt | 8 +++---- .../simiacryptus/aicoder/util/psi/PsiUtil.kt | 12 ++++------ .../actions/code/GenerateProjectAction.groovy | 14 +++++------ .../aicoder/ApplicationDevelopmentUITest.kt | 3 +-- .../github/simiacryptus/aicoder/UITestUtil.kt | 3 +-- 22 files changed, 80 insertions(+), 101 deletions(-) diff --git a/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy b/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy index 9b0eb479..49c7835f 100644 --- a/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy +++ b/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy @@ -22,8 +22,6 @@ import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream class GenerateProjectAction extends FileContextAction { - static Logger log = LoggerFactory.getLogger(GenerateProjectAction.class) - GenerateProjectAction() { super(false, true) diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/FileContextAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/FileContextAction.kt index 1673f036..6e55cd88 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/FileContextAction.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/FileContextAction.kt @@ -7,7 +7,6 @@ import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile -import com.simiacryptus.openai.APIClientBase import java.io.File abstract class FileContextAction( @@ -22,15 +21,15 @@ abstract class FileContextAction( abstract fun processSelection(state: SelectionState, config: T?): Array - final override fun handle(event: AnActionEvent) { - val config = getConfig(event.project) - val virtualFile = UITools.getSelectedFile(event) ?: UITools.getSelectedFolder(event) ?: return - val project = event.project ?: return + final override fun handle(e: AnActionEvent) { + val config = getConfig(e.project) + val virtualFile = UITools.getSelectedFile(e) ?: UITools.getSelectedFolder(e) ?: return + val project = e.project ?: return val projectRoot = File(project.basePath!!).toPath() Thread { try { - UITools.redoableTask(event) { - UITools.run(event.project, templateText!!, true) { + UITools.redoableTask(e) { + UITools.run(e.project, templateText!!, true) { val newFiles = try { processSelection( SelectionState( @@ -41,7 +40,7 @@ abstract class FileContextAction( } finally { if (it.isCanceled) throw InterruptedException() } - UITools.writeableFn(event) { + UITools.writeableFn(e) { val files = newFiles.map { file -> val localFileSystem = LocalFileSystem.getInstance() localFileSystem.findFileByIoFile(file.parentFile)?.refresh(false, true) diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/SelectionAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/SelectionAction.kt index c687dc72..9f5d721f 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/SelectionAction.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/SelectionAction.kt @@ -42,10 +42,10 @@ abstract class SelectionAction( } } - final override fun handle(event: AnActionEvent) { - val editor = event.getData(CommonDataKeys.EDITOR) ?: return - val config = getConfig(event.project) - val indent = UITools.getIndent(event) + final override fun handle(e: AnActionEvent) { + val editor = e.getData(CommonDataKeys.EDITOR) ?: return + val config = getConfig(e.project) + val indent = UITools.getIndent(e) val caretModel = editor.caretModel val primaryCaret = caretModel.primaryCaret var selectionStart = primaryCaret.selectionStart @@ -57,36 +57,36 @@ abstract class SelectionAction( selectionEnd = end selectionStart = start - UITools.redoableTask(event) { - val document = event.getData(CommonDataKeys.EDITOR)?.document + UITools.redoableTask(e) { + val document = e.getData(CommonDataKeys.EDITOR)?.document var rangeMarker: RangeMarker? = null - WriteCommandAction.runWriteCommandAction(event.project) { + WriteCommandAction.runWriteCommandAction(e.project) { rangeMarker = document?.createGuardedBlock(selectionStart, selectionEnd) } val newText = try { processSelection( - event = event, + event = e, SelectionState( selectedText = selectedText, selectionOffset = selectionStart, selectionLength = selectionEnd - selectionStart, entireDocument = editor.document.text, - language = ComputerLanguage.getComputerLanguage(event), + language = ComputerLanguage.getComputerLanguage(e), indent = indent, contextRanges = editorState.contextRanges, psiFile = editorState.psiFile, - project = event.project + project = e.project ), config = config ) } finally { if(null != rangeMarker) - WriteCommandAction.runWriteCommandAction(event.project) { + WriteCommandAction.runWriteCommandAction(e.project) { document?.removeGuardedBlock(rangeMarker!!) } } - UITools.writeableFn(event) { + UITools.writeableFn(e) { UITools.replaceString(editor.document, selectionStart, selectionEnd, newText) } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatAction.kt index 850e907e..e3305e48 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatAction.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatAction.kt @@ -13,15 +13,15 @@ import java.util.* class CodeChatAction : BaseAction() { - override fun handle(event: AnActionEvent) { - val editor = event.getData(CommonDataKeys.EDITOR) ?: return + override fun handle(e: AnActionEvent) { + val editor = e.getData(CommonDataKeys.EDITOR) ?: return val caretModel = editor.caretModel val primaryCaret = caretModel.primaryCaret val selectedText = primaryCaret.selectedText ?: editor.document.text - val language = ComputerLanguage.getComputerLanguage(event)?.name ?: return - val server = AppServer.getServer(event.project) + val language = ComputerLanguage.getComputerLanguage(e)?.name ?: return + val server = AppServer.getServer(e.project) val uuid = UUID.randomUUID().toString() - server.addApp("/$uuid", CodeChatServer(event.project!!, language, selectedText)) + server.addApp("/$uuid", CodeChatServer(e.project!!, language, selectedText)) Thread { Thread.sleep(500) try { diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt index 70d6a7b4..bc21ded3 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt @@ -10,7 +10,7 @@ class CodeChatServer( val project: Project, val language: String, val codeSelection: String, -) : SkyenetBasicChat( +) : BasicChat( applicationName = "Code Chat", model = AppSettingsState.instance.defaultChatModel() ) { @@ -38,10 +38,10 @@ rootMessageTrail = sessionId = sessionId ) { override fun run(userMessage: String) { - var messageTrail = ChatSession.divInitializer() - send("""$messageTrail
$userMessage
${SkyenetSessionServerBase.spinner}
""") + var messageTrail = divInitializer() + send("""$messageTrail
$userMessage
$spinner
""") messages += OpenAIClient.ChatMessage(OpenAIClient.ChatMessage.Role.user, userMessage) - val response = api.chat(chatRequest, model).choices.first()?.message?.content.orEmpty() + val response = api.chat(chatRequest, model).choices.first().message?.content.orEmpty() messages += OpenAIClient.ChatMessage(OpenAIClient.ChatMessage.Role.assistant, response) messageTrail += MarkdownUtil.renderMarkdown(response) send(messageTrail) diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/ConvertFileTo.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/ConvertFileTo.kt index 224b3d99..ac41b1d4 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/ConvertFileTo.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/ConvertFileTo.kt @@ -10,7 +10,6 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.command.WriteCommandAction -import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import java.io.IOException @@ -80,12 +79,12 @@ class ConvertFileTo : ActionGroup() { class ConvertFileToLanguage(private val targetLanguage: ComputerLanguage) : BaseAction( targetLanguage.name ) { - override fun handle(event: AnActionEvent) { - val sourceLanguage = ComputerLanguage.getComputerLanguage(event) - val indent = UITools.getIndent(event.getData(CommonDataKeys.CARET)) - val virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE) ?: return - val psiFile = event.getData(CommonDataKeys.PSI_FILE) ?: return - val project = event.project!! + override fun handle(e: AnActionEvent) { + val sourceLanguage = ComputerLanguage.getComputerLanguage(e) + val indent = UITools.getIndent(e.getData(CommonDataKeys.CARET)) + val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return + val psiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return + val project = e.project!! Thread { UITools.run(project, "Converting to " + targetLanguage.name) { try { diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/PrintTreeAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/PrintTreeAction.kt index 82ffc921..e9b42bc4 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/PrintTreeAction.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/PrintTreeAction.kt @@ -6,7 +6,6 @@ import com.github.simiacryptus.aicoder.util.UITools import com.github.simiacryptus.aicoder.util.psi.PsiUtil import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.diagnostic.Logger -import com.simiacryptus.openai.APIClientBase /** * The PrintTreeAction class is an IntelliJ action that enables developers to print the tree structure of a PsiFile. @@ -18,8 +17,8 @@ import com.simiacryptus.openai.APIClientBase class PrintTreeAction : BaseAction() { - override fun handle(e1: AnActionEvent) { - log.warn(PsiUtil.printTree(PsiUtil.getLargestContainedEntity(e1)!!)) + override fun handle(e: AnActionEvent) { + log.warn(PsiUtil.printTree(PsiUtil.getLargestContainedEntity(e)!!)) } override fun isEnabled(event: AnActionEvent): Boolean { diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/DictationAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/DictationAction.kt index 8c3f779d..d083d1aa 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/DictationAction.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/DictationAction.kt @@ -7,7 +7,6 @@ import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.diagnostic.Logger -import com.simiacryptus.openai.APIClientBase import com.simiacryptus.util.audio.AudioRecorder import com.simiacryptus.util.audio.LookbackLoudnessWindowBuffer import java.util.* @@ -22,8 +21,8 @@ import javax.swing.JFrame import javax.swing.JLabel class DictationAction : BaseAction() { - override fun handle(event: AnActionEvent) { - val continueFn = statusDialog(event)::isVisible + override fun handle(e: AnActionEvent) { + val continueFn = statusDialog(e)::isVisible val rawBuffer = ConcurrentLinkedDeque() Thread({ @@ -47,12 +46,12 @@ class DictationAction : BaseAction() { log.warn("Audio processing thread complete") }, "dictation-audio-processor").start() - val caretModel = (event.getData(CommonDataKeys.EDITOR) ?: return).caretModel + val caretModel = (e.getData(CommonDataKeys.EDITOR) ?: return).caretModel val primaryCaret = caretModel.primaryCaret val dictationPump = if (primaryCaret.hasSelection()) { - DictationPump(event, wavBuffer, continueFn, primaryCaret.selectionEnd, primaryCaret.selectedText ?: "") + DictationPump(e, wavBuffer, continueFn, primaryCaret.selectionEnd, primaryCaret.selectedText ?: "") } else { - DictationPump(event, wavBuffer, continueFn, caretModel.offset) + DictationPump(e, wavBuffer, continueFn, caretModel.offset) } Thread({ log.warn("Speech-To-Text thread started") diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/RedoLast.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/RedoLast.kt index 83a8f953..28109846 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/RedoLast.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/RedoLast.kt @@ -5,7 +5,6 @@ import com.github.simiacryptus.aicoder.util.UITools import com.github.simiacryptus.aicoder.util.UITools.retry import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import com.simiacryptus.openai.APIClientBase /** * The RedoLast action is an IntelliJ action that allows users to redo the last AI Coder action they performed in the editor. @@ -18,9 +17,9 @@ class RedoLast : BaseAction() { retry[e.getRequiredData(CommonDataKeys.EDITOR).document]!!.run() } - override fun isEnabled(e: AnActionEvent): Boolean { + override fun isEnabled(event: AnActionEvent): Boolean { if (UITools.isSanctioned()) return false - return null != retry[e.getRequiredData(CommonDataKeys.EDITOR).document] + return null != retry[event.getRequiredData(CommonDataKeys.EDITOR).document] } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/markdown/MarkdownListAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/markdown/MarkdownListAction.kt index 19995565..47ed45e1 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/markdown/MarkdownListAction.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/markdown/MarkdownListAction.kt @@ -48,9 +48,9 @@ class MarkdownListAction : BaseAction() { return chatProxy.create() } - override fun handle(event: AnActionEvent) { - val caret = event.getData(CommonDataKeys.CARET) ?: return - val psiFile = event.getData(CommonDataKeys.PSI_FILE) ?: return + override fun handle(e: AnActionEvent) { + val caret = e.getData(CommonDataKeys.CARET) ?: return + val psiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return val list = getSmallestIntersecting(psiFile, caret.selectionStart, caret.selectionEnd, "MarkdownListImpl") ?: return val items = StringUtil.trim( @@ -63,17 +63,17 @@ class MarkdownListAction : BaseAction() { val indent = getIndent(caret) val endOffset = list.textRange.endOffset val bulletTypes = listOf("- [ ] ", "- ", "* ") - val document = (event.getData(CommonDataKeys.EDITOR) ?: return).document + val document = (e.getData(CommonDataKeys.EDITOR) ?: return).document val rawItems = items.map(CharSequence::trim).map { val bulletType = bulletTypes.find(it::startsWith) if (null != bulletType) StringUtil.stripPrefix(it, bulletType).toString() else it.toString() } - UITools.redoableTask(event) { + UITools.redoableTask(e) { var newItems: List? = null UITools.run( - event.project, "Generating New Items", true + e.project, "Generating New Items", true ) { newItems = proxy.newListItems( rawItems, @@ -88,7 +88,7 @@ class MarkdownListAction : BaseAction() { val bulletString = bulletTypes.find(strippedList::startsWith) ?: "1. " newList = newItems?.joinToString("\n") { indent.toString() + bulletString + it } ?: "" } - UITools.writeableFn(event) { + UITools.writeableFn(e) { insertString(document, endOffset, "\n" + newList) } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionSettingsRegistry.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionSettingsRegistry.kt index 7645875a..61d8b0c9 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionSettingsRegistry.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionSettingsRegistry.kt @@ -52,10 +52,8 @@ class ActionSettingsRegistry { val localCode = actionConfig.file.readText() if (localCode != code) { val element = actionConfig.buildAction(localCode) - if(null != element) { - children.remove(it) - children.add(element) - } + children.remove(it) + children.add(element) } } actionConfig.version = version @@ -69,7 +67,7 @@ class ActionSettingsRegistry { if (!it.file.exists()) return@forEach if (!it.enabled) return@forEach val element = it.buildAction(it.file.readText()) - if(null != element) children.add(element) + children.add(element) } catch (e: Throwable) { UITools.error(log, "Error loading dynamic action", e) } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionTable.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionTable.kt index d566ab65..3e297204 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionTable.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/config/ActionTable.kt @@ -189,7 +189,7 @@ class ActionTable( return } rowData.removeIf { - it[2] == selectedSettings?.id + it[2] == selectedSettings.id } this@ActionTable.parent.invalidate() } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt index 0410b865..f540f009 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt @@ -103,12 +103,10 @@ class ModelSelectionWidgetFactory : StatusBarWidgetFactory { } override fun isAvailable(project: Project): Boolean { - if (UITools.isSanctioned()) return false - return true + return !UITools.isSanctioned() } override fun canBeEnabledOn(statusBar: StatusBar): Boolean { - if (UITools.isSanctioned()) return false - return true + return !UITools.isSanctioned() } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt index db74bf5f..4c3df59c 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt @@ -148,12 +148,10 @@ class TemperatureControlWidgetFactory : StatusBarWidgetFactory { } override fun isAvailable(project: Project): Boolean { - if (UITools.isSanctioned()) return false - return true + return !UITools.isSanctioned() } override fun canBeEnabledOn(statusBar: StatusBar): Boolean { - if (UITools.isSanctioned()) return false - return true + return !UITools.isSanctioned() } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt index 1c76a9e8..dc251085 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt @@ -125,12 +125,10 @@ class TokenCountWidgetFactory : StatusBarWidgetFactory { } override fun isAvailable(project: Project): Boolean { - if (UITools.isSanctioned()) return false - return true + return !UITools.isSanctioned() } override fun canBeEnabledOn(statusBar: StatusBar): Boolean { - if (UITools.isSanctioned()) return false - return true + return !UITools.isSanctioned() } } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/util/ComputerLanguage.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/util/ComputerLanguage.kt index 11ff8652..286e8caa 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/util/ComputerLanguage.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/util/ComputerLanguage.kt @@ -427,6 +427,7 @@ enum class ComputerLanguage(configuration: Configuration) { } fun setFileExtensions(vararg fileExtensions: CharSequence): Configuration { + @Suppress("UNCHECKED_CAST") this.fileExtensions = fileExtensions as Array return this } diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/util/IdeaOpenAIClient.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/util/IdeaOpenAIClient.kt index c9ce89b2..bbd81917 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/util/IdeaOpenAIClient.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/util/IdeaOpenAIClient.kt @@ -105,12 +105,11 @@ class IdeaOpenAIClient : OpenAIClient( } else { try { if (!AppSettingsState.instance.editRequests) return super.edit(editRequest) - return withJsonDialog(editRequest, { - val editRequest = it + return withJsonDialog(editRequest, { request -> UITools.run( lastEvent!!.project, "OpenAI Request", true, suppressProgress = false ) { - super.edit(editRequest) + super.edit(request) } }, "Edit Edit Request") } finally { diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/util/LineComment.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/util/LineComment.kt index c4e3346c..fdbaa598 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/util/LineComment.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/util/LineComment.kt @@ -10,14 +10,14 @@ class LineComment(private val commentPrefix: CharSequence, indent: CharSequence? IndentedText(indent!!, *lines) { class Factory(private val commentPrefix: String) : TextBlockFactory { override fun fromString(text: String?): LineComment { - var text = text - text = text!!.replace(Regex("\t"), TextBlock.TAB_REPLACEMENT.toString()) - val indent = getWhitespacePrefix(*text.split(TextBlock.DELIMITER.toRegex()).dropLastWhile { it.isEmpty() } + var textVar = text + textVar = textVar!!.replace(Regex("\t"), TextBlock.TAB_REPLACEMENT.toString()) + val indent = getWhitespacePrefix(*textVar.split(TextBlock.DELIMITER.toRegex()).dropLastWhile { it.isEmpty() } .toTypedArray()) return LineComment( commentPrefix, indent, - *Arrays.stream(text.split(TextBlock.DELIMITER.toRegex()).dropLastWhile { it.isEmpty() } + *Arrays.stream(textVar.split(TextBlock.DELIMITER.toRegex()).dropLastWhile { it.isEmpty() } .toTypedArray()) .map { s: String? -> stripPrefix( diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiUtil.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiUtil.kt index 9bbccff9..ba5a4495 100644 --- a/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiUtil.kt +++ b/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiUtil.kt @@ -2,11 +2,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.editor.Caret import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.PsiElementVisitor -import com.intellij.psi.PsiFile import com.simiacryptus.util.StringUtil import java.util.* import java.util.concurrent.atomic.AtomicReference @@ -152,13 +150,13 @@ object PsiUtil { } private fun getName(elementClass: Class<*>): String { - var elementClass = elementClass + var elementClassVar = elementClass val stringBuilder = StringBuilder() - val interfaces = getInterfaces(elementClass) - while (elementClass != Any::class.java) { + val interfaces = getInterfaces(elementClassVar) + while (elementClassVar != Any::class.java) { if (stringBuilder.isNotEmpty()) stringBuilder.append("/") - stringBuilder.append(elementClass.simpleName) - elementClass = elementClass.superclass + stringBuilder.append(elementClassVar.simpleName) + elementClassVar = elementClassVar.superclass } stringBuilder.append("[ ") stringBuilder.append(interfaces.stream().sorted().collect(Collectors.joining(","))) diff --git a/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy b/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy index 27e8ea4c..49c7835f 100644 --- a/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy +++ b/src/main/resources/sources/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy @@ -22,8 +22,6 @@ import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream class GenerateProjectAction extends FileContextAction { - static Logger logger = LoggerFactory.getLogger(GenerateProjectAction.class) - GenerateProjectAction() { super(false, true) @@ -326,7 +324,7 @@ class GenerateProjectAction extends FileContextAction { ) // def progressVal = currentDraft.incrementAndGet().toDouble() / totalDrafts // progress(progressVal) -// logger.info("Progress: $progressVal") +// log.info("Progress: $progressVal") return new Pair(file.location, implement) } }) @@ -371,7 +369,7 @@ class GenerateProjectAction extends FileContextAction { ) // def progressVal = currentDraft.incrementAndGet().toDouble() / totalDrafts // progress(progressVal) -// logger.info("Progress: $progressVal") +// log.info("Progress: $progressVal") return new Pair(file.location, implement) } }) @@ -418,7 +416,7 @@ class GenerateProjectAction extends FileContextAction { ) // def progressVal = currentDraft.incrementAndGet().toDouble() / totalDrafts // progress(progressVal) -// logger.info("Progress: $progressVal") +// log.info("Progress: $progressVal") return new Pair(file.location, implement) } }) @@ -522,20 +520,20 @@ class GenerateProjectAction extends FileContextAction { entries.each { file, sourceCode -> def relative = trimStart(trimEnd(file.file, '/'), ['/', '.']) ?: "" if (new File(relative).isAbsolute()) { - logger.warn("Invalid path: $relative") + log.warn("Invalid path: $relative") } else { def outFile = new File(outputDir, relative) outFile.parentFile.mkdirs() def best = sourceCode.max { it.code.length() } outFile.text = best.code - logger.debug("Wrote ${outFile.canonicalPath} (Resolved from $relative)") + log.debug("Wrote ${outFile.canonicalPath} (Resolved from $relative)") generatedFiles << outFile if (config.saveAlternates) sourceCode.findAll { it != best }.eachWithIndex { alternate, index -> def outFileAlternate = new File(outputDir, relative + ".${index + 1}") outFileAlternate.parentFile.mkdirs() outFileAlternate.text = alternate.code - logger.debug("Wrote ${outFileAlternate.canonicalPath} (Resolved from $relative)") + log.debug("Wrote ${outFileAlternate.canonicalPath} (Resolved from $relative)") generatedFiles << outFileAlternate } } diff --git a/src/test/kotlin/com/github/simiacryptus/aicoder/ApplicationDevelopmentUITest.kt b/src/test/kotlin/com/github/simiacryptus/aicoder/ApplicationDevelopmentUITest.kt index 0a5f7d86..17d7597b 100644 --- a/src/test/kotlin/com/github/simiacryptus/aicoder/ApplicationDevelopmentUITest.kt +++ b/src/test/kotlin/com/github/simiacryptus/aicoder/ApplicationDevelopmentUITest.kt @@ -109,8 +109,7 @@ class ApplicationDevelopmentUITest { ) { val reportPrefix = "${name}_${language}_" val testOutputFile = File(outputDir, "${name}_${language}.md") - val out = PrintWriter(FileOutputStream(testOutputFile)) - out.use { out -> + PrintWriter(FileOutputStream(testOutputFile)).use { out -> out.println( """ diff --git a/src/test/kotlin/com/github/simiacryptus/aicoder/UITestUtil.kt b/src/test/kotlin/com/github/simiacryptus/aicoder/UITestUtil.kt index 7aea2af6..faf79460 100644 --- a/src/test/kotlin/com/github/simiacryptus/aicoder/UITestUtil.kt +++ b/src/test/kotlin/com/github/simiacryptus/aicoder/UITestUtil.kt @@ -217,8 +217,7 @@ class UITestUtil { if (progressPanel.isEmpty()) return false val componentFixture = progressPanel.get(0) val labels = componentFixture.data.getAll() - if (labels.size == 0) return false - return true + return labels.size != 0 } fun documentJavaImplementation(