From 3039c41946985d7bbd76507b32b39ccf97765b7d Mon Sep 17 00:00:00 2001 From: andrewyuq <89420755+andrewyuq@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:41:44 -0700 Subject: [PATCH] CodeWhisperer: follow-up fixes for Getting Started UX (#3893) 1. Remove usage of Tuple, changed to Pair 2. Other refactor to the code --- .../learn/LearnCodeWhispererEditor.kt | 18 +++---- .../learn/LearnCodeWhispererUIComponents.kt | 5 +- .../learn/LearnCodeWhispererVirtualFile.kt | 2 +- .../CodeWhispererTelemetryService.kt | 2 +- .../util/CodeWhispererConstants.kt | 51 +++++++++---------- .../jetbrains/ui/feedback/FeedbackDialog.kt | 9 +--- .../ui/feedback/SubmitFeedbackInGateway.kt | 2 +- .../resources/MessagesBundle.properties | 3 +- 8 files changed, 42 insertions(+), 50 deletions(-) diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererEditor.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererEditor.kt index 937a5de6bd..32bbbd31ef 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererEditor.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererEditor.kt @@ -24,7 +24,6 @@ import com.intellij.ui.dsl.builder.Row import com.intellij.ui.dsl.builder.TopGap import com.intellij.ui.dsl.builder.panel import com.intellij.ui.dsl.gridLayout.Gaps -import groovy.lang.Tuple import icons.AwsIcons import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererCsharp @@ -44,7 +43,6 @@ import software.aws.toolkits.resources.message import java.awt.Font import java.beans.PropertyChangeListener import javax.swing.BorderFactory -import javax.swing.Icon import javax.swing.ImageIcon import javax.swing.JButton import javax.swing.JComponent @@ -178,15 +176,15 @@ class LearnCodeWhispererEditor(val project: Project, val virtualFile: VirtualFil private fun Row.learnCodeWhispererLanguageButton(buttonLanguage: CodeWhispererProgrammingLanguage): Cell { val buttonContext = when (buttonLanguage) { - CodeWhispererJava.INSTANCE -> Tuple("Java ", AwsIcons.Misc.JAVA) - CodeWhispererPython.INSTANCE -> Tuple("Python ", AwsIcons.Misc.PYTHON) - CodeWhispererJavaScript.INSTANCE -> Tuple("JavaScript ", AwsIcons.Misc.JAVASCRIPT) - CodeWhispererTypeScript.INSTANCE -> Tuple("TypeScript ", AwsIcons.Misc.TYPESCRIPT) - CodeWhispererCsharp.INSTANCE -> Tuple("C# ", AwsIcons.Misc.CSHARP) - else -> Tuple("Java ", AwsIcons.Misc.JAVA) + CodeWhispererJava.INSTANCE -> "Java " to AwsIcons.Misc.JAVA + CodeWhispererPython.INSTANCE -> "Python " to AwsIcons.Misc.PYTHON + CodeWhispererJavaScript.INSTANCE -> "JavaScript " to AwsIcons.Misc.JAVASCRIPT + CodeWhispererTypeScript.INSTANCE -> "TypeScript " to AwsIcons.Misc.TYPESCRIPT + CodeWhispererCsharp.INSTANCE -> "C# " to AwsIcons.Misc.CSHARP + else -> "Java " to AwsIcons.Misc.JAVA } - val text = buttonContext[0] as String - val buttonIcon = buttonContext[1] as Icon + val text = buttonContext.first + val buttonIcon = buttonContext.second return button(text) { LearnCodeWhispererManager.getInstance(project).language = buttonLanguage diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererUIComponents.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererUIComponents.kt index ea811041c9..c4c871375e 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererUIComponents.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererUIComponents.kt @@ -288,8 +288,8 @@ object LearnCodeWhispererUIComponents { addActionListener { val currentLanguage = LearnCodeWhispererManager.getInstance(project).language val fileContext = tryExampleFileContexts[taskType]?.get(currentLanguage) ?: return@addActionListener - val fileContent = fileContext[0] as String - val caretOffset = fileContext[1] as Int + val fileContent = fileContext.first + val caretOffset = fileContext.second CodeWhispererTelemetryService.getInstance().sendOnboardingClickEvent(currentLanguage, taskType) val fileExtension = LearnCodeWhispererManager.getInstance(project).getFileExtension() val fullFilename = "${tryExampleRowContext.filename}$fileExtension" @@ -298,6 +298,7 @@ object LearnCodeWhispererUIComponents { (editor.foldingModel as FoldingModelImpl).isFoldingEnabled = false (editor.foldingModel as FoldingModelImpl).rebuild() (editor as EditorImpl).resetSizes() + editor.caretModel.updateVisualPosition() if (fileExists) return@addActionListener editor.caretModel.moveToOffset(caretOffset) } diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererVirtualFile.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererVirtualFile.kt index 9ad5008869..7ec0f2a06e 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererVirtualFile.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/learn/LearnCodeWhispererVirtualFile.kt @@ -16,7 +16,7 @@ class LearnCodeWhispererVirtualFile : LightVirtualFile("Learn CodeWhisperer") { override fun isWritable(): Boolean = false // This along with hashCode() is to make sure only one editor for this is opened at a time - override fun equals(other: Any?) = this.hashCode() == other.hashCode() + override fun equals(other: Any?) = other is LearnCodeWhispererVirtualFile && this.hashCode() == other.hashCode() override fun hashCode(): Int = presentableName.hashCode() } diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt index 3f2eb1b281..91fec631d6 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt @@ -474,7 +474,7 @@ class CodeWhispererTelemetryService { fun sendOnboardingClickEvent(language: CodeWhispererProgrammingLanguage, taskType: CodewhispererGettingStartedTask) { // Project instance is not needed. We look at these metrics for each clientId. - CodewhispererTelemetry.onboardingClick(null as Project?, language.toTelemetryType(), taskType) + CodewhispererTelemetry.onboardingClick(project = null, language.toTelemetryType(), taskType) } fun recordSuggestionState( diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt index c3a08f3795..81dd080ee3 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt @@ -6,7 +6,6 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.util import com.intellij.openapi.editor.markup.EffectType import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.ui.JBColor -import groovy.lang.Tuple import software.amazon.awssdk.regions.Region import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererCsharp import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJava @@ -285,39 +284,39 @@ public class SumFunction val tryExampleFileContexts = mapOf( CodewhispererGettingStartedTask.AutoTrigger to mapOf( - CodeWhispererJava.INSTANCE to Tuple(AUTO_TRIGGER_CONTENT_JAVA, AUTO_TRIGGER_CONTENT_JAVA.length - 8), - CodeWhispererPython.INSTANCE to Tuple(AUTO_TRIGGER_CONTENT_PYTHON, AUTO_TRIGGER_CONTENT_PYTHON.length), - CodeWhispererJavaScript.INSTANCE to Tuple(AUTO_TRIGGER_CONTENT_TS_JS, AUTO_TRIGGER_CONTENT_TS_JS.length), - CodeWhispererTypeScript.INSTANCE to Tuple(AUTO_TRIGGER_CONTENT_TS_JS, AUTO_TRIGGER_CONTENT_TS_JS.length), - CodeWhispererCsharp.INSTANCE to Tuple(AUTO_TRIGGER_CONTENT_CSHARP, AUTO_TRIGGER_CONTENT_CSHARP.length - 8) + CodeWhispererJava.INSTANCE to (AUTO_TRIGGER_CONTENT_JAVA to AUTO_TRIGGER_CONTENT_JAVA.length - 8), + CodeWhispererPython.INSTANCE to (AUTO_TRIGGER_CONTENT_PYTHON to AUTO_TRIGGER_CONTENT_PYTHON.length), + CodeWhispererJavaScript.INSTANCE to (AUTO_TRIGGER_CONTENT_TS_JS to AUTO_TRIGGER_CONTENT_TS_JS.length), + CodeWhispererTypeScript.INSTANCE to (AUTO_TRIGGER_CONTENT_TS_JS to AUTO_TRIGGER_CONTENT_TS_JS.length), + CodeWhispererCsharp.INSTANCE to (AUTO_TRIGGER_CONTENT_CSHARP to AUTO_TRIGGER_CONTENT_CSHARP.length - 8) ), CodewhispererGettingStartedTask.ManualTrigger to mapOf( - CodeWhispererJava.INSTANCE to Tuple(MANUAL_TRIGGER_CONTENT_JAVA, MANUAL_TRIGGER_CONTENT_JAVA.length - 8), - CodeWhispererPython.INSTANCE to Tuple(MANUAL_TRIGGER_CONTENT_PYTHON, MANUAL_TRIGGER_CONTENT_PYTHON.length), - CodeWhispererJavaScript.INSTANCE to Tuple(MANUAL_TRIGGER_CONTENT_TS_JS, MANUAL_TRIGGER_CONTENT_TS_JS.length), - CodeWhispererTypeScript.INSTANCE to Tuple(MANUAL_TRIGGER_CONTENT_TS_JS, MANUAL_TRIGGER_CONTENT_TS_JS.length), - CodeWhispererCsharp.INSTANCE to Tuple(MANUAL_TRIGGER_CONTENT_CSHARP, MANUAL_TRIGGER_CONTENT_CSHARP.length - 8) + CodeWhispererJava.INSTANCE to (MANUAL_TRIGGER_CONTENT_JAVA to MANUAL_TRIGGER_CONTENT_JAVA.length - 8), + CodeWhispererPython.INSTANCE to (MANUAL_TRIGGER_CONTENT_PYTHON to MANUAL_TRIGGER_CONTENT_PYTHON.length), + CodeWhispererJavaScript.INSTANCE to (MANUAL_TRIGGER_CONTENT_TS_JS to MANUAL_TRIGGER_CONTENT_TS_JS.length), + CodeWhispererTypeScript.INSTANCE to (MANUAL_TRIGGER_CONTENT_TS_JS to MANUAL_TRIGGER_CONTENT_TS_JS.length), + CodeWhispererCsharp.INSTANCE to (MANUAL_TRIGGER_CONTENT_CSHARP to MANUAL_TRIGGER_CONTENT_CSHARP.length - 8) ), CodewhispererGettingStartedTask.CommentAsPrompt to mapOf( - CodeWhispererJava.INSTANCE to Tuple(COMMENT_AS_PROMPT_CONTENT_NON_PYTHON, COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length), - CodeWhispererPython.INSTANCE to Tuple(COMMENT_AS_PROMPT_CONTENT_PYTHON, COMMENT_AS_PROMPT_CONTENT_PYTHON.length), - CodeWhispererJavaScript.INSTANCE to Tuple(COMMENT_AS_PROMPT_CONTENT_NON_PYTHON, COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length), - CodeWhispererTypeScript.INSTANCE to Tuple(COMMENT_AS_PROMPT_CONTENT_NON_PYTHON, COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length), - CodeWhispererCsharp.INSTANCE to Tuple(COMMENT_AS_PROMPT_CONTENT_NON_PYTHON, COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length) + CodeWhispererJava.INSTANCE to (COMMENT_AS_PROMPT_CONTENT_NON_PYTHON to COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length), + CodeWhispererPython.INSTANCE to (COMMENT_AS_PROMPT_CONTENT_PYTHON to COMMENT_AS_PROMPT_CONTENT_PYTHON.length), + CodeWhispererJavaScript.INSTANCE to (COMMENT_AS_PROMPT_CONTENT_NON_PYTHON to COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length), + CodeWhispererTypeScript.INSTANCE to (COMMENT_AS_PROMPT_CONTENT_NON_PYTHON to COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length), + CodeWhispererCsharp.INSTANCE to (COMMENT_AS_PROMPT_CONTENT_NON_PYTHON to COMMENT_AS_PROMPT_CONTENT_NON_PYTHON.length) ), CodewhispererGettingStartedTask.Navigation to mapOf( - CodeWhispererJava.INSTANCE to Tuple(NAVIGATION_CONTENT_NON_PYTHON, NAVIGATION_CONTENT_NON_PYTHON.length), - CodeWhispererPython.INSTANCE to Tuple(NAVIGATION_CONTENT_PYTHON, NAVIGATION_CONTENT_PYTHON.length), - CodeWhispererJavaScript.INSTANCE to Tuple(NAVIGATION_CONTENT_NON_PYTHON, NAVIGATION_CONTENT_NON_PYTHON.length), - CodeWhispererTypeScript.INSTANCE to Tuple(NAVIGATION_CONTENT_NON_PYTHON, NAVIGATION_CONTENT_NON_PYTHON.length), - CodeWhispererCsharp.INSTANCE to Tuple(NAVIGATION_CONTENT_NON_PYTHON, NAVIGATION_CONTENT_NON_PYTHON.length) + CodeWhispererJava.INSTANCE to (NAVIGATION_CONTENT_NON_PYTHON to NAVIGATION_CONTENT_NON_PYTHON.length), + CodeWhispererPython.INSTANCE to (NAVIGATION_CONTENT_PYTHON to NAVIGATION_CONTENT_PYTHON.length), + CodeWhispererJavaScript.INSTANCE to (NAVIGATION_CONTENT_NON_PYTHON to NAVIGATION_CONTENT_NON_PYTHON.length), + CodeWhispererTypeScript.INSTANCE to (NAVIGATION_CONTENT_NON_PYTHON to NAVIGATION_CONTENT_NON_PYTHON.length), + CodeWhispererCsharp.INSTANCE to (NAVIGATION_CONTENT_NON_PYTHON to NAVIGATION_CONTENT_NON_PYTHON.length) ), CodewhispererGettingStartedTask.UnitTest to mapOf( - CodeWhispererJava.INSTANCE to Tuple(UNIT_TEST_CONTENT_JAVA, UNIT_TEST_CONTENT_JAVA.length - 2), - CodeWhispererPython.INSTANCE to Tuple(UNIT_TEST_CONTENT_PYTHON, UNIT_TEST_CONTENT_PYTHON.length), - CodeWhispererJavaScript.INSTANCE to Tuple(UNIT_TEST_CONTENT_TS_JS, UNIT_TEST_CONTENT_TS_JS.length), - CodeWhispererTypeScript.INSTANCE to Tuple(UNIT_TEST_CONTENT_TS_JS, UNIT_TEST_CONTENT_TS_JS.length), - CodeWhispererCsharp.INSTANCE to Tuple(UNIT_TEST_CONTENT_CSHARP, UNIT_TEST_CONTENT_CSHARP.length - 8) + CodeWhispererJava.INSTANCE to (UNIT_TEST_CONTENT_JAVA to UNIT_TEST_CONTENT_JAVA.length - 2), + CodeWhispererPython.INSTANCE to (UNIT_TEST_CONTENT_PYTHON to UNIT_TEST_CONTENT_PYTHON.length), + CodeWhispererJavaScript.INSTANCE to (UNIT_TEST_CONTENT_TS_JS to UNIT_TEST_CONTENT_TS_JS.length), + CodeWhispererTypeScript.INSTANCE to (UNIT_TEST_CONTENT_TS_JS to UNIT_TEST_CONTENT_TS_JS.length), + CodeWhispererCsharp.INSTANCE to (UNIT_TEST_CONTENT_CSHARP to UNIT_TEST_CONTENT_CSHARP.length - 8) ) ) } diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/FeedbackDialog.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/FeedbackDialog.kt index fb70b408b5..d2e5092b90 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/FeedbackDialog.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/FeedbackDialog.kt @@ -189,12 +189,7 @@ class FeedbackDialog( init { super.init() - - title = if (!isCodeWhisperer) { - message("feedback.title") - } else { - message("feedback.title.codewhisperer") - } + title = message("feedback.title", productName) setOKButtonText(message("feedback.submit_button")) } @@ -221,7 +216,7 @@ class FeedbackDialog( } } -class ShowFeedbackDialogAction : DumbAwareAction(message("feedback.title"), message("feedback.description"), AwsIcons.Misc.SMILE_GREY) { +class ShowFeedbackDialogAction : DumbAwareAction(message("feedback.title", "Toolkit"), message("feedback.description"), AwsIcons.Misc.SMILE_GREY) { override fun actionPerformed(e: AnActionEvent) { runInEdt { FeedbackDialog(e.getRequiredData(LangDataKeys.PROJECT)).show() diff --git a/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/SubmitFeedbackInGateway.kt b/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/SubmitFeedbackInGateway.kt index 7e9e3a9dcc..010918e4f7 100644 --- a/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/SubmitFeedbackInGateway.kt +++ b/jetbrains-core/src/software/aws/toolkits/jetbrains/ui/feedback/SubmitFeedbackInGateway.kt @@ -9,7 +9,7 @@ import com.intellij.openapi.project.DefaultProjectFactory import com.intellij.openapi.project.DumbAwareAction import software.aws.toolkits.resources.message -class SubmitFeedbackInGateway : DumbAwareAction(message("feedback.title")) { +class SubmitFeedbackInGateway : DumbAwareAction(message("feedback.title", "Toolkit")) { override fun actionPerformed(e: AnActionEvent) { runInEdt { FeedbackDialog(DefaultProjectFactory.getInstance().defaultProject).show() diff --git a/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties b/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties index 3b0f5495f5..ccd2b168b2 100644 --- a/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties +++ b/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties @@ -844,8 +844,7 @@ feedback.submit_failed=An exception occurred while sharing your feedback: {0} feedback.submit_failed_title=Failed to share feedback feedback.submit_success=Thanks for the feedback! feedback.submitting=Sharing... -feedback.title=Share Feedback for AWS Toolkit... -feedback.title.codewhisperer=Share Feedback for AWS CodeWhisperer... +feedback.title=Share Feedback for AWS {0}... feedback.validation.comment_too_long=Comment is too long. feedback.validation.empty_comment=Please provide a comment. feedback.validation.no_sentiment=Please select how you're feeling.