Skip to content

Commit

Permalink
CodeWhisperer: follow-up fixes for Getting Started UX (#3893)
Browse files Browse the repository at this point in the history
1. Remove usage of Tuple, changed to Pair
2. Other refactor to the code
  • Loading branch information
andrewyuq authored Sep 29, 2023
1 parent 7aa13bc commit 3039c41
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -178,15 +176,15 @@ class LearnCodeWhispererEditor(val project: Project, val virtualFile: VirtualFil

private fun Row.learnCodeWhispererLanguageButton(buttonLanguage: CodeWhispererProgrammingLanguage): Cell<JButton> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3039c41

Please sign in to comment.