From beab5074b29ebca16d8e71d1d0bb5a4f0384db7e Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 7 Oct 2024 17:58:52 -0700 Subject: [PATCH 1/2] jb: add actions to search --- .../actions/ContinuePluginActions.kt | 160 ++---------------- .../editor/ToggleInlineEditAction.kt | 27 --- .../src/main/resources/META-INF/plugin.xml | 61 +++---- extensions/vscode/package.json | 2 +- 4 files changed, 42 insertions(+), 208 deletions(-) delete mode 100644 extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToggleInlineEditAction.kt diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt index 791172388..6a2f38a7c 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt @@ -24,8 +24,8 @@ fun getPluginService(project: Project?): ContinuePluginService? { return null } return ServiceManager.getService( - project, - ContinuePluginService::class.java + project, + ContinuePluginService::class.java ) } @@ -42,7 +42,8 @@ class AcceptDiffAction : AnAction() { private fun acceptVerticalDiff(e: AnActionEvent) { val project = e.project ?: return - val editor = e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return + val editor = + e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return val diffStreamService = project.service() diffStreamService.accept(editor) } @@ -61,120 +62,14 @@ class RejectDiffAction : AnAction() { private fun rejectVerticalDiff(e: AnActionEvent) { val project = e.project ?: return - val editor = e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return + val editor = + e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return val diffStreamService = project.service() diffStreamService.reject(editor) } } - - class QuickInputDialogWrapper : DialogWrapper(true) { - private var panel: JPanel? = null - private var textArea: JTextArea? = null - init { - init() - title = "Continue Quick Input" - } - - override fun getPreferredFocusedComponent(): JComponent? { - return textArea - } - - override fun createCenterPanel(): JComponent? { - panel = JPanel(BorderLayout()) - textArea = JTextArea(3, 60) - textArea?.lineWrap = true - textArea?.wrapStyleWord = true - - // Add a DocumentListener to the JTextArea - textArea?.document?.addDocumentListener(object : DocumentListener { - override fun insertUpdate(e: DocumentEvent?) { - updateSize() - } - - override fun removeUpdate(e: DocumentEvent?) { - updateSize() - } - - override fun changedUpdate(e: DocumentEvent?) { - updateSize() - } - - private fun updateSize() { - val text = textArea?.text ?: "" - val lines = text.count { it == '\n' } + 1 - val metrics = textArea?.getFontMetrics(textArea?.font) - val lineHeight = metrics?.height ?: 0 - textArea?.preferredSize = Dimension(textArea?.width ?: 0, lines * lineHeight) - - // Revalidate the JPanel to reflect the changes - panel?.revalidate() - } - }) - - val scrollPane = JBScrollPane(textArea) - scrollPane.verticalScrollBarPolicy = JScrollPane.VERTICAL_SCROLLBAR_ALWAYS - panel?.add(scrollPane, BorderLayout.CENTER) - - return panel - } - - - fun showDialogAndGetText(): String? { - show() - return if (this.exitCode == OK_EXIT_CODE) { - textArea!!.text - } else { - null - } - } - } - - -class QuickTextEntryAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - val continuePluginService = getPluginService(e.project) ?: return - continuePluginService.ideProtocolClient?.sendHighlightedCode() - - // Create and show the dialog - val dialog = QuickInputDialogWrapper() - val text: String? = dialog.showDialogAndGetText() - - // Show the text entered by the user - if (text != null) { - val service = getPluginService(e.project) - service?.ideProtocolClient?.sendMainUserInput(text) - - val project = e.project - if (project != null) { - val toolWindowManager = ToolWindowManager.getInstance(project) - val toolWindow = toolWindowManager.getToolWindow("Continue") - - if (toolWindow != null) { - if (!toolWindow.isVisible) { - toolWindow.activate(null) - } - } - } - - continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus() - continuePluginService.sendToWebview("focusContinueInput", null) - - } - } -} - -class ViewLogsAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - Messages.showMessageDialog( - "This action is not yet implemented", - "Continue Action not Implemented", - Messages.getInformationIcon() - ) - } -} - -fun focusContinueInput(project: Project?) { +fun getContinuePluginService(project: Project?): ContinuePluginService? { if (project != null) { val toolWindowManager = ToolWindowManager.getInstance(project) val toolWindow = toolWindowManager.getToolWindow("Continue") @@ -186,7 +81,11 @@ fun focusContinueInput(project: Project?) { } } - val continuePluginService = getPluginService(project) ?: return + return getPluginService(project) +} + +fun focusContinueInput(project: Project?) { + val continuePluginService = getContinuePluginService(project) ?: return continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus() continuePluginService.sendToWebview("focusContinueInputWithoutClear", null) @@ -202,19 +101,7 @@ class FocusContinueInputWithoutClearAction : AnAction() { class FocusContinueInputAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - val project = e.project - if (project != null) { - val toolWindowManager = ToolWindowManager.getInstance(project) - val toolWindow = toolWindowManager.getToolWindow("Continue") - - if (toolWindow != null) { - if (!toolWindow.isVisible) { - toolWindow.activate(null) - } - } - } - - val continuePluginService = getPluginService(e.project) ?: return + val continuePluginService = getContinuePluginService(e.project) ?: return continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus() continuePluginService.sendToWebview("focusContinueInput", null) @@ -225,19 +112,7 @@ class FocusContinueInputAction : AnAction() { class NewContinueSessionAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - val project = e.project - if (project != null) { - val toolWindowManager = ToolWindowManager.getInstance(project) - val toolWindow = toolWindowManager.getToolWindow("Continue") - - if (toolWindow != null) { - if (!toolWindow.isVisible) { - toolWindow.activate(null) - } - } - } - - val continuePluginService = getPluginService(e.project) ?: return + val continuePluginService = getContinuePluginService(e.project) ?: return continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus() continuePluginService.sendToWebview("focusContinueInputWithNewSession", null) @@ -246,14 +121,7 @@ class NewContinueSessionAction : AnAction() { class ViewHistoryAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - val project = e.project - if (project != null) { - val toolWindowManager = ToolWindowManager.getInstance(project) - val toolWindow = toolWindowManager.getToolWindow("Continue") - } - val continuePluginService = getPluginService(e.project) ?: return - continuePluginService.sendToWebview("viewHistory", null) } } \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToggleInlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToggleInlineEditAction.kt deleted file mode 100644 index f14ce4dad..000000000 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToggleInlineEditAction.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.continuedev.continueintellijextension.editor - -import com.intellij.openapi.actionSystem.ActionManager -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.PlatformDataKeys -import com.intellij.openapi.components.service -import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.project.DumbAware - -class ToggleInlineEditAction : AnAction(), DumbAware { - override fun actionPerformed(e: AnActionEvent) { - val project = e.getData(PlatformDataKeys.PROJECT) ?: return - val editor = e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return - val diffService = project.service() - val handler = diffService.getHandler(editor) - if (handler == null) { - val actionId = "continue.inlineEdit" - val action = ActionManager.getInstance().getAction(actionId) - if (action != null) { - e.actionManager.tryToExecute(action, e.inputEvent, null, null, true) - } - } else { - handler.toggleFocus() - } - } -} \ No newline at end of file diff --git a/extensions/intellij/src/main/resources/META-INF/plugin.xml b/extensions/intellij/src/main/resources/META-INF/plugin.xml index 52111bc83..2e8130e5e 100644 --- a/extensions/intellij/src/main/resources/META-INF/plugin.xml +++ b/extensions/intellij/src/main/resources/META-INF/plugin.xml @@ -9,11 +9,13 @@ - + - + - + messages.MyBundle @@ -45,56 +48,40 @@ - - - - - + + + + - - - - - - - - + @@ -102,25 +89,28 @@ first-keystroke="ctrl shift J"/> + - - - + + + + @@ -129,6 +119,7 @@ + @@ -142,11 +133,13 @@ + + Date: Mon, 7 Oct 2024 18:01:54 -0700 Subject: [PATCH 2/2] Update ContinuePluginActions.kt --- .../continueintellijextension/actions/ContinuePluginActions.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt index 6a2f38a7c..62fcfbc07 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt @@ -113,7 +113,6 @@ class FocusContinueInputAction : AnAction() { class NewContinueSessionAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { val continuePluginService = getContinuePluginService(e.project) ?: return - continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus() continuePluginService.sendToWebview("focusContinueInputWithNewSession", null) } @@ -121,7 +120,7 @@ class NewContinueSessionAction : AnAction() { class ViewHistoryAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - val continuePluginService = getPluginService(e.project) ?: return + val continuePluginService = getContinuePluginService(e.project) ?: return continuePluginService.sendToWebview("viewHistory", null) } } \ No newline at end of file